我如何模拟' LISTAGG' Oracle 10g中的功能?

时间:2016-08-23 17:23:22

标签: sql oracle oracle10g listagg

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { if status == .NotDetermined { print ("Loction use not determined") return } if status == .Denied { print ("Location determined") return } guard status == .AuthorizedWhenInUse else { print("Location not using"); return; } print("Location using."); ownMapView.showsUserLocation = true; } orig_system作为值,他们有很多DNBowner_table_id相关联。我正在尝试将所有ID从多行带到一行。

但Oracle 10g不支持DNB。有没有其他方法可以在DNB的单行中连接所有listagg

以下是使用的查询:

OWNER_TABLE_ID

以下是样本数据:

SELECT OWNER_TABLE_ID,LISTAGG (ORIG_SYSTEM,',') WITHIN GROUP (ORDER BY ORIG_SYSTEM)
   from APPS.HZ_ORIG_SYS_REFERENCES
   WHERE ROWNUM < 100 GROUP BY OWNER_TABLE_ID

预期结果:

OWNER_TABLE_ID, ORIG_SYSTEM
182403  DNB
16604   DNB
84818   DNB
172891  DNB
16605   DNB
84819   DNB
205544  DNB
16606   DNB
84820   DNB

1 个答案:

答案 0 :(得分:0)

这是一个使用分层查询(包含所有铃声和口哨声)和分析函数row_number()的解决方案 - 两者都在Oracle 10中可用。注意:如果您有更多内容,则需要partition by子句不止一个ORIG_SYSTEM;我按OWNER_TABLE_ID命令null(意思是“随机”),但您可以根据需要按顺序排序(例如,按自己的顺序,按升序或递减顺序排列) - 没有这样的顺序虽然在你的例子中可见。

with
     hz_orig_sys_references ( owner_table_id, orig_system ) as (
       select 182403, 'DNB' from dual union all
       select 16604 , 'DNB' from dual union all
       select 84818 , 'DNB' from dual union all
       select 172891, 'DNB' from dual union all
       select 16605 , 'DNB' from dual union all
       select 84819 , 'DNB' from dual union all
       select 205544, 'DNB' from dual union all
       select 16606 , 'DNB' from dual union all
       select 84820 , 'DNB' from dual
     ),
     prep ( owner_table_id, orig_system, rn ) as (
       select owner_table_id, orig_system, 
              row_number() over (partition by orig_system order by null)
       from   hz_orig_sys_references
     )
select orig_system, 
       ltrim(sys_connect_by_path(owner_table_id, ','), ',')  as owner_tables
from   prep     
where  connect_by_isleaf = 1
connect by orig_system = prior orig_system and rn = prior rn + 1
start with rn = 1;

ORIG_SYSTEM  OWNER_TABLES
------------ ----------------------------------------------------------
DNB          182403,16604,84818,172891,84820,84819,205544,16606,16605