如何修复ORA-01427

时间:2015-06-03 14:43:24

标签: sql oracle stored-procedures plsql

我正在努力将存储过程从SQL转换为Oracle,我收到此错误:

ORA-01427:单行子查询返回多行 ORA-06512:在“CMIUSER.PROCEDURE3”,第21行 ORA-06512:第7行

t_name_match和t_descript_match是全局临时表。

有人可以向我解释我做错了什么吗?

Class2

2 个答案:

答案 0 :(得分:3)

你有“单行子查询”的唯一地方(我注意到)是:

UPDATE  t_name_match nm
    SET nm.DESCRIPT = (SELECT x.DESCRIPT
                       from  CHAR_FEATURE_XRF x
                       where x.KBID = nm.KBID and x.SYMBOLID = nm.SYMBOLID
                      );

如何修复它取决于您想要做什么。两种简单的方法是MAX()rownum = 1

UPDATE  t_name_match nm
    SET nm.DESCRIPT = (SELECT MAX(x.DESCRIPT)
                       from  CHAR_FEATURE_XRF x
                       where x.KBID = nm.KBID and x.SYMBOLID = nm.SYMBOLID
                      );

UPDATE  t_name_match nm
    SET nm.DESCRIPT = (SELECT x.DESCRIPT
                       from  CHAR_FEATURE_XRF x
                       where x.KBID = nm.KBID and x.SYMBOLID = nm.SYMBOLID and
                             rownum = 1
                      );

编辑:

哦,我看到有两个地方。另一个是:

UPDATE t_descript_match dm
    SET dm.FEATURENAME = (SELECT f.FEATURENAME
                          from  FEATURE_MASTER f
                          where f.KBID = dm.KBID and f.SYMBOLID = dm.SYMBOLID
                         );

你会以同样的方式修复它。

答案 1 :(得分:1)

    UPDATE  t_name_match nm
    SET nm.DESCRIPT = (SELECT x.DESCRIPT
    from  CHAR_FEATURE_XRF    x
    where x.KBID = nm.KBID
    and x.SYMBOLID = nm.SYMBOLID group by x.DESCRIPT);


    UPDATE  t_descript_match dm
    SET dm.FEATURENAME = (SELECT f.FEATURENAME
    from  FEATURE_MASTER      f
    where f.KBID = dm.KBID
    and f.SYMBOLID = dm.SYMBOLID group by f.FEATURENAME);

你可以尝试这些并检查。