来自String中参数名称的Oracle PL / SQL参数值

时间:2015-08-11 19:38:31

标签: database oracle plsql procedure

嗨我需要检索一个参数值,其中参数名称在不同的参数中。

让我们说proc是如下

PROCEDURE findValue
(
    p_date             IN VARCHAR2,
    p_name             IN VARCHAR2,
    p_class             IN VARCHAR2,
    p_paramname             IN VARCHAR2,
)
IS

现在假设我想将p_paramname作为p_date传递,并进一步使用PL / SQL块中p_date参数的值,我该如何使用它?

2 个答案:

答案 0 :(得分:0)

如果您能负担PL / SQL表输入,请尝试以下逻辑:

RewriteBase \

注意:代码语法可能不完美,但伪仍然可以满足您的要求。

答案 1 :(得分:0)

只需针对可能的参数名称检查P_PARAMNAME的值,并相应地进行分支。如,

CREATE OR REPLACE PROCEDURE matt_test1 (p_date        IN VARCHAR2,
                                        p_name        IN VARCHAR2,
                                        p_class       IN VARCHAR2,
                                        p_paramname   IN VARCHAR2) IS
BEGIN
  CASE p_paramname
    WHEN 'P_NAME' THEN
      DBMS_OUTPUT.put_line ('Did something with P_NAME.  Value was ' || p_name);
    WHEN 'P_DATE' THEN
      DBMS_OUTPUT.put_line ('Did something with P_DATE.  Value was ' || p_date);
    WHEN 'P_CLASS' THEN
      DBMS_OUTPUT.put_line ('Did something with P_CLASS.  Value was ' || p_class);
    ELSE
      raise_application_error (-20001, 'Invalid parameter name: ' || p_paramname);
  END CASE;
END matt_test1;


begin
  matt_test1(SYSDATE,'Fred','English 101', 'P_DATE');
  matt_test1(SYSDATE,'Fred','English 101', 'P_NAME');
  matt_test1(SYSDATE,'Fred','English 101', 'P_CLASS');
end;

输出:

Did something with P_DATE.  Value was 11-Aug-2015
Did something with P_NAME.  Value was Fred
Did something with P_CLASS.  Value was English 101