for c_cur in cur loop
  v_custcd := c_cur.CUST_CD;
  v_sectcd := c_cur.SECT_CD;
  dbms_output.put_line('The CUST_CD is ' || v_custcd);
  dbms_output.put_line('The SECT_CD is ' || v_sectcd);
  if (v_sectcd='nosuchsectcd') then
  tempSql := 'delete from T_QUEST_DTL where CUST_CD=' || v_custcd || 'current of cur';
  else
  tempSql := 'update T_QUEST_DTL set QUEST_DIV=' || '(select QUEST_DIV from T_QUEST_DTL where QUEST_TXT_1='~2600'' ||
  ' and SECT_CD='|| v_sectcd || ')';
  dbms_output.put_line('The tempSql is ' || tempSql);
  end if;
  update_cur := dbms_sql.open_cursor;
  dbms_sql.parse(update_cur, tempSql, dbms_sql.v7);
  proccesed := dbms_sql.execute(update_cur);
  dbms_sql.close(update_cur);
  end loop;
  commit;
 close cur;
在上一段程序中会根据select语句赋给c_cur的值来判断对当前的行进行删除或者更新,不知道这样写对不对,
还有current of cursor是不是对取出的当前行进行操作,其他的纪录不会受到影响,where后面除了current of cursor还可以加其他的条件吗?如果可以的话是用AND来连接?
谢谢大家,

解决方案 »

  1.   

    oracle中没这么用过, current of cursor_name 应当是Transact-SQL的吧?
    不清楚oracle是否支持
    建议表中建立唯一索引,然后根据唯一索引删除或更新数据
      

  2.   

    1、代码中有个地方引号用的不对   for c_cur in cur loop
          v_custcd := c_cur.cust_cd;
          v_sectcd := c_cur.sect_cd;
          dbms_output.put_line ('The CUST_CD is ' || v_custcd);
          dbms_output.put_line ('The SECT_CD is ' || v_sectcd);      if (v_sectcd = 'nosuchsectcd') then
             tempsql :=
                   'delete from T_QUEST_DTL where CUST_CD=' || v_custcd || 'current of cur';
          else
             tempsql :=
                   'update T_QUEST_DTL set QUEST_DIV='
                || '(select QUEST_DIV from T_QUEST_DTL where QUEST_TXT_1=''~2600''' --两个连续的单引号表示在字符串中用到一个引号
                || ' and SECT_CD='
                || v_sectcd
                || ')';
             dbms_output.put_line ('The tempSql is ' || tempsql);
          end if;      update_cur := dbms_sql.open_cursor;
          dbms_sql.parse (update_cur, tempsql, dbms_sql.v7);
          proccesed := dbms_sql.execute (update_cur);
          dbms_sql.close (update_cur);
       end loop;2、current of cursof就是处理当前cursor 所在行,举例:
    for i in cur loop
        update mytable
           set col1 = '1'
         where current of cur;
    end loop;