在 oracle 中将参数传递给函数 Return null 时?

when passing parameter to function Return null in oracle?

这是我的功能

---Write procedure for retrive data----
CREATE OR REPLACE FUNCTION retrieve_decrypt(
    custid  in NUMBER
)
RETURN sys_refcursor
IS
    decrypt_value sys_refcursor;
BEGIN
     open decrypt_value for Select custname,contactno, enc_dec.decrypt(creditcardno,password) as  
       creditcardno ,enc_dec.decrypt(income,password) as 
            income  from employees where custid=custid ;
    RETURN decrypt_value;
END;
/

我这样称呼它:SELECT retrieve_decrypt(5) FROM DUAL; 然后它 return 只有 {}.

但我是不是,硬编码 custid=5 代替了 custid=custid。它将 return 结果正确。需要一些专家的帮助来解决这个问题。

不要将参数命名为列;如果列名是 custid,则参数为 par_custid。否则,它会导致问题(如您所见)。

在你的例子中:

CREATE OR REPLACE FUNCTION retrieve_decrypt (par_custid IN NUMBER)
   RETURN SYS_REFCURSOR
IS
   decrypt_value  SYS_REFCURSOR;
BEGIN
   OPEN decrypt_value FOR
      SELECT custname,
             contactno,
             enc_dec.decrypt (creditcardno, password) AS creditcardno,
             enc_dec.decrypt (income, password) AS income
        FROM employees
       WHERE custid = par_custid;

   RETURN decrypt_value;
END;
/