listagg

oracle Select dates for items sold within 1 minute of each other

谁说我不能喝 提交于 2021-02-08 11:45:25
问题 Oracle 12c database. I have a car sales table: CREATE TABLE CAR_SALES ( NUM_CARS NUMBER(10,0), EQUIPMENT_TYPE VARCHAR2(100), LOCATION VARCHAR2(500), SOLD_DATE DATE ) ; --Insert sample data insert into car_sales (num_cars,equipment_type,location,sold_date) values ('8','Rovers','coventry','07-SEP-19 10:00:12'); insert into car_sales (num_cars,equipment_type,location,sold_date) values ('1','Rovers','coventry','07-SEP-19 10:00:45'); insert into car_sales (num_cars,equipment_type,location,sold

LISTAGG in ORACLE

点点圈 提交于 2021-02-05 06:11:05
问题 I am trying to use LISTAGG() to fetch more than two columns. SELECT deptname, deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees FROM emp GROUP BY deptno; But it is throwing this error: : FROM keyword not found where expected 00000 - "FROM keyword not found where expected" *Cause: *Action: Error at Line: 3 Column: 12 Can please somebody explain why it is? 回答1: The LISTAGG analytic function was introduced in Oracle 11g Release 2 . So, if you are on older version, you won't

How to concat rows separated by a space in oracle?

百般思念 提交于 2021-01-29 13:18:55
问题 I am trying to concat/merge rows in a table to one single row. I tried using listagg but due to varchar limitation this doesn't work. create table tmp(word VARCHAR2(4000), lvl NUMBER); insert into tmp2 values('python',1); insert into tmp2 values('java',2); select listagg(word,' ') within group(order by lvl) as listagg_output from tmp; The output should look like python java. 回答1: What will you do with such a long string? Anyway, have a look at this example; if listagg won't work, xmlagg will.

oracle sql listagg [duplicate]

寵の児 提交于 2020-01-24 13:02:11
问题 This question already has an answer here : Not able to use LISTAGG (1 answer) Closed 2 years ago . SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees FROM emp GROUP BY deptno; Error:- ORA-00923: FROM keyword not found where expected 00923. 00000 - "FROM keyword not found where expected" *Cause: *Action: Error at Line: 1 Column: 42 Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production 回答1: For the 10gR2 or 11gR1 versions of Oracle , you can use

Transposing and aggregating Oracle column data

*爱你&永不变心* 提交于 2020-01-11 12:32:58
问题 I have the following data Base End RMSA Item 1 RMSA Item 2 RMSA Item 3 RMSB Item 1 RMSB Item 2 RMSC Item 4 I want to convert it to the following format Key Products RMSA;RMSB Item 1, Item 2 RMSA Item 3 RMSC Item 4 Basically, those with similar results should be grouped into 1 line. However, I can't seem to get it to work using listagg, etc since I'm grouping on two columns. Is there any way to do this with a direct Oracle query? 回答1: You can use listagg() window analytic function twice as

Transposing and aggregating Oracle column data

早过忘川 提交于 2020-01-11 12:32:32
问题 I have the following data Base End RMSA Item 1 RMSA Item 2 RMSA Item 3 RMSB Item 1 RMSB Item 2 RMSC Item 4 I want to convert it to the following format Key Products RMSA;RMSB Item 1, Item 2 RMSA Item 3 RMSC Item 4 Basically, those with similar results should be grouped into 1 line. However, I can't seem to get it to work using listagg, etc since I'm grouping on two columns. Is there any way to do this with a direct Oracle query? 回答1: You can use listagg() window analytic function twice as

How to Use COLLECT with VARCHAR2 Oracle 10g

邮差的信 提交于 2020-01-04 06:05:33
问题 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