私が思いついた解決策よりも簡単にできると思いました。したがって、私は次のような問題に、よりシンプルなソリューションを持つことが可能であるかどうかを求めています:1つの列を2つの列に入れ替える
次のように私は、単一のカラム形式のデータを持っている:
COLUMN 1
=========
partnumber
version
partnumber
version
partnumber
version
etc
各項目は部品番号で識別され、バージョン。アイテムのバージョンは、そのアイテムの部品番号の直後にあります。しかし、私は次の形式でデータをたいと思います:より良い代替手段はあり
with data as (
select col,rownum+mod(rownum,2) item_index,row_number() over (partition by rownum+mod(rownum,2) order by rownum) colno from(
select -2141 col from dual
union all
select 5 col from dual
union all
select -2102 col from dual
union all
select 2 col from dual
union all
select -2021 col from dual
union all
select 4 col from dual))
select t1.col,t2.col from (select col,item_index from data where colno=1) t1
join (select col,item_index from data where colno=2) t2
on t1.item_index=t2.item_index;
with data as (
select col,rownum rn from (
select -2141 col from dual
union all
select 5 col from dual
union all
select -2102 col from dual
union all
select 2 col from dual
union all
select -2021 col from dual
union all
select 4 col from dual))
select t1.col,t2.col from (select col,rn+mod(rn,2) item_index from data where mod(rn,2)=1) t1
join (select col,rn+mod(rn,2) item_index from data where mod(rn,2)=0) t2
on t1.item_index=t2.item_index;
:
COLUMN 1 COLUMN 2
========== =========
partnumber version
partnumber version
partnumber version
etc etc
私は2つの代替クエリを、次のを思い付きましたの?
「直後」をどのように定義しますか?行が物理的にデータベースに格納される順序に頼っていますか?どんな理由であれ、それが変わったときにあなたは何をしますか? – mathguy
@mathguyの値は、VARRAYに格納されます。 – user2672165