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

解决方案 »

  1.   

    是不是各个列的类型不一样啊?这样改看看
    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
      

  2.   

    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
    )
      

  3.   

    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
      

  4.   

    不是很懂楼主意思。
      a1  a2  b1  b2
      50  60  70  80
      30  20  10  5
    行列都固定吗?
      

  5.   

    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
    这样试试,不会有问题的
      

  6.   

    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