阅读更多
create or replace procedure sp_tmp_test(v_col1 in varchar2,v_col2 in varchar2)
as
v_num NUMBER;
v_char varchar2(10);
sql_text varchar2(2000);
sql_text1 varchar2(2000);
notes varchar2(500);
p_nError NUMBER;
V_ERROR_MESSAGE VARCHAR2(500);
BEGIN
select count(*) into v_num from user_tables where table_name='T_TEMP';
--create temporary table
execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
COL1 VARCHAR2(10),
COL2 VARCHAR2(10)
) ON COMMIT delete ROWS';
--insert data
sql_text:='insert into t_temp values(:1,:2)';
execute immediate sql_text using v_col1,v_col2;
--sql_text1:='select col1 into :1 from t_temp ';
--execute immediate sql_text1 using v_num;
--select col1 into v_num from t_temp;
execute immediate 'select col1 from t_temp' into v_char;
dbms_output.put_line(v_char);
execute immediate 'delete from t_temp';
commit;
execute immediate 'drop table t_temp';
EXCEPTION
WHEN OTHERS THEN
execute immediate 'drop table t_temp';
p_nError := SQLCODE;
V_ERROR_MESSAGE := sqlerrm;
dbms_output.put_line('error: ' || p_nError || ' ' || sqlerrm(p_nError));
END;