CREATE OR REPLACE procedure modifyStuinfo
(
  id in stuinfo.ID%type,
  stuName in stuinfo.STUNAME%type,
  password in stuinfo.PASSWORD%type,
  stuClass in stuinfo.STUCLASS%type,
  actor in stuinfo.ACTOR%type,
  computer in stuinfo.COMPUTER%type,
  message out varchar2
)
as
begin
  execute immediate 'update stuinfo set stuName='||&stuName||',password='||&password||',stuClass='||&stuClass||',actor='||&actor||',computer='||&computer||' where id='||&id||';
  commit;
  message:='更新成功';
  exception when others then
  message:='更新失败;
  rollback;
end;动态sql这一段有问题,不懂连接引号,字符型参数、整型参数的写法。参数id是整型,其他是字符。目前只作控制台输入和输出用。

解决方案 »

  1.   

    把&去掉,没有这个写法
    ',password='||&password||',
    最好改成',password='''||&password||''',这样比较保险,后面的一样
      

  2.   

    SQL_STMT VARCHAR2(256) ='update stuinfo set stuName= :stuName,password=:password,stuClass=:stuClass,actor=:actor,computer=:computer where id=:id';
    BEGIN
        MESSAGE := '更新成功';
        EXECUTE IMMEDIATE SQL_STMT
            USING STUNAME, PASSWORD, STUCLASS, ACTOR, COMPUTER, ID;
    EXCEPTION
        WHEN OTHERS THEN
            MESSAGE := '更新失败';
            RETURN;
    END;
      

  3.   


    execute immediate 'update stuinfo set stuName='''||stuName||''',password='''||password||''',stuClass='''||stuClass||''',actor='''||actor||''',computer='''||computer||''' where id='''||id||''';
      

  4.   

    有必要用动态SQL吗?为什么不直接写
    CREATE OR REPLACE procedure modifyStuinfo
    (
      v_id in stuinfo.ID%type,
      v_stuName in stuinfo.STUNAME%type,
      v_password in stuinfo.PASSWORD%type,
      v_stuClass in stuinfo.STUCLASS%type,
      v_actor in stuinfo.ACTOR%type,
      v_computer in stuinfo.COMPUTER%type,
      message out varchar2
    )
    as
    begin
      MESSAGE := '更新成功';
      update stuinfo
          set stuName=v_stuName,
              password=v_password,
              stuClass=v_stuClass,
              actor=v_actor,
              computer=v_computer
          where id=v_id;
      commit;
    EXCEPTION
        WHEN OTHERS THEN
            MESSAGE := '更新失败';
            RETURN;
    END;
      

  5.   

    这里使用stuName='||&stuName||';"&"符号会出问题如果你想要数据库中的字段也显示成"&stuName",最好将"&"改成ascii码形式:stuName=chr(38)||'stuName'
      

  6.   

    CREATE OR REPLACE procedure modifyStuinfo
    (
      id in stuinfo.ID%type,
      stuName in stuinfo.STUNAME%type,
      password in stuinfo.PASSWORD%type,
      stuClass in stuinfo.STUCLASS%type,
      actor in stuinfo.ACTOR%type,
      computer in stuinfo.COMPUTER%type,
      message out varchar2
    )
    as
    begin
      execute immediate 'update stuinfo set stuName='||stuName||',password='||password||',stuClass='||stuClass||',actor='||actor||',computer='||computer||' where id='||id||';
      commit;
      message:='更新成功';
      exception when others then
      message:='更新失败;
      rollback;
    end;