我在oracle 11g上遇到存储过程问题。
我创建了这个程序,当我在sql开发人员上运行时,它会被卡住。 执行永远不会结束,也没有打印出来。
步骤:
create or replace PROCEDURE "GET_RECORDS_SP" (CURSOR_ OUT sys_refcursor, PARAM_0 VARCHAR2,PARAM_1 VARCHAR2)
AS
myquery varchar2(255);
BEGIN
DBMS_OUTPUT.enable();
DBMS_OUTPUT.PUT_LINE(PARAM_0);
DBMS_OUTPUT.PUT_LINE('-- 1 --');
CASE
WHEN PARAM_0 = 'A' THEN
DBMS_OUTPUT.PUT_LINE('-- 2 --');
myquery := 'SELECT * FROM table
WHERE char_field = ''N'' and date_field is not null';
WHEN PARAM_0 = 'B' THEN
DBMS_OUTPUT.PUT_LINE('-- 3 --');
myquery:= 'SELECT * FROM table
WHERE char_field = ''N'' and
date_field is not null and
char_field2 = '''||PARAM_1||'''';
WHEN PARAM_0 = 'C' THEN
DBMS_OUTPUT.PUT_LINE('-- 4 --');
myquery:= 'SELECT * FROM table
WHERE char_field = ''N'' and
date_field is not null
and char_field3 = ''S''';
END CASE;
DBMS_OUTPUT.PUT_LINE(myquery);
OPEN CURSOR_ FOR myquery;
END;
如果我对该行OPEN CURSOR_ FOR myquery;
发表评论,则会打印A
,-- 1 --
,-- 2 --
和查询SELECT * FROM table WHERE char_field = ''N'' and date_field is not null
(A
传递PARAM_0
1}})。
如果我尝试单独运行查询SELECT * FROM table WHERE char_field = ''N'' and date_field is not null
,它会执行并给我结果。
谁能告诉我我的手术有什么问题? 谢谢!
答案 0 :(得分:0)
我意识到我正在查询比我需要更多的字段。
所以我改变了查询:
SELECT * FROM table WHERE char_field = ''N'' and date_field is not null';
要:
SELECT field1, field2, field3, field4 FROM table WHERE char_field = ''N'' and date_field is not null';
现在程序不再被卡住了。它不是那么快,但我得到了结果。