Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamic sql with LISTAGG

1055358Mar 14 2016 — edited Mar 14 2016

Hi,

I need  results as follow

EMPLOYEE_ID

--------------------------

206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, ...

Unfortunately i'm getting following  error which i cant fix my self.Please help me on this.

error  :

ORA-06550: line 53, column 45:

PLS-00103: Encountered the symbol ";" when expecting one of the following:

   . ( ) , * % & = - + < / > at in is mod remainder not rem

   <an exponent (**)> <> or != or ~= >= <= <> and or like like2

-----------------------------------------------------------------------------------------------------------------------------

My Code :

DECLARE

varSql VARCHAR2(4000);

BEGIN

varSql:= 'SELECT LISTAGG(A.EMPLOYEE_ID, ', ') WITHIN GROUP (ORDER BY S.EMPLOYEE_ID)';

varSQL := varSQL||' FROM HR.EMPLOYEES A';

EXECUTE IMMEDIATE varSql;

DBMS_OUTPUT.PUT_LINE(varSql);

END;

This post has been answered by Tubby on Mar 14 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 11 2016
Added on Mar 14 2016
6 comments
1,150 views