T1.LEID 需要使用 MSID 和 ESTID 都匹配的行中的 T1.ID 值进行更新。
我已经改变了我的语法并尝试了几种变体,但总是以同样的错误 01427 告终。
UPDATE T1
SET LEID = (SELECT T2.id
FROM T2
WHERE T2.MSID = T1.MSID )
WHERE EXISTS (SELECT T2.id
FROM T2
WHERE T2.ESTID = T1.ESTID
);
ORA-01427: single-row subquery returns more than one row
{ CREATE TABLE T1
(
{
ESTID NUMBER(8),
MSID NUMBER(8),
SMID NUMBER(8),
LEID NUMBER(8)
)
NOLOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(545, 5454, 888, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(334, 5555, 6541, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(254, 4487, 888, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(659, 54518, 654, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(854, 8548, 85478, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(658, 12485, 254, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(444, 5555, 888, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(444, 5545, 888, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(444, 4444, 888, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(555, 5555, 999, NULL);
Insert into T1
(ESTID, MSID, SMID, LEID)
Values
(444, 3333, 5, NULL);
COMMIT; }
CREATE TABLE T2
(
ESTID NUMBER(8),
MSID NUMBER(8),
ID NUMBER(8)
)
NOLOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING; }
Insert into T2
{(ESTID, MSID, ID)
Values
(545, 5454, 14);
Insert into T2
(ESTID, MSID, ID)
Values
(334, 5555, 16);
Insert into T2
(ESTID, MSID, ID)
Values
(254, 4487, 18);
Insert into T2
(ESTID, MSID, ID)
Values
(659, 54518, 20);
Insert into T2
(ESTID, MSID, ID)
Values
(854, 8548, 22);
Insert into T2
(ESTID, MSID, ID)
Values
(658, 12485, 24);
Insert into T2
(ESTID, MSID, ID)
Values
(444, 5555, 26);
Insert into T2
(ESTID, MSID, ID)
Values
(444, 5545, 28);
Insert into T2
(ESTID, MSID, ID)
Values
(444, 4444, 30);
Insert into T2
(ESTID, MSID, ID)
Values
(555, 5555, 32);
Insert into T2
(ESTID, MSID, ID)
Values
(444, 3333, 34);
COMMIT; }
对于如何更改脚本顶部更新 T1 中的 ropws 的任何帮助或建议,将不胜感激。