I'm working on converting a stored procedure from SQL to Oracle and I get this error:
ORA-01427: single-row subquery returns more than one row ORA-06512: at "CMIUSER.PROCEDURE3", line 21 ORA-06512: at line 7
t_name_match and t_descript_match are global temp tables.
Can someone explain to me what I'm doing wrong?
create or replace PROCEDURE "PROCEDURE3"
(
IN_SEARCH_TEXT IN NVARCHAR2
, OUT_O_RC OUT SYS_REFCURSOR
) AS
BEGIN
/******************************************************************************* ***
** Name matches
******************************************************************************** ***/
/*
** Load matches to Name Table
*/
INSERT INTO t_name_match (KBID, SYMBOLID, FEATURENAME)
SELECT fm.KBID, fm.SYMBOLID, fm.FEATURENAME
from FEATURE_MASTER fm
where Upper(featurename) like IN_SEARCH_TEXT;
/*
** Add description for each of these matching names.
*/
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);
/******************************************************************************* ***
** Description matches
******************************************************************************** ***/
/*
** Load matches to Descript table
*/
INSERT INTO t_descript_match (KBID, SYMBOLID, DESCRIPT)
SELECT x.KBID, x.SYMBOLID, x.DESCRIPT
from CHAR_FEATURE_XRF x
where Upper(descript) like IN_SEARCH_TEXT;
/*
** Add name for each of these matching descriptions.
*/
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);
/******************************************************************************* ***
** Return result set
******************************************************************************** ***/
OPEN OUT_O_RC FOR
SELECT nm.featurename, nm.descript
from t_name_match nm
UNION
SELECT dm.featurename, dm.descript
from t_descript_match dm
ORDER BY featurename, descript;
END PROCEDURE3;
The only place (that I notice) where you have a "single row subquery" is:
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
);
How you fix it depends on what you want to do. Two simple ways are MAX()
and 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
);
EDIT:
Oh, I see there are two places. The other is:
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
);
You would fix it the same way.
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);
can you try these and check.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.