select rownum rid,tab_a.* from
(
select 'a1' colname,to_char(a1) value
from t1
union all
select 'a2' colname,to_char(a2) value
from t1
union all
select 'b1' colname,to_char(b1) value
from t1
union all
select 'b2' colname,to_char(b2) value
from t1
) tab_a
这样试试,不会有问题的
select rownum, x.*
from (
select * from tab t where t.a1 = a1
union all
select * from tab t where t.a2 = a2
union all
select * from tab t where t.b1 = b1
union all
select * from tab t where t.b2 = b2
) x
select rownum, x.*
from (
select * from tab t where t.a1 = a1
union all
select * from tab t where t.a2 = a2
union all
select * from tab t where t.b1 = b1
union all
select * from tab t where t.b2 = b2
)
是不是各个列的类型不一样啊?这样改看看
select rownum rid,tab_a.* from
(
select 'a1' colname,to_number(a1) value
from t1
union all
select 'a2' colname,to_number(a2) value
from t1
union all
select 'b1' colname,to_number(b1) value
from t1
union all
select 'b2' colname,to_number(b2) value
from t1
) tab_a
select rownum, x.*
from (
select 'a1' colname from tab t where t.a1 = a1
union all
select 'a2' colname from tab t where t.a2 = a2
union all
select 'b1' colname from tab t where t.b1 = b1
union all
select 'b2' colname from tab t where t.b2 = b2
) x
select rownum rid,tab_a.* from
(
select 'a1' colname,a1 value
from t1
union all
select 'a2' colname,a2 value
from t1
union all
select 'b1' colname,b1 value
from t1
union all
select 'b2' colname,b2 value
from t1
) tab_a