我试图动态执行存储过程,因为我基于一个简单的数字得到了它们,所以我创建了另一个程序来执行此操作,但我一直在我的问题的标题上得到错误,这里是我的程序:
PROCEDURE P_EXEC_REG(p_Register IN VARCHAR2, p_LineBuff IN VARCHAR2, p_User IN VARCHAR2) IS
l_Procedure VARCHAR2(50);
l_Sentence VARCHAR2(500);
BEGIN
l_Procedure := 'P_REG_' || TRIM(p_Register);
l_Sentence := 'BEGIN CTS.PK_INTEGRATE_MANIFESTO.' || l_Procedure || '(:A, :B); END;';
EXECUTE IMMEDIATE l_Sentence
USING IN p_LineBuff, p_User;
END;
由于我们有数百个程序,用if语句做这个很痛苦,希望有人可以帮我解决这个问题,同时,我会告诉你我是怎么称呼的:
PROCEDURE P_LOAD_FILE(p_Linebuff IN VARCHAR2, p_User IN VARCHAR2) IS
l_Register VARCHAR2(3);
BEGIN
BEGIN
SELECT SUBSTR(p_Linebuff,1,3)
INTO l_Register
FROM DUAL;
EXCEPTION
WHEN NO_DATA_FOUND THEN
--p_result := false;
NULL;
END;
CTS.PK_INTEGRATE_MANIFESTO.P_EXEC_REG(l_Register, p_Linebuff, p_User);
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
答案 0 :(得分:0)
谢谢你们,我找到了这个问题的答案,感谢@John Heller的评论,用这个命令我可以注意到它实际上正在执行,但是当我发送动态参数时,isl_Register,我没有检查空值,所以它直接进入EXECUTE IMMEDIATE,最后使用带有null参数的过程。现在它看起来像这样:
PROCEDURE P_LOAD_FILE(p_Linebuff IN VARCHAR2, p_User IN VARCHAR2, p_Error OUT BOOLEAN, p_Message OUT VARCHAR2) IS
l_MessageLevel NUMBER(1);
l_Register VARCHAR2(3);
l_Command VARCHAR2(50);
l_Procedure VARCHAR2(4000);
l_Error NUMBER(1);
BEGIN
IF p_Linebuff IS NOT NULL OR p_Linebuff <> '' THEN
BEGIN
SELECT SUBSTR(p_Linebuff,1,3)
INTO l_Register
FROM DUAL;
IF LENGTH(TRIM(l_Register)) = 3 THEN
P_EXEC_REG(l_Register, p_Linebuff, p_User, l_Error, p_Message);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
END IF;
EXCEPTION
WHEN OTHERS THEN
p_Error := TRUE;
p_Message := 'Sucedio un error al procesar el archivo.';
END;
感谢您的帮助,对不起,如果这是一个愚蠢的问题:)