【问题标题】:Error: PL/SQL: SQL Statement ignored错误:PL/SQL:忽略 SQL 语句
【发布时间】:2014-07-19 18:51:54
【问题描述】:

我正在尝试向新表中添加一列并使用过程更新该列。但我遇到了 2 个错误。

错误:PL/SQL:忽略 SQL 语句。错误:PL/SQL:ORA-00947:不是 足够的价值

不知道如何找出它们。请帮帮我!!

ALTER TABLE emp1
  ADD Bonus integer;

set serveroutput on

CREATE OR REPLACE Procedure proc2_update

AS

BEGIN

   dbms_output.put_line('Truncate Table emp1');

   execute immediate 'truncate table emp1';

   dbms_output.put_line('Truncated Table emp1 successfully');

   dbms_output.put_line('Insert into Table emp1');

   insert into emp1 select * from emp;

   dbms_output.put_line('Inserted into Table emp1 successfully');

   dbms_output.put_line('Update Table emp1');

   if Deptno= 10 then 

  update emp1 set Bonus = sal * 10/100;

  Elsif Deptno= 20 then 

  update emp1 set Bonus = sal * 20/100;

  elsif Deptno= 30 then 

  update emp1 set Bonus = sal * 30/100;

  else 

  update emp1 set Bonus = sal * 40/100;

  end if;

   END proc2_update;

/

【问题讨论】:

    标签: oracle plsql


    【解决方案1】:

    我发现您发布的代码有两个问题

    而不是像下面那样做

    insert into emp1 select * from emp;
    

    指定列名以确保关闭喜欢

    insert into emp1(col1,col2,col3) select col1,col2,col3 from emp;
    

    你的UPDATE 对我来说看起来很奇怪。我想你的意思是这样做

    update emp1 set Bonus = sal * 10/100 WHERE Deptno= 10;
    

    【讨论】:

      【解决方案2】:

      问题最有可能出在这一行:

      insert into emp1 select * from emp;
      

      它告诉您并非emp1 的所有列都与emp 的列匹配。

      要么明确给出所有字段,要么更新表以使其列匹配。

      我认为你的程序应该是这样的:

      CREATE OR REPLACE Procedure proc2_update
      AS
      BEGIN
        dbms_output.put_line('Truncate Table emp1');
        execute immediate 'truncate table emp1';
        dbms_output.put_line('Truncated Table emp1 successfully');
        --
        dbms_output.put_line('Insert into Table emp1');
        insert into emp1
        ( col1 -- replace with real column names
        , col2
        )
        select col1
        ,      col2
        from   emp
        ;
         dbms_output.put_line('Inserted into Table emp1 successfully');
        --
        dbms_output.put_line('Update Table emp1');
        update emp1 set Bonus = sal * 10/100 where deptno = 10;
        update emp1 set Bonus = sal * 20/100 where deptno = 20;
        update emp1 set Bonus = sal * 30/100 where deptno = 30;
        update emp1 set Bonus = sal * 40/100 where deptno not in ( 10, 20, 30 );
      END proc2_update;
      

      【讨论】:

      • @user3856535:需要更多帮助?
      【解决方案3】:

      我同意,很可能是插入行中的 pronlem。 如果没有明确的 emp1 列列表和 emp 中的星号,则不应使用此表单。 更改 emp1 或 emp 可能会破坏很多 PL/SQL 代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-10
        • 1970-01-01
        • 2016-07-19
        • 2020-11-24
        • 2012-11-22
        • 2017-09-15
        相关资源
        最近更新 更多