日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle的cols,Oraclecols_as_rows比对数据

發布時間:2025/3/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle的cols,Oraclecols_as_rows比对数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

AskTom提供的腳本,用于比對數據. create or replace type myscalartype as object ( rnum number, cname varchar2(30), val varc

AskTom提供的腳本,用于比對數據.

create or replace type myscalartype as object

( rnum number, cname varchar2(30), val varchar2(4000) )

/

create or replace type mytabletype as table of myscalartype

/

create or replace

function cols_as_rows( p_query in varchar2 ) return mytabletype

-- This function is designed to be installed ONCE per database, and

-- it is nice to have ROLES active for the dynamic sql, hence the

-- AUTHID CURRENT_USER.

authid current_user

-- This function is a pipelined function, meaning that it'll send

-- rows back to the client before getting the last row itself.

-- In 8i, we cannot do this.

pipelined

as

l_thecursor integer default dbms_sql.open_cursor;

l_columnvalue varchar2(4000);

l_status integer;

l_colcnt number default 0;

l_desctbl dbms_sql.desc_tab;

l_rnum number := 1;

begin

-- Parse, describe and define the query. Note, unlike print_table,

-- I am not altering the session in this routine. The

-- caller would use to_char() on dates to format and if they

-- want, they would set cursor_sharing. This routine would

-- be called rather infrequently. I did not see the need

-- to set cursor sharing therefore.

dbms_sql.parse( l_thecursor, p_query, dbms_sql.native );

dbms_sql.describe_columns( l_thecursor, l_colcnt, l_desctbl );

for i in 1 .. l_colcnt loop

dbms_sql.define_column( l_thecursor, i, l_columnvalue, 4000 );

end loop;

-- Now, execute the query and fetch the rows. iterate over

-- the columns and "pipe" each column out as a separate row

-- in the loop. Increment the row counter after each

-- dbms_sql row.

l_status := dbms_sql.execute(l_thecursor);

while ( dbms_sql.fetch_rows(l_thecursor) > 0 )

loop

for i in 1 .. l_colcnt

loop

dbms_sql.column_value( l_thecursor, i, l_columnvalue );

pipe row

(myscalartype( l_rnum, l_desctbl(i).col_name, l_columnvalue ));

end loop;

l_rnum := l_rnum+1;

end loop;

-- Clean up and return...

dbms_sql.close_cursor(l_thecursor);

return;

end cols_as_rows;

/

create or replace function

cols_as_rows8i( p_query in varchar2 ) return mytabletype

authid current_user

as

l_thecursor integer default dbms_sql.open_cursor;

l_columnvalue varchar2(4000);

l_status integer;

l_colcnt number default 0;

l_desctbl dbms_sql.desc_tab;

l_data mytabletype := mytabletype();

l_rnum number := 1;

begin

dbms_sql.parse( l_thecursor, p_query, dbms_sql.native );

dbms_sql.describe_columns( l_thecursor, l_colcnt, l_desctbl );

for i in 1 .. l_colcnt loop

dbms_sql.define_column( l_thecursor, i, l_columnvalue, 4000 );

end loop;

l_status := dbms_sql.execute(l_thecursor);

while ( dbms_sql.fetch_rows(l_thecursor) > 0 )

loop

for i in 1 .. l_colcnt

loop

dbms_sql.column_value( l_thecursor, i, l_columnvalue );

l_data.extend;

l_data(l_data.count) :=

myscalartype( l_rnum, l_desctbl(i).col_name, l_columnvalue );

end loop;

l_rnum := l_rnum+1;

end loop;

dbms_sql.close_cursor(l_thecursor);

return l_data;

end cols_as_rows8i;

/

以HR表為例,比對員工編號200和201的員工數據

column val format a20;

select a.cname,a.val,b.val from

table(cols_as_rows('select * from hr.employees where employee_id=200')) a,

table(cols_as_rows('select * from hr.employees where employee_id=201')) b

where a.cname=b.cname and (a.val is not null or b.val is not null)

order by a.cname;

本文永久更新鏈接地址:,

本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴

本文系統來源:php中文網

總結

以上是生活随笔為你收集整理的oracle的cols,Oraclecols_as_rows比对数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。