无法在存储过程中运行大型动态选择查询

时间:2012-05-29 16:27:54

标签: oracle plsql oracle11g

我有一个执行动态选择查询的存储过程。查询字符串很大。以下是存储过程


create or replace
procedure My_SP
(
procRefCursor out sys_refcursor,
--My other input variables here
)
is

dynSqlComplete varchar2(8000) := 'n/a';

begin

  dynSqlComplete := 'Large query here';

  open procRefCursor for dynSqlComplete;

end;

当我运行此sp时,它显示以下错误

  

ORA-00600:内部错误代码,参数:[qcscbAddToSelLists],[],[],[],[],[],[],[],[],[],[], []

所以我将dynSqlComplete变量的大小减小为varchar2(5000),然后运行存储过程。我收到以下错误:

  

ORA-06502:PL / SQL:数字或值错误:字符串缓冲区太小

我尝试过很多事情,但我也不想在这里添加它们,因为它会误导。

- 编辑 - 2012年6月6日

大家好,

我能够确定问题,但我还无法解决问题。我试图逐个运行查询,我发现了抛出错误的查询。它包含START WITH,当我评论它时,查询开始起作用。我已经给出了下面的代码,并注释了出错的代码。


      SELECT RowNum AS RowNumber1,
      GR.*,
      --LEVEL AS LineageLvl,
      VDE.*
    FROM
      (SELECT *
      FROM group_relations  left outer join relation_classifier_instances RC on 
      rc.relation_id = group_relations.Group_relation_id  WHERE group_relation_type_id IN
      (19,20,32,38,42,43)  and (rc.relation_id is null) 
      ) GR
    LEFT OUTER JOIN Vendor_Feed_data_elements VDE
    ON GR.Group_Relation_Type_Id = 19
    AND GR.Primary_GroupField_Id = VDE.Vendor_Data_Element_Id
      /* Code which is giving the error
      START WITH
      (
        VDE.Vendor_Data_Element_Id IS NOT NULL  )
      CONNECT BY nocycle prior GR.RELATED_GROUPFIELD_ID = GR.PRIMARY_GROUPFIELD_ID*/

2 个答案:

答案 0 :(得分:0)

您可以尝试在11g中使用clob一个CLOB,类似于(未经测试):

declare
  l_sql clob;
  l_str1 varchar2(32767);
  l_str2 varchar2(32767);
begin
  dbms_lob.createtemporary(l_sql, false);

  l_str1 := 'some large SQL chunk';
  l_str2 := 'and the rest of large SQL chunk';

  l_sql := l_str1;
  dbms_lob.writeappend(l_sql, length(l_str2), l_str2);

  execute immediate l_sql;

  dbms_lob.freetemporary(l_sql);

end;

答案 1 :(得分:-1)

当然你不想要一个功能?这是我做的类似的一个例子。

FUNCTION showbody(cust varchar2, receipt varchar2) 
    RETURN sys_refcursor AS retval sys_refcursor;
BEGIN
    OPEN retval FOR
        SELECT * 
        FROM comp.comp_remittance_details
        WHERE receipt_number=receipt 
            AND customer_number=cust;
    RETURN(retval);
END showbody;