listagg

How to Use COLLECT with VARCHAR2 Oracle 10g

我的未来我决定 提交于 2020-01-04 06:04:07
问题 I'm trying to get the COLLECT function to work for me. I'm using 10g and therefore found that LISTAGG and WM_CONCAT will not work (invalid identifier errors). The data I have is for example as follows. Order Lot 123 A23088 123 A23089 089 AABBCC 305 120848 305 CCDDYY What I need returned is as follows Order Lot 123 A23088, A23089 089 AABBCC 305 120848, CCDDYY Using the following, I get the error: TO_STRING is an invalid identifier TO_STRING ( CAST(COLLECT(DISTINCT LOT) AS varchar2(100)) ) AS

ORACLE SQL LISTAGG not returning expected result

不想你离开。 提交于 2019-12-31 05:45:35
问题 I am running Oracle Database 11g Enterprise 11.2.0.4.0, PL/SQL Release 11.2.0.4.0 and I am having some some issues getting the LISTAGG function to return the dataset I am expecting. Here is the scenario: I have a data set that looks like this I want to return the values in the MOD_CODE column in a one column on one row e.g.: AR4001,AR4002 I have been trying to complete this using the LISTAGG function e.g: SELECT LISTAGG(MOD_CODE,',') WITHIN GROUP (ORDER BY MOD_CODE) FROM XOTEST_A WHERE MOD

how to select not-null values from Oracle (optimized method)

依然范特西╮ 提交于 2019-12-24 13:03:16
问题 how can I select not null values from table ... lets image table as follows: master_id | date_update | name | dpt | channel | source | active --------------------------------------------------------------------------- 1 | 1/2/2015 15:43:21 | NULL | NULL | NULL | NULL | y 1 | 1/2/2015 15:43:21 | NULL | FIN | NULL | NULL | n 1 | 1/2/2015 15:40:16 | Elvis | NULL | NULL | NULL | n 1 | 1/2/2015 15:26:38 | NULL | NULL | CH1 | NULL | n 1 | 1/2/2015 14:57:02 | NULL | NULL | NULL | S1 | n 5 | 2/2/2015

how to select not-null values from Oracle (optimized method)

我与影子孤独终老i 提交于 2019-12-24 12:55:03
问题 how can I select not null values from table ... lets image table as follows: master_id | date_update | name | dpt | channel | source | active --------------------------------------------------------------------------- 1 | 1/2/2015 15:43:21 | NULL | NULL | NULL | NULL | y 1 | 1/2/2015 15:43:21 | NULL | FIN | NULL | NULL | n 1 | 1/2/2015 15:40:16 | Elvis | NULL | NULL | NULL | n 1 | 1/2/2015 15:26:38 | NULL | NULL | CH1 | NULL | n 1 | 1/2/2015 14:57:02 | NULL | NULL | NULL | S1 | n 5 | 2/2/2015

Oracle - unique Listagg values

微笑、不失礼 提交于 2019-12-24 12:54:40
问题 I am new to using Listagg. The following script works in respect of it gives me a list of values but, the list duplicates the values. Is it possible to use Listagg to return only a unique list of values. I am using oracle 10g. select distinct ds.catnr,ds.planqty, ds.ordnr, ds.posnr, ds.segnr, listagg(case when not li.paco is null then (select unique max(li1.paco) from leos_item li1 where li.av_part_no = li1.av_part_no) end, ', ') within group (order by pd.part_no) inq_no from oes_delsegview

SQL STUFF not working, why?

为君一笑 提交于 2019-12-24 07:28:32
问题 I did lot of querys on Oracle, and now I'm working with SQL Server. I saw the way of use similar function like listagg from oracle in sql server (stuff). Select sqd.id_question, STUFF((Select ',' + nm_departament from tb_departament where sqd.id_departament = id_departament for xml path('')),1,1,'') nm_departements from tb_survey_question_departament sqd The sintax its correct, but the result not. The goal is have for example for the 2 top rows, the result as 1 - RH, Planta Brasilia Where is

Convert WM_CONCAT to Listagg

社会主义新天地 提交于 2019-12-23 14:57:55
问题 My DBA is upgrading my oracle db from v10 to v12. I have some old SP's that uses wm_concat and I need to change it to listagg . The problematic code is this: Select registration_id,package_set_id, REPLACE(REPLACE(WM_CONCAT(REPLACE( (case when ROW_NUMBER() over (partition by product_id,product_detail_set_id,registration_id,product_family_id,application_id,package_Set_id, legal_status order by packset_country)=1 then legal_status else null end), ',' , '#')) OVER (PARTITION BY PRODUCT_ID,

What's the equivalent for LISTAGG in postgres?

天大地大妈咪最大 提交于 2019-12-23 06:53:09
问题 I have to replace the Oracle driver with the newest postgres. Postgres doesn't know the function LISTAGG. I have to concat values by comma separated. What's the equivalent for the Oracle function LISTAGG in Postgres? Thanks. 回答1: The equivalent function in Postgres is string_agg() select string_agg(col,',') from my_table string_agg : input values concatenated into a string, separated by delimiter 回答2: From Postgres 9.0 or later, I believe you could do something like this: SELECT c_id, STRING

How to return a redundant row for duplicate ID in single row in Oracle

怎甘沉沦 提交于 2019-12-23 05:52:28
问题 I have a Audit kind of table where we store some information based on some triggers in other tables. ID, Changed_Column, OldValue, NewValue will be available. Now there is a possibility for same Id there will be 3-4 duplicates since the changed column will have different values I wants to merge them into single row and take data For exmaple, ID ChangedColumn OldValue NewValue 1 Name Bob Roy 1 Age 26 28 1 Section B C When we select now it will display all the rows into separte but I wants to

How to return a redundant row for duplicate ID in single row in Oracle

房东的猫 提交于 2019-12-23 05:52:06
问题 I have a Audit kind of table where we store some information based on some triggers in other tables. ID, Changed_Column, OldValue, NewValue will be available. Now there is a possibility for same Id there will be 3-4 duplicates since the changed column will have different values I wants to merge them into single row and take data For exmaple, ID ChangedColumn OldValue NewValue 1 Name Bob Roy 1 Age 26 28 1 Section B C When we select now it will display all the rows into separte but I wants to