PLSQL代码函数不返回值

时间:2016-02-29 07:13:53

标签: oracle plsql

我正在使用函数

create or replace FUNCTION FSS_REF_GETREFIDBYCODEANDORDER (v_Code In CHAR, v_OrderBy In number )
RETURN number IS v_RefID NUMBER(10);

BEGIN

 SELECT REFID
 INTO v_RefID
 FROM REFERENCE
 WHERE Code like (v_Code || '%')
 AND
 ORDERBY = v_OrderBy
 and ROWNUM = 1;

 RETURN (v_RefID); 
 END;

它应该返回一个值,因为如果我单独运行它而没有给出下面给出的函数,它将结果作为1个所需的1值

 SELECT REFID
 -- INTO v_RefID
 FROM REFERENCE
 WHERE Code like ('001' || '%')
 AND
 ORDERBY = 4
 and ROWNUM = 1;

任何人都可以帮我解决任何功能错误。因为我是PL / SQL编程的新手。

1 个答案:

答案 0 :(得分:1)

尝试将“v_Code In CHAR”更改为“v_Code In VARCHAR2”。 我还建议您添加NO_DATA_FOUND异常处理程序。 E.g。

CREATE OR REPLACE FUNCTION fss_ref_getrefidbycodeandorder(v_code IN VARCHAR2, v_orderby IN NUMBER) RETURN NUMBER IS
  v_refid NUMBER(10);

BEGIN

  SELECT refid
    INTO v_refid
    FROM reference
   WHERE code LIKE (v_code || '%')
     AND orderby = v_orderby
     AND rownum = 1;

  RETURN(v_refid);
EXCEPTION
  WHEN no_data_found THEN
    RETURN NULL;
END;