这里发生了什么?当我尝试运行此代码时,出现以下错误

时间:2016-06-10 08:28:33

标签: sql xml oracle

          -- Creating a procedure to convert DB to XML 
        CREATE OR REPLACE PROCEDURE XML_OUTPUT AS 
        BEGIN
-- Declaring a ref cursor and a variable of type XMLTYPE
DECLARE
  refcursor SYS_REFCURSOR;
  wxmltype XMLTYPE;
BEGIN
-- Prompting the user to input the range of database to be converted
dbms_output.put_line('Input the min value of MESSID');
-- Declaring the ref cursor and pointing it to a select variable
  OPEN refcursor FOR SELECT messname,
                            studentname 
                            FROM studentsmessdata
                            -- Accepting user input for range
                            WHERE messid > &messid; 
  wxmltype:= XMLTYPE(refcursor);
  -- printing the database as XML
  dbms_output.put_line(wxmltype.getClobVal);
END;
  NULL;
END XML_OUTPUT;

出现以下错误:

  

错误:PLS-00801:内部错误[ph2csql_strdef_to_diana:bind]   错误(9,22):PL / SQL:忽略SQL语句错误(12,34):PL / SQL:   ORA-06544:PL / SQL:内部错误,参数:
  [ph2csql_strdef_to_diana:bind],[],[],[],[],[],[],[]

1 个答案:

答案 0 :(得分:2)

禁用替换变量时会出现错误:

set define off

CREATE OR REPLACE PROCEDURE
...
/

Procedure XML_OUTPUT compiled
Errors: check compiler log

show errors

Errors for PROCEDURE STACKOVERFLOW.XML_OUTPUT:

LINE/COL ERROR
-------- ----------------------------------------------------------------------------------------------------------------
0/0      PLS-00801: internal error [ph2csql_strdef_to_diana:bind]
11/22    PL/SQL: SQL Statement ignored
13/34    PL/SQL: ORA-06544: PL/SQL: internal error, arguments: [ph2csql_strdef_to_diana:bind], [], [], [], [], [], [], []

将define设置为默认值&(假设您使用的是支持替换变量的客户端;这是在SQL Developer中),在编译时会提示您输入&messid值,并且然后在过程定义中修复值。

如果要在运行时提供值,则需要将其作为参数传递,称为p_messid

CREATE OR REPLACE PROCEDURE XML_OUTPUT(p_messid studentsmessdata.messid%TYPE) AS 
  refcursor SYS_REFCURSOR;
  wxmltype XMLTYPE;
BEGIN
  -- Declaring the ref cursor and pointing it to a select variable
  OPEN refcursor FOR SELECT messname,
                            studentname 
                            FROM studentsmessdata
                            -- Accepting user input for range
                            WHERE messid > p_messid; 
  wxmltype:= XMLTYPE(refcursor);
  -- printing the database as XML
  dbms_output.put_line(wxmltype.getClobVal);
END XML_OUTPUT;
/

我删除了冗余的嵌套块,使其缩短了一点。然后你会把它称为,例如:

set serveroutput on
exec XML_OUTPUT(42);