我在Oracle SQL Developer中创建存储过程。我试图比较两个表形式2表,如果任何表有更多的记录,我需要收集它们并存储在(另一个表)我的存储过程工作正常如果我只有一个记录不匹配,任何一个记录和它抛出
ORA-01422:精确提取返回超过请求的行数 ORA-06512:在“TEST_VAL”,第73行 ORA-06512:第2行
如果我将其作为SQL查询
运行,那么这个查询运行得很好SELECT h.STATEMENTNUMBER, h.STATEMENTTOTAL
FROM statement_header h
MINUS
SELECT j.STATEMENTNUMBER, j.STATEMENTTOTAL
FROM jwf_statement j;
,我的存储过程看起来像这样
create or replace PROCEDURE TEST_VAL
IS
l_num_recs VARCHAR2 (20);
BEGIN
select STATEMENTNUMBER into l_num_recs
from
(SELECT H.STATEMENTNUMBER, H.STATEMENTTOTAL
FROM statement_header H
MINUS
SELECT J.STATEMENTNUMBER, J.STATEMENTTOTAL
FROM jwf_statement J
);
insert into l_num_recs values(l_num_recs);
Commit;
End;
任何帮助都是适当的
答案 0 :(得分:1)
create or replace PROCEDURE TEST_VAL
IS
BEGIN
insert into destinationTableName
select STATEMENTNUMBER
from
(SELECT H.STATEMENTNUMBER, H.STATEMENTTOTAL
FROM erocks.statement_header_staging H
MINUS
SELECT J.STATEMENTNUMBER, J.STATEMENTTOTAL
FROM erocks.ps_jwf_statement_staging J
);
Commit;
End;