临时表的动态创建于动态删除的测试。
15:22:49 SQL> create or replace procedure pro_temp(v_col1 varchar2,v_col2 varchar2) as
15:23:01 2 v_num number;
15:23:01 3 begin
15:23:01 4 select count(*) into v_num from user_tables where table_name='T_TEMP';
15:23:01 5 --create temporary table
15:23:01 6 if v_num<1 then
15:23:01 7 execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
15:23:01 8 COL1 VARCHAR2(10),
15:23:01 9 COL2 VARCHAR2(10)
15:23:01 10 ) ON COMMIT delete ROWS';
15:23:01 11 end if;
15:23:01 12 --insert data
15:23:01 13 execute immediate 'insert into t_temp values('''||v_col1||''','''||v_col2||''')';
15:23:03 14 execute immediate 'select col1 from t_temp' into v_num;
15:23:36 15 dbms_output.put_line(v_num);
15:23:50 16 execute immediate 'delete from t_temp';
15:23:54 17 commit;
15:23:54 18 execute immediate 'drop table t_temp';
15:23:54 19 end pro_temp;
15:23:54 20 /
过程已创建。
已用时间: 00: 00: 00.78
15:23:54 SQL> set serveroutput on
15:24:01 SQL> exec pro_temp('11','22');
11
PL/SQL 过程已成功完成。
已用时间: 00: 00: 00.79
15:24:08 SQL> desc t_temp;
ERROR:
ORA-04043: 对象 t_temp 不存在
15:24:14 SQL>
15:23:01 2 v_num number;
15:23:01 3 begin
15:23:01 4 select count(*) into v_num from user_tables where table_name='T_TEMP';
15:23:01 5 --create temporary table
15:23:01 6 if v_num<1 then
15:23:01 7 execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
15:23:01 8 COL1 VARCHAR2(10),
15:23:01 9 COL2 VARCHAR2(10)
15:23:01 10 ) ON COMMIT delete ROWS';
15:23:01 11 end if;
15:23:01 12 --insert data
15:23:01 13 execute immediate 'insert into t_temp values('''||v_col1||''','''||v_col2||''')';
15:23:03 14 execute immediate 'select col1 from t_temp' into v_num;
15:23:36 15 dbms_output.put_line(v_num);
15:23:50 16 execute immediate 'delete from t_temp';
15:23:54 17 commit;
15:23:54 18 execute immediate 'drop table t_temp';
15:23:54 19 end pro_temp;
15:23:54 20 /
过程已创建。
已用时间: 00: 00: 00.78
15:23:54 SQL> set serveroutput on
15:24:01 SQL> exec pro_temp('11','22');
11
PL/SQL 过程已成功完成。
已用时间: 00: 00: 00.79
15:24:08 SQL> desc t_temp;
ERROR:
ORA-04043: 对象 t_temp 不存在
15:24:14 SQL>
...全文
相关推荐
oracle经验技巧
oracle经验技巧
MFC 动态创建
纯正的封装,算是彻底实现MFC程序的界面动态配置,是实现界面和功能的分离的基础
js动态创建、删除表格示例代码
生成一个2000*5的表格,每个单元格的内容是行号+逗号+列号,具体的实现过程如下,感兴趣的朋友可以参考下,希望对大家有所帮助
sqlserver通用的删除服务器上的所有相同后缀的临时表
代码如下: use tempdb if object_id(‘tempdb..#table’) is not null drop table tempdb..#table select name into tempdb..#table from (select * from sysobjects where xtype=’U’) a where a.name like ‘%test_select’ declare @table varchar(100),@count int select @count=count(name) from tempdb..#table while(@count>0
动态创建库/表
在不确定数据库个数,或不确定 数据库表内容的情况下。对创建数据库和表进行封装


基础和管理
