【问题标题】:Error(11,10): PLS-00306: wrong number or types of arguments in call to 'CONSTRUCT'错误(11,10):PLS-00306:调用“CONSTRUCT”时参数的数量或类型错误
【发布时间】:2019-04-22 16:15:05
【问题描述】:

我是 plsql 的新手,我尝试运行这段代码,但它给出错误并且无法调试

create or replace type final as object ( ename1 varchar2(10), sal1 
NUMBER(7,2));--object 

create or replace type construct is table  of final; /*nested table of 
object type */

create or replace function returnmore (empno1 number) /*Function to 
return more*/
return construct 
AS
vemp construct:=construct();
vename varchar2(10);
vsal1 NUMBER(7,2);
begin

select ENAME,sal into vename,vsal1 from emp where empno=empno1;
vemp.extend;
vemp(1):=construct(vename,vsal1);
return vemp;
end;

但是给我一个错误

Function SYSTEM.RETURNMORE@loacaDB
Error(11,1): PL/SQL: Statement ignored
Error(11,10): PLS-00306: wrong number or types of arguments in call to 'CONSTRUCT'

我正在使用 oracle10gxe 和 sqldeveloper4.2

【问题讨论】:

    标签: oracle plsql oracle10g


    【解决方案1】:

    您可以更喜欢使用非保留关键字,例如 typ_emp,而不是保留的 final。

    SQL> create or replace type typ_emp as object ( ename1 varchar2(10), sal1 number(7,2));
    SQL> create or replace type construct is table of typ_emp; 
    

    你可以转换你的功能如下:

    create or replace function returnmore( empno1 emp.empno%type ) 
     return construct AS
      vemp   construct := construct();
      vename varchar2(10);
      vsal1  number(7, 2);
    begin
      select ename, sal into vename, vsal1 from emp where empno = empno1;
      vemp.extend;
      vemp(1) := typ_emp(vename, vsal1);
      dbms_output.put_line(vemp(1).ename1);
    
      return vemp;
    end;
    /
    

    或其他处理相同操作的方式:

    SQL> create or replace function returnmore( empno1 emp.empno%type ) 
      return construct AS
      vemp   construct := construct();
      v_sql  varchar2(2000);
    begin
      v_sql := 'select typ_emp(ename, sal) from emp where empno = :v_empno1';
      execute immediate v_sql bulk collect into vemp using empno1;
      dbms_output.put_line(vemp(1).ename1);
    
      return vemp;
    end;
    /
    

    并通过调用进行测试

    SQL> set serveroutput on; 
    SQL> declare
      result construct;
    begin
      result := returnmore( 1 ); -- 1 is just an ordinary presumed value for empno 
    end; 
    /   --> this will return the employee name as printed.
    

    附:永远不要将SYSTEM 用户用于非管理目的。可能对您的数据库极为有害。

    【讨论】:

    • 在这种情况下我们是否需要使用动态 sql 以获得更好的性能或为什么
    • @Arun 不,您不需要性能,只是您可以尝试使用的另一个建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多