string-aggregation

comma-separated list as a result of select statement in Oracle [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-11-27 22:35:57
This question already has an answer here: How can I combine multiple rows into a comma-delimited list in Oracle? [duplicate] 11 answers I have a table named "person". It contains person's id and it's parent id (only one parent is possible). As a result of a query, I want a table with first column - a person id, and a second column - a list of it's children id's. How exactly to do this? I've read about listagg function, but I'm not sure if it is appropriate for my purpose. And this query produces an empty second column: select t1.id, (select t2.id from person t2 where t2.parent_id = t1.id) from

Oracle string aggregation

丶灬走出姿态 提交于 2019-11-27 15:54:35
My table structure look like this, I am new for the this field. I know the basic queries.But it's complicated for me. Please help me to do this. Table structure Customer Product piriority 10001 Main_product 1 10001 Sub_product1 2 10001 Sub_product2 2 10001 Sub_product3 2 10001 Sub_product4 2 10002 Main_product 1 10002 Sub_product1 2 10002 Sub_product2 2 Expected Output: Customer Main_Product Sub_product 10001 Main_product Sub_product1,Sub_product2,Sub_product3,Sub_product4 10002 Main_product Sub_product1,Sub_product2 I'm going to assume that the PRIORITY column is always 1 when there's a "main

Why does the wm_concat not work here?

孤街浪徒 提交于 2019-11-27 09:46:29
I have this query : (SELECT OBJECT_ID from cr_object_group_entries_vw where object_group_id IN (SELECT ITEM FROM TABLE(CR_FN_SPLIT_STRING('28,56',',')))) that returns : But when I do : SELECT wm_concat(object_id) FROM (SELECT OBJECT_ID from cr_object_group_entries_vw where object_group_id IN (SELECT ITEM FROM TABLE(CR_FN_SPLIT_STRING('28,56',',')))) I get a blank result... what am I doing wrong? You must avoid wm_concat function because it is undocumented and discovered as workaround at Oracle 8i times. Since times of old method with custom aggregate function as discovered by Tom Kyte here

How to write a query that does something similar to MySQL's GROUP_CONCAT in Oracle?

余生颓废 提交于 2019-11-27 08:25:34
问题 When I run the following SQL query in my Oracle database: SELECT p.pkt_nazwa, u.us_nazwa FROM punkty p, kategorie_uslug ku, usluga u WHERE ku.pkt_id = p.pktk_1_id AND ku.us_id = u.usk_1_id ORDER BY p.pkt_nazwa; I get the following output: NAME | SERVICE --------------------|------------------- Baita De Mario | WC Baita De Mario | Kuchnia Baita De Mario | Nocleg Bistro-Cafe | Bar Bistro-Cafe | Dyskoteka Bistro-Cafe | Kuchnia How would I go about to get the following output? NAME | SERVICES ---

MSSQL - GROUP_CONCAT

烈酒焚心 提交于 2019-11-26 23:47:50
问题 Here is the sample data : IdProduit Localisation Qte_EnMain 4266864286880063006 E2-R40-B-T 13.00000 4266864286880063006 E2-R45-B-T 81.00000 4266864286880063007 E2-R45-C-T 17.00000 4266864286880063008 E2-R37-B-T 8.00000 And this is what i would like to have IdProduit AllLocalisation 4266864286880063006 E2-R40-B-T (13), E2-R45-B-T (81) 4266864286880063007 E2-R45-C-T (17) 4266864286880063008 E2-R37-B-T (8) I watched all the examples of GROUP_CONCAT on the forum and I tried several tests. I don't

string_agg for sql server pre 2017

我只是一个虾纸丫 提交于 2019-11-26 23:28:09
问题 Can anyone help me make this query work for sql server 2014. This is working on Postgresql and probably on sql server 2017. On Oracle it is listagg instead of string_agg. Here is the sql: select string_agg(t.id,',') AS id from Tabel t I checked on the site some xml option should be used but I could not understand it. 回答1: In SQL Server pre-2017, you can do: select stuff( (select ',' + cast(t.id as varchar(max)) from tabel t for xml path ('') ), 1, 1, '' ); The only purpose of stuff() is to

Oracle: Combine multiple results in a subquery into a single comma-separated value [duplicate]

纵饮孤独 提交于 2019-11-26 22:47:08
This question already has an answer here: How can I combine multiple rows into a comma-delimited list in Oracle? [duplicate] 11 answers I'm trying to convert a single-columned subquery into a command-separated VARCHAR -typed list of values. This is identical to this question , but for Oracle rather than SQL Server or MySQL. There is an excellent summary of the available string aggregation techniques on Tim Hall's site. I found this that seems to work. Thoughts? SELECT SUBSTR (c, 2) concatenated FROM (SELECT SYS_CONNECT_BY_PATH ( myfield, ',') c, r FROM (SELECT ROWNUM ID, myfield, RANK () OVER

Oracle string aggregation

南楼画角 提交于 2019-11-26 17:24:51
问题 My table structure look like this, I am new for the this field. I know the basic queries.But it's complicated for me. Please help me to do this. Table structure Customer Product piriority 10001 Main_product 1 10001 Sub_product1 2 10001 Sub_product2 2 10001 Sub_product3 2 10001 Sub_product4 2 10002 Main_product 1 10002 Sub_product1 2 10002 Sub_product2 2 Expected Output: Customer Main_Product Sub_product 10001 Main_product Sub_product1,Sub_product2,Sub_product3,Sub_product4 10002 Main_product

How can multiple rows be concatenated into one in Oracle without creating a stored procedure? [duplicate]

大城市里の小女人 提交于 2019-11-26 14:33:05
This question already has an answer here: SQL Query to concatenate column values from multiple rows in Oracle 11 answers How can I achieve the following in oracle without creating a stored procedure? Data Set: question_id element_id 1 7 1 8 2 9 3 10 3 11 3 12 Desired Result: question_id element_id 1 7,8 2 9 3 10,11,12 There are many way to do the string aggregation, but the easiest is a user defined function. Try this for a way that does not require a function. As a note, there is no simple way without the function. This is the shortest route without a custom function: (it uses the ROW_NUMBER(

Oracle: Combine multiple results in a subquery into a single comma-separated value [duplicate]

女生的网名这么多〃 提交于 2019-11-26 08:26:26
问题 This question already has answers here : How can I combine multiple rows into a comma-delimited list in Oracle? [duplicate] (11 answers) Closed 5 years ago . I\'m trying to convert a single-columned subquery into a command-separated VARCHAR -typed list of values. This is identical to this question, but for Oracle rather than SQL Server or MySQL. 回答1: There is an excellent summary of the available string aggregation techniques on Tim Hall's site. 回答2: I found this that seems to work. Thoughts?