Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 191389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:20:14+00:00 2026-05-11T16:20:14+00:00

I’d like to run a query like the one below against an Oracle 9i

  • 0

I’d like to run a query like the one below against an Oracle 9i database from Java (an example table structure and example data are below).

SELECT deptno
,      SUBSTR(comma_list, 2)    comma_list
FROM   (SELECT deptno
        ,      SYS_CONNECT_BY_PATH(ename, ',')    comma_list
        ,      row_number
        ,      row_count
        FROM  (SELECT deptno
               ,      ename
               ,      ROW_NUMBER()OVER(PARTITION BY deptno
                                       ORDER BY     empno)    row_number
               ,      COUNT(*)OVER(PARTITION BY deptno)       row_count
               FROM   wd_emp)
        START WITH row_number = 1
        CONNECT BY deptno = PRIOR deptno
        AND        row_number = PRIOR row_number + 1)
WHERE  row_number = row_count;

This works fine. However, if the sys_connect_by_path which builds up comma_list hits the varchar2 4000 character limit, then I get an “ORA-01489: result of string concatenation is too long” error.

Does anyone have any suggestions on how to overcome this limit so my concatenation can exceed 4000 characters?

Tables and example data:


CREATE TABLE WD_DEPT(DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY
                    ,DNAME VARCHAR2(14) 
                    ,LOC VARCHAR2(13));

CREATE TABLE WD_EMP(EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY
                   ,ENAME VARCHAR2(10)
                   ,JOB VARCHAR2(10)
                   ,MGR NUMBER(4)
                   ,HIREDATE DATE
                   ,SAL NUMBER(7,2)
                   ,DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES WD_DEPT);

INSERT INTO WD_DEPT VALUES(10,'TEAM GREGORY','TABLE 3');
INSERT INTO WD_DEPT VALUES(20,'TEAM HANLEY','TABLE 2');
INSERT INTO WD_DEPT VALUES(30,'TEAM OFFIAH','TABLE 4');
INSERT INTO WD_DEPT VALUES(40,'TEAM BOTICA','TABLE 1');
INSERT INTO WD_DEPT VALUES(50,'TEAM SKERRETT','TABLE 4');
INSERT INTO WD_DEPT VALUES(60,'TEAM McGINTY','TABLE 1');
INSERT INTO WD_DEPT VALUES(70,'EMPTY TEAM','NO TABLE');

INSERT INTO WD_EMP VALUES(11,'GREGORY',  'TEAM LEAD',  28,   to_date('18-JAN-2000', 'DD-MON-RRRR'), 800,  10);
INSERT INTO WD_EMP VALUES(12,'BELL',     'DEVELOPER',  11,   to_date('17-JAN-2000', 'DD-MON-RRRR'), 600,  10);
INSERT INTO WD_EMP VALUES(13,'CLARKE',   'DEVELOPER',  11,   to_date('16-JAN-2000', 'DD-MON-RRRR'), 600,  10);
INSERT INTO WD_EMP VALUES(14,'HANLEY',   'TEAM LEAD',  28,   to_date('15-JAN-2000', 'DD-MON-RRRR'), 800,  20);
INSERT INTO WD_EMP VALUES(15,'BETTS',    'CONTRACTOR', 14,   to_date('14-JAN-2000', 'DD-MON-RRRR'), 700,  20);
INSERT INTO WD_EMP VALUES(16,'MILES',    'CONTRACTOR', 14,   to_date('13-JAN-2000', 'DD-MON-RRRR'), 700,  20);
INSERT INTO WD_EMP VALUES(17,'HAMPSON',  'DEVELOPER',  14,   to_date('12-JAN-2000', 'DD-MON-RRRR'), 600,  20);
INSERT INTO WD_EMP VALUES(18,'PRESTON',  'DEVELOPER',  14,   to_date('11-JAN-2000', 'DD-MON-RRRR'), 600,  20);
INSERT INTO WD_EMP VALUES(19,'OFFIAH',   'TEAM LEAD',  28,   to_date('10-JAN-2000', 'DD-MON-RRRR'), 800,  30);
INSERT INTO WD_EMP VALUES(20,'PLATT',    'DEVELOPER',  19,   to_date('09-JAN-2000', 'DD-MON-RRRR'), 600,  30);
INSERT INTO WD_EMP VALUES(21,'POTTER',   'DEVELOPER',  19,   to_date('08-JAN-2000', 'DD-MON-RRRR'), 600,  30);
INSERT INTO WD_EMP VALUES(22,'CASE',     'DEVELOPER',  19,   to_date('07-JAN-2000', 'DD-MON-RRRR'), 600,  30);
INSERT INTO WD_EMP VALUES(23,'BOTICA',   'TEAM LEAD',  28,   to_date('06-JAN-2000', 'DD-MON-RRRR'), 800,  40);
INSERT INTO WD_EMP VALUES(24,'GILL',     'DEVELOPER',  23,   to_date('05-JAN-2000', 'DD-MON-RRRR'), 600,  40);
INSERT INTO WD_EMP VALUES(25,'SKERRETT', 'TEAM LEAD',  28,   to_date('04-JAN-2000', 'DD-MON-RRRR'), 800,  50);
INSERT INTO WD_EMP VALUES(26,'McGINTY',  'TEAM LEAD',  28,   to_date('03-JAN-2000', 'DD-MON-RRRR'), 800,  60);
INSERT INTO WD_EMP VALUES(27,'LOWE',     'MANAGER',    28,   to_date('02-JAN-2000', 'DD-MON-RRRR'), 900,  NULL);
INSERT INTO WD_EMP VALUES(28,'MONIE',    'MANAGER',    NULL, to_date('01-JAN-2000', 'DD-MON-RRRR'), 1000, NULL);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:20:14+00:00Added an answer on May 11, 2026 at 4:20 pm

    Is it necessary to build the comma-list in SQL?

    Since you are running this from Java anyway, maybe you could query rows with “parent_id” ,”child_id”, “tree_level” columns and build the employee path in your application code ? I suppose you are splitting it into a List now anyway (a 4000 character string cannot be for direct display purposes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.