另一种方法:
-- this type is going to contain value's name and the value itself
SQL> create type t_data is object(
2 col1 varchar2(31),
3 col2 varchar2(31)
4 );
5 /
Type created
SQL> create type t_table is table of t_data;
2 /
Type created
之后,可以通过以下方式构造查询:
-- sample of data from the question + some extra data
-- just for the sake of demonstration.
SQL> with t1(EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL) as
2 ( select 100, 'Steven', 'King', 'SKING' from dual union all
3 select 101, 'Steven1', 'King1', 'SKING1' from dual
4 )
5 select col1
6 , col2
7 from t1 t
8 cross join table(
9 t_table( t_data('Employee_id', t.employee_id)
10 , t_data('First_name', t.first_name)
11 , t_data('Last_Name' , t.last_name)
12 , t_data('e-mail' , t.email)
13 )
14 )
15 ;
结果:
COL1 COL2
------------------------------- -------------------------------
Employee_id 100
First_name Steven
Last_Name King
e-mail SKING
Employee_id 101
First_name Steven1
Last_Name King1
e-mail SKING1
8 rows selected