create or replace procedure prc_statistic_declare(table_name varchar2 ,table_name_pass varchar2 ,not_exist varchar2,not_exist_record varchar2)
--eg:'t_statistic_bianyuanhu_month',t_statistic_bianyuanhu_month,('year','statistic_id')','yesr'
isv_sql_column varchar2(1000);
v_sql_record varchar2(1000);
get_declare varchar2(9000);
begin
declare
type v_column is record(c_value varchar2(200));
dec_column v_column;
type my_cursor is ref cursor;
v_statistic_cur my_cursor;
begin
v_sql_column :=' select column_name from user_tab_columns c where c.table_name = upper('||table_name||')
and c.column_name not in ('||not_exist||')';
dbms_output.put_line(v_sql_column);
get_declare :=' ';
open v_statistic_cur for v_sql_column;
fetch v_statistic_cur into dec_column;
while v_statistic_cur%found loop----------獲得declare陣列語句
get_declare :='type '||dec_column.c_value||' is table of '||table_name_pass||'.'||dec_column.c_value||'%type index by pls_integer;';
dbms_output.put_line('type v_'||dec_column.c_value||' is table of '||table_name_pass||'.'||dec_column.c_value||'%type index by pls_integer;');
fetch v_statistic_cur into dec_column;
end loop;
commit;
open v_statistic_cur for v_sql_column;
fetch v_statistic_cur into dec_column;
while v_statistic_cur%found loop----------獲得declare陣列語句
get_declare :=' dec_'||dec_column.c_value||' v_'|| dec_column.c_value||';';
dbms_output.put_line(' dec_'||dec_column.c_value||' v_'|| dec_column.c_value||';');
fetch v_statistic_cur into dec_column;
end loop;
commit;
dbms_output.put_line('');
dbms_output.put_line('');
v_sql_record :=' select column_name from user_tab_columns c where c.table_name = upper('||table_name||')
and c.column_name not in upper('||not_exist_record||')';
dbms_output.put_line(v_sql_record);
open v_statistic_cur for v_sql_record;
fetch v_statistic_cur into dec_column;
while v_statistic_cur%found loop-----------獲得record語句
get_declare := 'v_'||dec_column.c_value||' '||table_name_pass||'.'||dec_column.c_value||'%type,';
dbms_output.put_line(get_declare);
fetch v_statistic_cur into dec_column;
end loop;
commit;
open v_statistic_cur for v_sql_record;
fetch v_statistic_cur into dec_column;
while v_statistic_cur%found loop-----------獲得record語句
get_declare := 'rec_'||dec_column.c_value||' v_'|| dec_column.c_value||'; ';
dbms_output.put_line(get_declare);
fetch v_statistic_cur into dec_column;
end loop;
commit;
end;
end prc_statistic_declare;
ORACLE 儲存寫儲存過程總結
step01 需要建立乙個package 例如 create or replace package package name is end package name 這一步只是建立乙個package。step02 為建立好的package建立包體 例如 create or replace packa...
自己寫的通用分頁儲存過程
新手乙個,寫的最簡單的儲存過程分頁,上 吧,還請大神們多多調教!1 use bms 2go 3 object storedprocedure dbo pages script date 12 21 2015 11 48 57 4 set ansi nulls on5go 6set quoted id...
自己寫的帶分頁的儲存過程
儲存過程 create procedure dbo.select my num varchar 20 user varchar 40 pagenum int,countt int output asset nocount on if user is null select countt count ...