日期:2014-05-17 浏览次数:20914 次
CREATE TABLE tabsrc(id NUMBER(5),sname VARCHAR2(50)); INSERT INTO tabsrc SELECT LEVEL,dbms_random.string('P',8 ) FROM dual CONNECT BY LEVEL<=20; CREATE OR REPLACE PROCEDURE p001(p_tablename IN VARCHAR2) AS v_id tabsrc.id%TYPE; v_sname tabsrc.sname%TYPE; BEGIN execute IMMEDIATE 'create table aaa'||p_tablename||'(id number(5),sname varchar2(50))'; BEGIN select id,sname INTO v_id,v_sname from tabsrc where rownum=1; EXCEPTION WHEN No_Data_Found THEN raise_application_error(-20102,'** Thats no data in tabsrc now! **'); END; Dbms_Output.put_line('value:'||v_id||v_sname); execute IMMEDIATE 'insert into aaa'||p_tablename||' values ('''||v_id||''','''||v_sname||''')'; IF SQL%ROWCOUNT=1 THEN DELETE FROM tabsrc WHERE id=v_id AND sname=v_sname; END IF; END p001; EXEC p001('001'); Line Pos Text 23 PL/SQL block, executed in 0.047 sec. value:1|pSn%@~8 Total execution time 0.047 sec. SELECT * FROM aaa001; ID SNAME 1 |pSn%@~8 SELECT Count(*) FROM tabsrc WHERE id=1 AND sname='pSn%@~8'; COUNT(*) 0
------解决方案--------------------