PLSQL的 dynamic sql小例子

开始

SET serveroutput ON;

DECLARE
  p_tab_name varchar2(20);
  cursor_name INTEGER;
  p_rows_del INTEGER;
BEGIN
   p_tab_name := 'EMP_CPY';

   cursor_name := DBMS_SQL.OPEN_CURSOR;

   DBMS_SQL.PARSE(cursor_name, 'DELETE FROM '||p_tab_name, DBMS_SQL.NATIVE);
   
   DBMS_OUTPUT.PUT_LINE('p_tab_name:'|| p_tab_name);

   p_rows_del := DBMS_SQL.EXECUTE (cursor_name);

   DBMS_SQL.CLOSE_CURSOR(cursor_name);

EXCEPTION
   WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,100));
END;

结束

posted @ 2012-11-30 08:42  健哥的数据花园  阅读(206)  评论(0编辑  收藏  举报