更新表的多列

nov*_*ice 0 sql oracle oracle10g

我有两个包含以下字段的表:

table1 : OTNAME table2 : SNCODE, description_text

我正在尝试将 table2 的两列添加到 table1 并更新列。我的查询是:

alter table  table1 add sncode integer                              
alter table  table1 add description_text varchar2(30)

update table1 set 
sncode,description_text = (SELECT  sncode, description_text
   FROM   table2, table1
  WHERE   SUBSTR (otname, INSTR (otname,'.', 1, 3)
                         + 1, 
                         INSTR (otname, '.', 1, 4)
                              - INSTR (otname,'.', 1, 3)
                              - 1)
                               = sncode)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:ORA 00927 - Missing Equal to Operator,指向我的更新语句的第二行。感谢有人能指出我正确的方向。

问候,

新手

Qua*_*noi 5

MERGE
INTO    table1 t1
USING   table2 t2
ON      (SUBSTR (otname, INSTR (otname,'.', 1, 3)
                         + 1, 
                         INSTR (otname, '.', 1, 4)
                              - INSTR (otname,'.', 1, 3)
                              - 1)
                               = t2.sncode))
WHEN MATCHED THEN
UPDATE
SET    t1.sncode = t2.sncode,
       t1.description_text = t2.description_text
Run Code Online (Sandbox Code Playgroud)

您还可以简化表达式:

MERGE
INTO    table1 t1
USING   table2 t2
ON      (REGEXP_SUBSTR(otname, '[^.]+', 1, 4) = t2.sncode)
WHEN MATCHED THEN
UPDATE
SET    t1.sncode = t2.sncode,
       t1.description_text = t2.description_text
Run Code Online (Sandbox Code Playgroud)