csii_根據acct表同一個acctnbr(列轉行)動態sql_儲存過程

wisdomone1發表於2010-11-25

create or replace procedure proc_acct(in_table in varchar2 default 'ACCT',o_str out varchar2)
as
v_reccnt integer;
v_colcnt integer;
v_str varchar2(3000):='';
v_col user_tab_columns.COLUMN_NAME%type;
v_data_type user_tab_columns.data_type%type;
v_data_length user_tab_columns.DATA_LENGTH%type;
cursor cur_acct is select infortyp,addr from acct;

v_infortyp acct.infortyp%type;
v_addr acct.addr%type;
begin

select count(1) into v_reccnt from acct;
for i in 1..v_reccnt loop
   for x in (select column_name,data_type,data_length
            from user_tab_columns
            where table_name=upper(in_table) and column_name not in('ACCTNBR')) loop

      v_str:=v_str||x.column_name||i||' '||x.data_type||''||'('||x.data_length||'),';
   end loop;
end loop;
v_str:=substr(v_str,1,length(v_str)-1);
v_str:='acctnbr number(22),'||v_str;
v_str:='create table v_t('||v_str;
v_str:=v_str||')';
o_str:=v_str;
execute immediate o_str;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-680287/,如需轉載,請註明出處,否則將追究法律責任。

相關文章