1

我正在 pl/sql 中创建一个包。在此我声明了参考光标。在过程中使用带有多个列名的 select 语句。但我无法得到结果。在这里我附上了我的代码。帮助我纠正错误。我是 pl/sql 的新手

code

CREATE OR REPLACE PACKAGE types AS 
  TYPE cursor_type IS REF CURSOR;
END Types; 
/

CREATE OR REPLACE
PROCEDURE get_CDR_rs (p_no    IN  zkv.FLD_callingPartyNumber%TYPE,
                  CDR_recordset OUT SYS_REFCURSOR) AS 
BEGIN 
 OPEN CDR_recordset FOR
SELECT  FLD_callingPartyNumber,
       FLD_dateTimeConnect

FROM   CISCOCUIC_TBL
WHERE  FLD_callingPartyNumber= p_no
ORDER BY FLD_callingPartyNumber,;
END get_CDR_rs;
/



SET SERVEROUTPUT ON SIZE 1000000
DECLARE
  l_cursor  SYS_REFCURSOR;
  l_callingPartyNumber   zkv.FLD_callingPartyNumber%TYPE;
  l_dateTimeConnect  zkv.FLD_dateTimeConnect%TYPE;
BEGIN

LOOP 
FETCH l_cursor
INTO  l_callingPartyNumber, l_dateTimeConnect;
EXIT WHEN l_cursor%NOTFOUND;

END LOOP;
CLOSE l_cursor;
END;
/


Error

9/41    PL/SQL: ORA-00936: missing expression
5/5     PL/SQL: SQL Statement ignored
4

1 回答 1

1

首先是程序中存在语法错误。它应该是

CREATE OR REPLACE
PROCEDURE get_CDR_rs (p_no    IN  zkv.FLD_callingPartyNumber%TYPE,
                  CDR_recordset OUT SYS_REFCURSOR) AS 
BEGIN 
 OPEN CDR_recordset FOR
SELECT  FLD_callingPartyNumber,
       FLD_dateTimeConnect

FROM   CISCOCUIC_TBL
WHERE  FLD_callingPartyNumber= p_no
ORDER BY FLD_callingPartyNumber; -- there was a comma which is not required or you    
--   missed a column
END get_CDR_rs;
/

其次,在哪里get_CDR_rs被调用来检索结果?

第三,为什么需要以下内容?因为您正在使用 sys_refcursor

CREATE OR REPLACE PACKAGE types AS 
  TYPE cursor_type IS REF CURSOR;
END Types; 
/

如果您想查看返回 sys_refcursor 的过程的结果,请执行以下操作

variable rset refcursor;

DECLARE
  p_no  zkv.FLD_callingPartyNumber%TYPE;
BEGIN
  p_no := '123';
  get_CDR_rs (p_no, :rset);  
END;
/

print rset
于 2012-11-19T05:39:31.953 回答