Listagg function excdding 4000 characters
Hi allOracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
I'm using listagg function to concatenate the column values. I have nearly 4000 records in the table. I guess listagg function can concatenate till 4000 characters and if it exceeds 4000 then I'm getting an Ora error which says 'results of string concatenation is too long'.
case 1:
select listagg(id, ',') within group (order by id) from (select level as id from dual connect by level < 1000);
No Issue.
Case 2:
select listagg(id, ',') within group (order by id) from (select level as id from dual connect by level < 1050);
Ora-01489
How to handle the issue?
Thank youRod.
SQL> set long 10000
SQL> select listagg(id, ',') within group (order by id)
2 from (select level as id from dual connect by level < 1050)
3 /
from (select level as id from dual connect by level < 1050)
*
ERROR at line 2:
ORA-01489: result of string concatenation is too long
SQL> select rtrim(xmlagg(xmlelement(e,id,',').extract('//text()') order by id).GetClobVal(),',')
2 from (select level as id from dual connect by level < 1050)
3 /
RTRIM(XMLAGG(XMLELEMENT(E,ID,',').EXTRACT('//TEXT()')ORDERBYID).GETCLOBVAL(),','
--------------------------------------------------------------------------------
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,5
7,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,
84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,
108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,
148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,
168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,
188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,
228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,
RTRIM(XMLAGG(XMLELEMENT(E,ID,',').EXTRACT('//TEXT()')ORDERBYID).GETCLOBVAL(),','
--------------------------------------------------------------------------------
248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,
268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,
288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,
308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,
328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,
348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,
368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,
388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,
408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,
428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,
448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,
RTRIM(XMLAGG(XMLELEMENT(E,ID,',').EXTRACT('//TEXT()')ORDERBYID).GETCLOBVAL(),','
--------------------------------------------------------------------------------
468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,
488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,
508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,
528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,
548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,
568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,
588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,
608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,
628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,
648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,
668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,
RTRIM(XMLAGG(XMLELEMENT(E,ID,',').EXTRACT('//TEXT()')ORDERBYID).GETCLOBVAL(),','
--------------------------------------------------------------------------------
688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,
708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,
728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,
748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,
768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,
788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,
808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,
828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,
848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,
868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,
888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,
RTRIM(XMLAGG(XMLELEMENT(E,ID,',').EXTRACT('//TEXT()')ORDERBYID).GETCLOBVAL(),','
--------------------------------------------------------------------------------
908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,
928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,
948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,
968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,
988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,10
06,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,10
22,1023,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,10
38,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049
SQL>
SY.
Tags: Database
Similar Questions
-
Listagg function gives ORA-00979: not a GROUP BY expression error
Hello
I have an environment that supports the Listagg function. Suite works perfectly:
Select task_code, LISTAGG(ename||) e ('| role |') (',',') WITHIN GROUP (ORDER BY ename) as employees
team
where task_code = '01.07.05'
Task_code group
However, this is just a test request, the real is a little wider and I can't get the function works, I get ORA-00979: not a GROUP BY expression error.
Here's my query (the column names are in Dutch, but that shouldn't really be a problem):
SELECT distinct op_sod.sod_code, op_sod.sod_omschr_lang, op_ood.ood_code, op_ood.ood_omschr_lang, op_activiteit.act_code, op_activiteit.act_omschr_lang, op_taak.taak_code, op_taak.taak_omschr_lang, op_afdeling___master.afd_code, op_taak.belmo, op_taak_j.planning_la,
LISTAGG (op_ploeg.wn_naam |) ' ('| op_ploeg.rol |') (',',') WITHIN GROUP (ORDER BY op_ploeg.wn_naam) as employees.
"Write subtaak/mijlpaal toe."
op_teamplanning.subtaak_mijlpaal as subtaak_of_mijlpaal,
op_teamplanning.subtaak_omschr | -case when op_teamplanning.subtaak_mijlpaal = 'BELMO Mijlpaal' then ' (BRUNO mijlpaalnr: ' | nvl (op_teamplanning.nummer, 0) |) ')' other ' ' end
as subtaak_mijlpaal_omschrijving, op_teamplanning.deadline as date limit, op_teamplanning.status as status,
trim (both
case when op_teamplanning.vlag1 = 'Geen' and op_teamplanning.vlag2 = 'Geen' and op_teamplanning.vlag3 = 'Geen' and op_teamplanning.vlag4 = 'Geen'
and op_teamplanning.vlag5 = 'Geen' or op_teamplanning.vlag1 is null and op_teamplanning.vlag2 is null and op_teamplanning.vlag3 is null
op_teamplanning.vlag5 is null and op_teamplanning.vlag4 is null then 'Geen '.
Another pad (both case when op_teamplanning.vlag1 = 'Geen' then "else trim (both from op_teamplanning.vlag1) end) |
trim (both case when op_teamplanning.vlag2 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag2) end) |
trim (both case when op_teamplanning.vlag3 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag3) end) |
trim (both case when op_teamplanning.vlag4 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag4) end) |
trim (both case when op_teamplanning.vlag5 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag5) end) end) as Beleidsvlaggen,
op_teamplanning.naam_verantw as quotation, op_teamplanning.subtaak_id as subtaak_id, nvl (op_teamplanning.nummer, 0) as Nummer, nvl (op_teamplanning.regelgevingsagenda, 'Nee') as
Regelgeving, op_teamplan_subsubtaak.subsubtaak_submijlpaal as subsubtaak_submijlpaal, op_teamplan_subsubtaak.subsubtaak_id as subsubtaak_id, op_teamplan_subsubtaak.subsubtaak_omschr
like subsubtaak_omschr, op_teamplan_subsubtaak.deadline, sub_deadline, op_teamplan_subsubtaak.status as sub_status, op_teamplan_subsubtaak.naam_verantw as naam_verantw
Of...
WHERE THE...
Group of op_sod.sod_code, op_sod.sod_omschr_lang, op_ood.ood_code, op_ood.ood_omschr_lang, op_activiteit.act_code, op_activiteit.act_omschr_lang, op_taak.taak_code, op_taak.taak_omschr_lang, op_afdeling___master.afd_code, op_taak.belmo, op_taak_j.planning_la
Can someone tell me the reason for this error?
Thanks in advance!
Kind regards
NDG
NDG123 wrote:
I don't really understand your other question:
Is below for example, a group of expression?
op_teamplanning.subtaak_mijlpaal
After some additional research:
The group by mistake is not appear anymore when I delete all fields after the listagg field, that might be a clue to the solution.
It is not difficult to understand. You can have other columns not aggregated in your projection on the side of those listed in the group by expression.
The reason for ORA-01489 is that the resulting string will become long and exceeds 4000 bytes.
You will find several solution in this forum.
For example
-
LOVs using cascading on the Page elements with values exceeding 4000 characters
A few days ago, I asked a question on the community, but it turned out that there was something wrong with my account and they have removed the item, so I'll just post the solution I found here now:
Well, I found a way to use LOVs cascading on page elements with values exceeding 4000 characters:
Let's say I have a shuttle named P1_ORGANISATIE with "List of values" box, a dynamic LOV named "Source: lists of values Query" containing the value:
Select NAAM as display_value, ID like return_value
of NINEHAM
order by 1
If the number of records-NINEHAM is insufficient, the length of the value of P1_ORGANISATIE, which is a list of concatenated with colon separated digital ID, can exceed 4000 characters.
Now, suppose I have a list of selection called P1_TEST that is connected through "List of values"-> "Cascading LOV Parent article (s)" with P1_ORGANISATIE, using a named LOV dynamic with "Source: lists of values Query" containing:
Select distinct TST. NAAM as display_value, TST.ID as return_value
of the OTE NINEHAM
Join the AFDELINGEN ADG ON (ADG. OTE_ID = OTE.ID)
Join the DEELNEMERS DNR ON (DNR. ADG_ID = ADG.ID)
Join TESTDEELNEMERS TDR WE (TDR. DNR_ID = DNR.ID)
Join TESTEN TST ON (TST.ID = RDT. TST_ID)
where instr (":" |: P1_ORGANISATIE |) '':'', '':'' || OTE.ID | :'') > 0
order by 1
In this case, when P1_ORGANISATIE exceeds 3998 characters, you'll get an "ORA-01704: string literal too long"-error and the P1_TEST will show an element called "undefined".
A way around this is possible because for a named LOV, you can use a "function that returns a sql query" instead of a simple sql query. In other words, we can apply in the context of PL/SQL and thus have maximum for expressions of 32767 instead of 4000 characters. In addition, it is possible to use the two APEX_UTIL. STRING_TO_TABLE and APEX_COLLECTION.
Setting "Source: lists of query values" on the LOV appointed to P1_TEST with the following code will work:
DECLARE
l_selected APEX_APPLICATION_GLOBAL. VC_ARR2;
l_qry varchar2 (32767): =.
"Select distinct TST. NAAM as display_value, TST.ID as return_value
of the OTE NINEHAM
Join the AFDELINGEN ADG ON (ADG. OTE_ID = OTE.ID)
Join the DEELNEMERS DNR ON (DNR. ADG_ID = ADG.ID)
Join TESTDEELNEMERS TDR WE (TDR. DNR_ID = DNR.ID)
Join TESTEN TST ON (TST.ID = RDT. TST_ID)
$1
order by 1';
BEGIN
IF: P1_ORGANISATIE IS NULL
OR LENGTH(:P1_ORGANISATIE) < = 4000
THEN RETURN
Replace (l_qry
,'$1'
,' where instr (":" |: P1_ORGANISATIE |) '':'', '':'' || OTE.ID | :'') > 0'
);
ON THE OTHER
l_selected: = APEX_UTIL. STRING_TO_TABLE(:P1_ORGANISATIE);
APEX_COLLECTION. CREATE_OR_TRUNCATE_COLLECTION (p_collection_name = > 'ORGANISATIE_COLLECTIE');
FOR id IN 1.l_selected.count
LOOP
APEX_COLLECTION.add_member (p_collection_name = > 'ORGANISATIE_COLLECTIE')
, p_n001 = > to_number (l_selected (id))
);
END LOOP;
RETURN
Replace (l_qry
,'$1'
,'join apex_collections ON APC (APC. COLLECTION_NAME = "ORGANISATIE_COLLECTIE" AND APC. N001 = OTE.ID)"
);
END IF;
END;
Andreas Groenevelt says:
A few days ago, I asked a question on the community, but it turned out that there was something wrong with my account and they have removed the item, so I'll just post the solution I found here now:
Something was wrong with the whole site: AP invoice tolerance
I don't post anything substantive until we find out what is happening.
-
Problem copying 4000 characters of CLOB in VARCHAR2 (4000 TANK)
I'm migrating data from a table where it is stored in a CLOB to another table where I said a column of VARCHAR2(4000 CHAR).
I stated a cursor in the form:
(a) select columna, columnb, substr(clob_column,1,4000) of...
(b) select columna, columnb, dbms_lob.substr(clob_column,4000,1) of...
I then loop and EXTRACT the value of substr in a variable that is declared as VARCHAR2 (4000 TANK)
With the cursor version 'a', using the regular subtr function, I get: ORA-01461: can bind to a LONG value only for insert into a LONG column
With the slider 'b' version, by using the dbms_lob.substr function, I get: ORA-06502: PL/SQL: digital or value error: character string buffer too small
I use Oracle 10.2.0.4.0
I don't know yet what to watch next?Machinery says:
However, the database uses NLS_CHARACTERSET UTF8 and NLS_NCHAR_CHARACTERSET = AL16UTF16, which are multibyte so I was expecting the declared with semantic CHAR VARCHAR2 to be multibyte.
And it is. But in Oracle SQL VARCHAR2, as I already mentioned, must not exceed 4000 bytes. So even if you have declared it as 4000 characters, you'll get an error when the total length in bytes is greater than 4000. And since, according to the character set, a character can be 1 to 4 bytes, Oracle takes the best cases and allows you to declare it as max 4000 characters. How many characters will fit in eseccion is another question.
SY.
-
XML with embedded BLOBs 4000 characters maximum
Hi all
My proc (PROCEDURE pr_xml (pi_xml IN XMLTYPE)) database is delegated an XMLTYPE object as a parameter (from .NET). This doc XMLTYPE contains data image (in HEXADECIMAL format) that I need to store in a BLOB column. I can do this OK if the image is & lt; 4000 characters. If it is more than that, I have a problem. I tried the following two queries to get the BLOB data:
proc definition is
(1) select image
FROM XMLTABLE (' / DocumentElement / pic_record ' PASSAGE xmltype ('))
& lt; DocumentElement & gt;
& lt; pic_record & gt; & lt; PIC & gt; FFD8FFE000104A46494600010101006000600000FFE10066 & hellip; & hellip; & hellip; & hellip; & lt; / Peak & gt;
& lt; / pic_record & gt;
& lt; / DocumentElement & gt;
The COLUMNS ') image VARCHAR2 (4000) path 'Pic')
(2) SELECT extractvalue (column_value, 'Peak')
TABLE (xmlsequence (extract (xmltype ('))))
& lt; DocumentElement & gt;
& lt; pic_record & gt;
& lt; pic_record & gt; & lt; PIC & gt; FFD8FFE000104A46494600010101006000600000FFE10066 & hellip; & hellip; & hellip; & hellip; & lt; / Peak & gt;
& lt; / pic_record & gt;
& lt; / DocumentElement & gt;
(((, ' / DocumentElement/pic_record/Pic ")))
Using 1) I expect to be able to declare the COLUMN as a BLOB (VARCHAR2 (4000) - above), but the only types that you can use are MANY and VARCHAR.
Using 2) complains about the function of extractValue above 4000 characters.
Does anyone have any experience or suggestions. Thank you
TimTry extract () .getClobVal ()... However, it won't work that (at least in the pre - 11 g databases) if the size of PIC in it is encoded form is less than 64 KB. In addition, you are out of luck until the 11 g version. A better way to do it (at least in 11g) is to store the XML in a storage schema that maps the correctly coded data.
-
Hi all
I need to get the defeintion of the opinion GV$ SESSION.
I get only the first 4000 characters.
Select * from v$ fixed_view_definition where view_name = "GV$ SESSION;
Could you please help me?
Thank you
Cherif.
Cherif bh wrote:
Hi Martin,
Thanks for your help. I use 11.2.0.3 and is EXPAND_SQL_TEXT added 12 c.
I try to get the definition of a problem of performance on gv$ session; I need a list of the tables and columns and add the best predicates and access them using indices
You should be able to get the same thing on 11.2.0.3 too:
https://jonathanlewis.WordPress.com/2012/07/10/expanding-SQL/
The package is called DBMS_SQL2 it.
Randolf
-
Hello
I'm not able to get the data using the listagg function.
DB: 11g
CREATE TABLE HAS
(NAME, VARCHAR2 (10))
VAL VARCHAR2 (10));
INSERT INTO A VALUES ('LTR', ' 111');
INSERT INTO A VALUES ('LTR', ' 112');
INSERT INTO A VALUES ('LTR', ' 113');
COMMIT;
SELECT * FROM A;
SELECT * FROM WHERE A VAL IN (SELECT LISTAGG (A1. VAL, ",") THE GROUP (RANKING BY A1. (VAL) AN A1);
Break down the problem.
your subquery is:
SELECT LISTAGG (A1. VAL, ",") THE GROUP (RANKING BY A1. VAL) AN A1;
which returns the following STRING:
LISTAGG (A1. VAL, ",") WITHINGROUP (ORDERBYA1. VAL)
--------------------------------------------------------------------------------
111,112,113
Then use one to find... so basically, you do this:
SELECT * FROM WHERE A VAL IN ('111,112,113');
See the problem yet?
Looking around 'dynamic IN the list... "
I don't have the links, however, it is fairly easy to find in this search string
-
limit the number of values in the listagg function and create several games
Hi all
I have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
For example:
EMPNO CODEZONE
A111 AL
A111 AK
A111 AZ
A111 AR
A111 CA
A111 CO
A111 CT
TO A111
A111 DC
A111 FL
A111 GA
A111 HI
B222 AL
B222 AK
B222 AZ
B222 AI
B222 KS
B222 KY
THE B222
B222 ME
B222 MD
MY B222
B222 MI
B222 CA
B222 CO
B222 CT
B222 OF
Result set:
EMPNO CODEZONE
A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
A111 GA | HI
B222 AL | AK | AZ | AI | KS | KY | THE | ME | MD | MY
B222 MI | CA | CO | CT | OF
The above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.
Thank you1008754 wrote:
Hi allI have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
For example:
EMPNO CODEZONE
A111 AL
A111 AK
A111 AZ
A111 AR
A111 CA
A111 CO
A111 CT
TO A111
A111 DC
A111 FL
A111 GA
A111 HI
B222 AL
B222 AK
B222 AZ
B222 AI
B222 KS
B222 KY
THE B222
B222 ME
B222 MD
MY B222
B222 MI
B222 CA
B222 CO
B222 CT
B222 OFResult set:
EMPNO CODEZONE
A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
A111 GA | HI
B222 AL | AK | AZ | AI | KS | KY | THE | ME | MD | MY
B222 MI | CA | CO | CT | OFThe above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.
Thank you
ME_XE?with data (empno, areacode) as 2 ( 3 select 'A111', 'AL' from dual union all 4 select 'A111', 'AK' from dual union all 5 select 'A111', 'AZ' from dual union all 6 select 'A111', 'AR' from dual union all 7 select 'A111', 'CA' from dual union all 8 select 'A111', 'CO' from dual union all 9 select 'A111', 'CT' from dual union all 10 select 'A111', 'DE' from dual union all 11 select 'A111', 'DC' from dual union all 12 select 'A111', 'FL' from dual union all 13 select 'A111', 'GA' from dual union all 14 select 'A111', 'HI' from dual union all 15 select 'B222', 'AL' from dual union all 16 select 'B222', 'AK' from dual union all 17 select 'B222', 'AZ' from dual union all 18 select 'B222', 'IA' from dual union all 19 select 'B222', 'KS' from dual union all 20 select 'B222', 'KY' from dual union all 21 select 'B222', 'LA' from dual union all 22 select 'B222', 'ME' from dual union all 23 select 'B222', 'MD' from dual union all 24 select 'B222', 'MA' from dual union all 25 select 'B222', 'MI' from dual union all 26 select 'B222', 'CA' from dual union all 27 select 'B222', 'CO' from dual union all 28 select 'B222', 'CT' from dual union all 29 select 'B222', 'DE' from dual 30 ) 31 select 32 empno, listagg(areacode, ',') within group (order by emp_grp) as emp_list 33 from 34 ( 35 select 36 ceil(row_number() over (partition by empno order by areacode) / 10) as emp_grp, 37 empno, 38 areacode 39 from data 40 ) 41 group by empno, emp_grp; EMPNO EMP_LIST ------------------------------ ------------------------------ A111 AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL A111 GA,HI B222 AK,AL,AZ,CA,CO,CT,DE,IA,KS,KY B222 LA,MA,MD,ME,MI 4 rows selected. Elapsed: 00:00:00.05 ME_XE?
In the future, it would be nice if you could provide baseline data.
See you soon,.
-
LISTAGG function: "result of concatenating string is too long."
Hello
I use Oracle SQL developer 3.0.04 version. I tried using the LISTAGG function to group the data.
However, I get the error message,CREATE TABLE FINAL_LOG AS SELECT SESSION_DT, C_IP, CS_USER_AGENT, listagg(WEB_LINK, ' ') WITHIN GROUP(ORDER BY C_IP, CS_USER_AGENT) "WEB_LINKS" FROM webviews GROUP BY C_IP, CS_USER_AGENT, SESSION_DT ORDER BY SESSION_DT
SQL error: ORA-01489: result of concatenating string is too long
Is it possible to go around it, or are there other alternatives?Tim Hall has a page on the various techniques of aggregation of chain that guides you through an example of creating and using a user-defined aggregate.
On AskTom referenced by Tim page, there is an implementation of an aggregation function of string that returns a CLOB that you can use.
If you want to understand what makes the user-defined aggregate function, it may look a bit complex, especially if you have never looked at object types in PL/SQL. You don't need to understand all the details of the implementation if you use just the code, however, you can simply create the function and use it as you would with any other aggregate function.
Justin
-
Should what data type I use to store more than 4000 characters in a column
Hello friends,
I am currently using the suite oracle version for my database:
SQL > select * from v version $;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
PL/SQL release 11.1.0.6.0
SQL > create table clobexample (clob t1);
SQL > insert into clobexample values ('aaaaaaaaaaaaaaaaaaaa... ») ;
Error in the command line: 2 column: 8
Error report:
SQL error: ORA-01704: string literal too long
01704 00000 - "string literal too long."
* Cause: The string literal is longer than 4000 characters.
* Action: Use a string literal of more than 4,000 characters.
Longer values can only be entered using bind variables.
My request is that what kind of data can I use table to enter more than 4000 characters in the table, I even tried with clob (example) above, but it is not favourable.
Is there another way of letting?
Please help me.
Thank you in advance.
Kind regards.Hello
You can use the same CLOB, but you cannot insert directly, you may need to use the pl/sql.
Try the method mentioned in this link.
http://www.orafaq.com/Forum/t/48485/0/
see you soon
VT
-
How to store more than 4000 characters in a table
I have a requirement to store 4000 + string in the table. CLOB and BLOB cannot me because he has limitations of 4000 characters.
Any suggestions please.Pentaho seems based jdbc then look for an example of a jdbc clob insertion.
For example http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.htmlThis will probably be a better approach than messing around with blocks anonymous plsql, etc. that do not sound relevant to what you're trying to reach really.
This forum comment made me smile of the 'Integration of data head' @ Pentaho can:
http://forums.Pentaho.com/showthread.php?62231-insert-a-string-in-a-CLOBIt should work just fine. You probably need to swap your JDBC driver or something. Oracle can be mysterious in that dept. xxx xxxxxx, Chief Data Integration Pentaho, Open Source Business Intelligence
Reassuring.
-
Hi all
I'm still reviewing the analytical functions and I was wondering if someone can help me with the LISTAGG function. If this has nothing to do with some school or as homework. It's just me discover Oracle.
So, here is some code to insert data of base. It's just a person table and an array of phone number.
The following query returns all the person with their different phone numbers into a single line.-- to avoid name conflicts ;-) DROP TABLE PERSONNES CASCADE CONSTRAINTS purge; DROP TABLE TELEPHONES CASCADE CONSTRAINTS purge; -- create a person table with an id and a name. CREATE TABLE PERSONNES ( ID_PERSONNE NUMBER(10) , NOM VARCHAR2(100) , CONSTRAINT PK_PERSONNES PRIMARY KEY(ID_PERSONNE) ); -- table with phone number for persons. CREATE TABLE TELEPHONES ( ID_TELEPHONE NUMBER(10) , ID_PERSONNE NUMBER(10) , NUMERO VARCHAR2(100) , ACTIF CHAR(1) DEFAULT '0' -- is the number active or not. , CONSTRAINT PK_TELEPHONES PRIMARY KEY(ID_TELEPHONE) , CONSTRAINT UK_NUMERO UNIQUE(ID_TELEPHONE, NUMERO) , CONSTRAINT C_ACTIF_BOOLEAN CHECK(ACTIF IN ('0', '1')) , CONSTRAINT FK_PERSONNE FOREIGN KEY(ID_PERSONNE) REFERENCES PERSONNES ); -- insert some data. BEGIN -- create a person with a random name. FOR i in 1 .. 10 LOOP INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (i, InitCap(DBMS_RANDOM.STRING('l', 5))); -- for each newly inserted person, insert 5 different phone numbers. FOR j in 1 .. 5 LOOP INSERT INTO TELEPHONES(ID_TELEPHONE, ID_PERSONNE, NUMERO, ACTIF) VALUES(((i-1)*10) + j, i, '+32.' || TRUNC(DBMS_RANDOM.VALUE(1, 9)) || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 999), 'fm099') || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 99), 'fm09') || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 99), 'fm09'), CASE MOD(j, 2) WHEN 0 THEN '0' ELSE '1' END ); END LOOP; END LOOP; -- now insert two different person without any phone number. INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (100, InitCap(DBMS_RANDOM.STRING('l', 5))); INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (101, InitCap(DBMS_RANDOM.STRING('l', 5))); END;
But what I would like is to have numbers grouped by the flag of the ASSET.SELECT NOM, LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM ORDER BY 2 NULLS LAST;
I thought that maybe using the PARTITION CLAUSE but I couldn't understand it. So maybe one of you has a better idea? I want to do in a single query (without using the inline views or with clause). But all the tips are welcome. I just discover Oracle ;-)Name1 Actif=0 +32... , +3200000000 Name1 Actif=1 +32... , +........... Name2 Actif=0 +32... , +3200000000 Name2 Actif=1 +32... , +...........
Thank youHello
user13117585 wrote:
... But what I would like is to have numbers grouped by the flag of the ASSET.This is the solution! You want to have results grouped by asset, so add assets to the GROUP BY clause:
SELECT NOM , ACTIF -- New , LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM , ACTIF -- New ORDER BY 3 NULLS LAST -- Changed ;
If you want to display ACTIVE, you will need to add it to the SELECT clause.
Don't forget to change the ORDER BY clause, which changes what is in the column #2, as stated above (assuming that it is how you want the output sorted). However, a better way is to give this column alias, which can be used in the ORDER BY clause:SELECT NOM , ACTIF , LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) AS NUMEROS -- Alias defined FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM , ACTIF ORDER BY NUMEROS NULLS LAST -- Alias used ;
-
more than 4000 characters of parameter
Layer of java calls a stored proc EXEC_DDL that makes an EXECUTE IMMEDIATE on the VARCHAR2 parameter string passed. Since the java layer goes to more than 4000 characters DDL statement, we get an error cannot bind for a long time... What kind of data can I use as a parameter instead of VARCHAR2 inside the stored EXEC_DDL Steven Feuerstein proc advises against the use for a long TIME in his book of PL/SQL. All types of BUSINESS are inside or outside the database objects, but I want just the java code to pass a DDL string greater than 4000 characters. I want to use the simplest approach.
Thank you in anticipationWhat version of Oracle are you using? One thing - you can pass a variable of liaison which is more than 4,000 characters - so your options are rather spend a clob. Now if you're on 11g you can pass a clob in an immediate statement execute otherwise you will need to store the clob as varchar2 variable in the procedure, and then pass that variable in the statement execute immediate. In pl/sql, you can store up to 32K into a varchar2 variable.
-
without using the listagg function
Hi Sir,
Today my Bishop asked me to write a sql query to display comma separated values using listagg, sys_connect_by_path, wm_concat?
I said, we can write with the cursor... without predefined oracle functions? is this correct? or a Counselor about it?
Please help me
Concerning
AR
SQL > create table SEPM (deptno number (2), ename varchar2 (2));
Table created
SQL > insert all
2 in samp (deptno, ename) values (10, 'A')
3 in the SEPM (deptno, ename) values (20, 'd')
4 in the samp (deptno, ename) values (20, 'E')
5 SELECT * FROM DUAL;3 lines inserted
SQL > SELECT * FROM SAMP;
DEPTNO ENAME
------ -----
10A
20 D
20 ENeed to display like this
10A
20 D, E
-
Need help with the listagg function
Hi all
I try to use Listagg in the query below, but not able to get the answer. It is throwing an error message saying ORA-00979: not a GROUP BY expression.
If I try to remove the Group By function and run the query, I get the following error ORA-00937: not a function of simple-group.
Help, please.
Select Distinct V.User_X, V.Original_Request_Id, (V.Support_Group_Name, ',') listagg Group (order of V.Support_group_name) as Group1,
T.Individualassignedto, T.Status, T.Groupassignedto, T.Ticketcategory, T.Tickettype, T.orgcompany, T.submitter,
T.Orgassignedto, T.Urgency
Display V
INNER JOIN K_TICKET T ON T.TICKETNUMBER = V.ORIGINAL_REQUEST_ID
V.Original_Request_ID group
Because you use a GROUP BY, you don't need SEPARATE.
All the columns you are not aggregate (list) should be in the GROUP BY.
Maybe you are looking for
-
Sort my songs a to z, since the 10 update it does by the artist?
Since the update when I go into my songs, it changed title of the song from a to z to the artist from a to z. I do not know if someone has it but o does not know how to change this back? and yes I returned to the page from the main menu thingy and se
-
Hello. Something strange started to happen on my laptop. whenever I turn it on, it starts and at the loading screen, an error screen appears and restart the laptop. I have Windows XP, and the error I get is the following: A problem has been detected
-
I want to know how can I find out if my email is accessed from another computer that may have gotten my user & password?
-
8500 A909g does not print black
Usually, I keep my scale, black project, gray ink printer settings only. About a month ago the black became an off color. It is still dark but not black. Can someone help me.
-
ALS ik een fotolijst wil maken bij een foto lukt dat niet meer the meld system dan's 21.When I want to create a photo frame I download the 21 error message.