exception 不能写在循环里面吧,语法问题

解决方案 »

  1.   

    增加了两行,试下
    create or replace procedure proc_trade
    as
    v_cname user_tab_columns.COLUMN_NAME%type;
    v_cvalue varchar2(50);
    cursor t_columname is select column_name as b from user_tab_columns where table_name='MDM_CUSTEPMASTER';
    begin
      open t_columname;
      loop
        fetch t_columname into v_cname;
        exit when t_columname%notfound;
        begin
        select v_cname into v_cvalue from mdm_custepmaster where trim(v_cname)='Y';
        exception
     
          when no_data_found then dbms_output.put_line('没有数据');
          when too_many_rows then dbms_output.put_line(v_cname);
          when others then dbms_output.put_line('错误情况不明');
      end;
        end loop;
        close t_columname;
     end;
      

  2.   

    就是在语句前后加了begin end 
    显示成sql code,颜色表示就显示不正常了
      

  3.   

    测试可用
    procedure a is
    v_cname user_tab_columns.COLUMN_NAME%type;
    v_cvalue varchar2(50);
    cursor t_columname is select column_name as b from user_tab_columns where table_name='MDM_CUSTEPMASTER';
    begin
      open t_columname;
      loop
        fetch t_columname into v_cname;
        exit when t_columname%notfound;
        begin
         select v_cname into v_cvalue from mdm_custepmaster where trim(v_cname)='Y';
        exception
          when no_data_found then dbms_output.put_line('没有数据');
          when too_many_rows then dbms_output.put_line(v_cname);
          when others then dbms_output.put_line('错误情况不明');
        end;
        end loop;
    close t_columname;
    end;
      

  4.   

    是不会出现问题了,但是还是没查询出来东西
    我想要查出来这个表中哪个列中的值有N,可能是‘N   ’,或者'    N   '之类的,只要是trim(属性值)=N的都要查出来,怎么办啊?
      

  5.   

    select v_cname into v_cvalue from mdm_custepmaster where trim(v_cname)='Y';v_cname本身是一个字符串,这样相当于select了一列常数,而不是选择了表中的数据
      

  6.   

    给你一个函数,参数为要执行的select语句,返回值为select语句的执行结果
    FUNCTION GetValue (P_SQL in varchar2) RETURN varchar2 IS
      str varchar2(500);
    mycursor INTEGER; 
    ignore INTEGER;
    begin
    mycursor := dbms_sql.open_cursor;
    dbms_sql.parse(mycursor,P_SQL,1);
      DBMS_SQL.DEFINE_COLUMN(mycursor,1,str,500); 
    ignore := dbms_sql.execute(mycursor);
    if DBMS_SQL.FETCH_ROWS(mycursor)<> 0 then
    DBMS_SQL.COLUMN_VALUE(mycursor,1,str);
    end if;
    dbms_sql.close_cursor(mycursor);
    return str;
    END;
      

  7.   

    select v_cname into v_cvalue from mdm_custepmaster where trim(v_cname)='Y';
    这行改为
    v_cvalue:=GetValue('select '||v_cname||' from mdm_custepmaster where trim('||v_cname||')=''Y''');
      

  8.   

    终于给整好了,代码如下:
    create or replace procedure proc_trade
    as
    v_cname user_tab_columns.COLUMN_NAME%type;
    v_cvalue varchar2(50):=' ';
    cursor t_columname is select column_name from user_tab_columns where table_name='MDM_CUSTEPMASTER';
    begin
      open t_columname;
      loop
        fetch t_columname into v_cname;
        exit when t_columname%notfound;
        v_cvalue:=GetValue('select '||v_cname||' from MDM_CUSTEPMASTER where trim('||v_cname||')=''N'''); 
        if v_cvalue<>' ' then 
          DBMS_OUTPUT.PUT_LINE(v_cname);
          end if;
        end loop;
    close t_columname;
    end;
    create or replace function GetValue(PL_SQL in varchar2) return varchar2 is
      str varchar2(500);
      mycursor INTEGER; 
    ignore INTEGER;
    begin
      mycursor := dbms_sql.open_cursor;
      dbms_sql.parse(mycursor,PL_SQL,1);
      DBMS_SQL.DEFINE_COLUMN(mycursor,1,str,500); 
      ignore := dbms_sql.execute(mycursor);
    if DBMS_SQL.FETCH_ROWS(mycursor)<> 0 then
    DBMS_SQL.COLUMN_VALUE(mycursor,1,str);
    end if;
    dbms_sql.close_cursor(mycursor);  
      return(str);
    end GetValue;