包裹PLSQL程序时出错请帮助我

时间:2014-03-24 19:18:25

标签: oracle plsql syntax-error wrapping

我在包装PLSQL过程时遇到错误。下面是我的代码和错误

实际功能:

create or replace function column_job_salary_restriction(
    v_schema        in varchar2,
    v_object        in varchar2
    ) return varchar2
         is
    v_sql varchar2(100);
        begin
    if lower( sys_context( 'userenv', 'session_user') ) = 'user2' then
            v_sql := '0 = 1';
        end if;
            return v_sql;
end;

/

包装代码:

DECLARE
       INPUT DBMS_SQL.VARCHAR2S;
       OUTPUT DBMS_SQL.VARCHAR2S;
       BEGIN
       INPUT(1) := 'create or replace function column_job_salary_restriction( v_schema in varchar2, v_object in varchar2) return varchar2 is';
       INPUT(2) := 'v_sql varchar2(100) := null;';  
   INPUT(3) := 'begin';
   INPUT(4) := 'if lower(sys_context("userenv","session_user")) = "user2" then';
       INPUT(5) := 'v_sql := '0 = 1';';
   INPUT(6) := 'end if;';   
       INPUT(7) := 'return v_sql';
       INPUT(8) 'end;';
       SYS.DBMS_DDL.CREATE_WRAPPED(DDL => INPUT,
                                                                        LB  => 1,
                                                                        UB  => INPUT.COUNT);
       END;

/

错误:

ERROR at line 9:
ORA-06550: line 9, column 35:
PLS-00103: Encountered the symbol "0" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset

执行EXEC column_job_salary_restriction

ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to
'COLUMN_JOB_SALARY_RESTRICTION'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

请帮助我,我是PLSQL的新手。

1 个答案:

答案 0 :(得分:2)

关于PLS-00103:

INPUT(5) := 'v_sql := '0 = 1';';

应该是:

INPUT(5) := 'v_sql := ''0 = 1'';';

双引号是一种逃避字符串内部引用的方法。

关于PLS-00306:

declare
  v_ret varchar2(100);
begin
  v_ret := column_job_salary_restriction('foo', 'bar');
end;
/

这是一个函数,所以你必须将返回值绑定到一个变量,你还必须给输入参数赋值。