Temporary Temporation Method in Oracle

xiaoxiao2021-03-06  72

Description: Some of the descriptions and sample code below are taken from 9CBS, which will not be clear, here, thank the relevant authors! 1 Syntax in Oracle, you can create two temporary tables: 1) Temporary session table CREATE GLOBAL tEMPORARY () ON COMMIT PRESERVE ROWS; 2) transaction-specific temporary table CREATE GLOBAL tEMPORARY () ON COMMIT DELETE ROWS; CREATE GLOBAL tEMPORARY tABLE MyTempTable built Although the temporary table is present, if the INSERT records and then uses another connection to go to SELECT, the record is empty. --On commit delete rows Description Tempory Table is Transaction Specifies, each submission Oracle will cut off the table (delete all rows) --on commit preserve rows Description Tempory table is specified, and when the interrupt session will cut the table. 2 created dynamically create or replace procedure pro_temp (v_col1 varchar2, v_col2 varchar2) as v_num number; begin select count (*) into v_num from user_tables where table_name = 'T_TEMP'; --create temporary table if v_num <1 then execute immediate 'CREATE Global TempoR2 (10), Col2 Varchar2 (10)) on commit delete rows'; end if; --insert data execute immediate 'insert intert data (' '|| v_col1 ||' ", '' '|| v_col2 ||' '') '; execute immediate' select col1 from t_temp 'into v_num; dbms_output.put_line (v_num); execute immediate' delete from t_temp '; commit; execute immediate' drop table t_temp '; End pro_Temp; Test: 15:23:54 SQL> SET ServerOutput on 15:24:01 SQL> EXEC Pro_Temp ('11 ',' 22 '); 11 PL / SQL process has been successfully completed. Time: 00: 00: 00.79 15:24:08 SQL> DESC T_TEMP; Error: ORA-04043: Object T_Temp does not exist 3 characteristics and performance (comparison with ordinary tables and views)

The temporary table only does not establish an index only in the current connection, so if the amount of data is relatively large or multiple queries, it is not recommended to use the data processing. When the data is complicated, the view is fast, and the view is when it is only querying the data. Recommended Cursor: Open Cursor for 'SQL CLAUSE'; welcome to supplement!

转载请注明原文地址:https://www.9cbs.com/read-91821.html

New Post(0)