首先v_col不是表中的一列,而是你自定义的变量,其次缺少where条件,这样会导致全部替换的。

解决方案 »

  1.   

    回 magicnbh
    我现在就是想对表的每一列都进行处理。我想问这样的语句为什么会编译不了,thx!
      

  2.   

    要用动态SQL,你可以参考下面
    http://community.csdn.net/Expert/topic/2896/2896736.xml?temp=.4902155
      

  3.   

    动态SQL的例子,把自己需要的更新的字段名赋给v_string字符串来执行.
    create or replace function test return varchar2 as
        v_cursor number;
        v_string varchar2(200);
        v_row number;
    begin
        v_cursor:=dbms_sql.open_cursor;
        v_string:='update table a set a.字段=''OK'' where ...' ;
        dbms_sql.parse(v_cursor,v_string,dbms_sql.native);
        v_row:=dbms_sql.execute(v_cursor);
        dbms_sql.close_cursor(v_cursor);
        return ('成功执行'||v_row||'行!');
        exception
            when others then
                dbms_sql.close_cursor(v_cursor);
                return ('执行失败!'||sqlcode||sqlerrm);
                raise;
    end;
      

  4.   

    create or replace procedure SP_REPLACE (v_tablename IN VARCHAR2) AS 
       v_col        varchar2(128);
       v_str        varchar2(200);
       cursor c_col is select column_name from all_tab_columns where table_name=v_tablename;
    begin
      open c_col;
        loop 
          fetch c_col into v_col; 
             v_str:='update' ||v_tablename|| 'set' ||v_col|| '=replace('||v_col||','*','')';
             dbms_output.put_line(v_str);
             execute immediate v_str;
          exit when c_col%notfound; 
        end loop;
        commit;
     close c_col;
    end;改成这样还不行
    编译无错误,运行出现错误
    SQL> exec SP_replace('TEST');begin SP_replace('TEST'); end;ORA-06502: PL/SQL: 数字或值错误 :  字符到数值的转换错误
    ORA-06512: 在"SCOTT.SP_REPLACE", line 9
    ORA-06512: 在line 1
      

  5.   

    v_col        varchar2(128);
    v_col 不是列,怎么能执行