我在这里尝试做的不是反复运行插入代码,这就是我决定创建存储过程的原因。下面是存储过程的脚本,它已成功创建,但是当我执行存储过程“BEGIN SP_INSERT_PMC_UPDATE_DP; END;”时我收到一条错误消息“*调用SP_INSERT_PMC_UPDATE_DP时参数的错误数量或类型*”
我的思维框架和sp代码是:
1-我检查PMC_UPDATE_DP中是否有记录并将该值放入RECORD_COUNT。
2-现在,如果RECORD_COUNT大于零,我想清除PMC_UPDATE_DP表中的所有记录。
3-如果RECORD_COUNT等于零,那么我想将EXTERNAL_PMC_UPDATE_FD表中的数据插入PMC_UPDATE_DP。
CREATE OR REPLACE PROCEDURE PMC.SP_INSERT_PMC_UPDATE_DP
(RECORD_COUNT OUT NUMBER) --Is my issue here???
IS
BEGIN
--Returns the total records and adds the value to RECORD_COUNT variable.
SELECT COUNT(*)
INTO RECORD_COUNT
FROM PMC.PMC_UPDATE_DP;
--Condition to see if RECORD_COUNT is greater than zero and dumps data to clear out PMC.PMC_UPDATE_DP table.
IF RECORD_COUNT > 0 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE PMC.PMC_UPDATE_DP';
END IF;
--Condition to see if RECORD_COUNT equals zero. If true insert data into PMC_UPDATE_DP table from the PMC.EXTERNAL_PMC_UPDATE_FD table.
IF RECORD_COUNT = 0 THEN
INSERT INTO PMC.PMC_UPDATE_DP
( JOB_ID,
CONTROL_ID,
ACCT_NO,
CALC_DIVIDEND,
CERT_NEW_SHARES,
CALC_CASH_DISBURSMENT,
DECEASED,
STATUS,
ALPHA_SP1,
ALPHA_SP2,
ALPHA_SP3,
ALPHA_SP4,
NUM_SP1,
NUM_SP2,
NUM_SP3,
NUM_SP4,
DONT_CALL,
DONT_MAIL
)
SELECT JOB_ID,
CONTROL_ID,
ACCT_NO,
CALC_DIVIDEND,
CERT_NEW_SHARES,
CALC_CASH_DISBURSMENT,
DECEASED,
STATUS,
ALPHA_SP1,
ALPHA_SP2,
ALPHA_SP3,
ALPHA_SP4,
NUM_SP1,
NUM_SP2,
NUM_SP3,
NUM_SP4,
DONT_CALL,
DONT_MAIL
FROM PMC.EXTERNAL_PMC_UPDATE_FD
COMMIT;
END IF;
END;
答案 0 :(得分:1)
如果要调用带有OUT
参数的过程,则需要传入一个局部变量,以便Oracle能够保存输出。
DECLARE
l_record_count pls_integer;
BEGIN
PMC.SP_INSERT_PMC_UPDATE_DP ( l_record_count );
-- Do something with l_record_count, probably not just calling dbms_output
-- dbms_output.put_line( 'Record count = ' || l_record_count );
END;
如果您不打算对输出做任何事情,也许您真的不希望该过程具有OUT
参数。也许您只想将record_count
声明为局部变量。