Oracle儲存過程使用動態游標

2021-09-08 11:47:21 字數 1814 閱讀 3086

spool f:/dbtest12.log;

set timing on;

set serveroutput on;

declare

--定義游標:獲取所有表

cursor c_alltables is

select t.

owner

,t.table_name

from all_tab_comments t

where t.

owner

='orcl'

;--定義游標:獲取表的所有字段

type ref_col is ref cursor;

c_col ref_col;

--獲取表所有欄位sql

sql_all_cols varchar

(300);

v_col varchar

(100);

--拼接字段

v_cols_sql varchar

(2000);

begin

--不限制 緩衝大小

dbms_output

.enable

(buffer_size=>

null);

--迴圈獲取表

for tabs in c_alltables loop

sql_all_cols :

='select column_name from all_tab_columns where owner='

''||tabs.

owner

||''

''||

' and table_name='

''||tabs.

table_name

||''

' order by column_id'

;--內迴圈前,清空變數

v_cols_sql :=''

;--迴圈獲取表字段

open c_col for sql_all_cols;

loop

fetch c_col into v_col;

exit when c_col%notfound;

if v_cols_sql is null

then

v_cols_sql :

= v_col;

else

v_cols_sql :

= v_cols_sql||

','||v_col;

endif

;end

loop

; close c_col;

--輸出 拼接sql

dbms_output

.put_line

('insert into '

||tabs.

owner

||'.'

||tabs.

table_name

||' ('

||v_cols_sql||

')')

;dbms_output

.put_line

('select '

||v_cols_sql||

' from '

||tabs.

owner

||'.'

||tabs.

table_name

||'_old;');

dbms_output

.put_line

('commit;');

dbms_output

.put_line(''

);endloop

;end;

oracle 動態儲存過程

1.定時 begin sys.dbms scheduler.create job job name job pro his delete cp job type stored procedure job action pro his delete cp start date sysdate,repe...

oracle動態呼叫 動態呼叫儲存過程

關鍵字 execute immediate sqlname using in 1 in 2 out c sql create or replace procedure p test a in varchar2,b in varchar2,c out varchar2 2 is 3 begin 4 c...

delphi動態呼叫oracle儲存過程

function fun logincheck var puserinfo tremployee var errormessage string flag string integer varadostoredproctemp tadostoredproc begin adostoredprocte...