Function group &; order by function
Hi all; »
When we use function group & sort function. Always I get the error message.
SQL > select sum(bytes/1024/1024), NAME of v$ datafile including the group by name.
where the group by name
* ERROR on line 2:
ORA-00936: lack of expression
SQL > select sum(bytes/1024/1024), NAME, FILE number of v$ datafile where order by case number;
where to order by case number
*
ERROR on line 2:
ORA-00936: lack of expression
SQL > select name, sum (bytes/1024/1024), the status of v$ datafile where ts #= '4' group of FILE #;
Select name, sum (bytes/1024/1024), status from v$ datafile
*
ERROR on line 1:
ORA-00979: not a GROUP BY expression
SQL > select name, sum (bytes/1024/1024), the status of v$ datafile where TS #= '4';
Select name, sum (bytes/1024/1024), status from v$ datafile
*
ERROR on line 1:
ORA-00937: not a single group group function
Thanks in advance...
Hello
GTS (DBA) wrote:
...
I need output only for ts #= '4' only... I mean
Select sum(bytes/1024/1024), NAME from v$ datafile {only for ts #= 4}
...
This looks like a job of a WHERE clause:
SELECT SUM (bytes / 1024 / 1024) AS megabytes
name
folder #.
V $ datafile
WHERE the ts # = 4-* NEW *.
GROUP BY name
folder #.
ORDER BY line #.
;
Tags: Database
Similar Questions
-
I made a group for a community that I am, and I'm wishing I can lock the subject and the group photo, so that they cannot constantly which change all the time and lose focus on what the cat is actually for the value of things. I looked up and I tried the commands he said, but nothing has worked yet. New versions of Skype no longer as an option? I would really like it if it was a thing once again.
Hello
Options for the Set - TOPIC_AND_PIC_LOCKED_FOR_USERS command only works in P2P-based groups. When you create a group, this is a group based on a cloud, in which this command does not work. To create a group of P2P based, you can use the /createmoderatedchat command.
More details are available on this page: https://support.skype.com/en/faq/FA10042/what-are-chat-commands-and-roles
Hope that helps.
-
Do not understand why this partition by does not include a function of group
It's the oradocs
SELECT name, salary, department_id,
PERCENTILE_CONT (0.5) INTRA GROUP (ORDER BY salary DESC)
COURSES (PARTITION BY department_id) "Percentile_Cont."
PERCENT_RANK()
COURSES (PARTITION BY department_id ORDER BY salary DESC) "Percent_Rank.
Employees
WHERE department_id IN (30, 60)
ORDER BY last_name, salary, department_id;
http://docs.Oracle.com/database/121/SQLRF/functions140.htm#i1000909
I recently moved from analytical functions - the PARTITION OF analytical functions I practised so far have prescribed a group by article.
I don't understand why it does not include a.
Any tips?
There is no need to include a GROUP BY in your query, simply because you use analytical functions.
The main point of the use of analytic functions is to allow you to perform the aggregation or other lines of reference data without having to group data in the normal sense. The 'score' window, is what defines the data group that you want to reference without actually the outcome of consolidation.
-
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
-
This table includes the id, the coutry, and the word soundex
ID Word word_soundex
1 Egypt E213
2 Ejypt E213
3 Yemen Y550
E524 England 4
5 Yemen Y550
I want to get results like this
Egypt 1.2
Yemen 2.5
England 4
I try to do
Select word, listagg (id, ',') in the group test by country group (order by id)
but e incorrect results.
Published by: Isabelle on August 7, 2012 22:48
-
Need a query sql for obtaining the planned op, please notify--General Employee table -- Version: oracle 11g Rel 2 create table employee (ID varchar2(100),first_name varcha2(200),last_name varchar2(200),start_date date,end_date date,city varchar2(100)) select listagg(First_name,',') within group (order by first_name) from employee group by city ; op: 1. XXX,YYy,ZZZ 2. AAA,SSS Excepted OP: 1. 1.XXX,2.YYY,3.ZZZ 2. 1.AAA,2.SSS
Thanks in advance
Carole Kumar
Edited by: 876377 may 1, 2012 22:04876377 wrote:
--General Employee table -- Version: oracle 11g Rel 2 select listagg(First_name,',') within group (order by first_name) from employee; op: 1. XXX,YYy,ZZZ 2. AAA,SSS Excepted OP: 1. 1.XXX,2.YYY,3.ZZZ 2. 1.AAA,2.SSS
Need a query sql for obtaining the planned op, please notify
Thanks in advance
Carole KumarTry to use
row_number over (partition by ID_COLUMN order by first_name) as RN
And then
listagg( rn || first_name)
Since you don't validate your description of table we do not know what are the columns, etc... I guessed that the ID column is named ID_COLUMN, adjust accordingly.
-
Rank as aggregate function - help
Hi all
I am trying to learn oracle RANK as an aggregate function.
After that I run under request.
with temp (No., name, dept, sal) as
(select 1, 'aaa', 20, 32254 double Union all
Select 2, 'eee', 20, 45615 double Union all
Select 3, 'fff', 10, double union all 34645
Select 4, 'bbb', 30, double union all 45734
Select 9, 'mmm', 30, 23225 double Union all
Select 8, "nnn", 20, double union all 43565
Select 5, 'bbb', 20, double union all 56116
Select 7, "ccc", 30, double union all 45166
Select 6, 'ccc', 20, double 75166)
Select
Rank (45166) WITHIN GROUP (order by sal) as rank_1,
Rank (10,45166) WITHIN GROUP (stopped by the Department, sal) as rank_2,
Rank (45166,2) GROUP WITHIN (order by sal, no.) as rank_3
temp;
I get the output voltage:
rank_1 > 5
rank_2 > 2
rank_3 > 5
Here, how is the value of rank_2 is 2 and rank_3 is 5, I expect that two column should be zero because it does not correspond with the records.
Please help me understand, how does the row aggregate function is the species.
Thanks for all help you. Please let me know for further details.
If possible, any study link to learn the rank of aggregate function.
Oracle version:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production."
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Its says not where is the match - but where it appears in the list - game or not.
It's your list sorted by dept, sal
SAL DEPT
---------- ----------
10 34645
32254 20
20 43565
20 45615
20 56116
20 75166
30 23225
45166 30
30 45734
10,45166 would appear in the slot 2
-
How to write a decryption function?
Hi! everyone ,
I see one encryption function in my database.
Select f_pwd_encrypt ('password') of double
-> 12412913141313139139130121
My question is
How to write a decryption function?
As:
Select f_pwd_decrypt ('12412913141313139139130121') of double
->password
CREATE OR REPLACE FUNCTION EPADM."F_PWD_ENCRYPT" ( vpwd in varchar2) return varchar2 is vother_p varchar2(9); vtr_pwd varchar2(2048); i number; j number; vsubstr varchar2(9); vtemp1 varchar2(08); vvalue number := 0; vdb_pwd varchar2(100); function str_2_bit(vstring in varchar2) return varchar2 is i number; vtemp number; v1 varchar(2048); function single_byte(vin in number) return varchar2 is i number; vresult varchar2(08); vtemp number := vin; begin for i in 1..8 loop vresult := to_char(mod(vtemp,2))||vresult; vtemp := trunc(vtemp/2); end loop; return(vresult); end; -- begin for i in 1..lengthb(vstring) loop select to_number(substrb(dump( vstring ,10,i,1),instr(dump( vstring ,10,i,1),' ',-1)+1)) into vtemp from dual; v1 := v1 || single_byte(vtemp); end loop; return(v1); end; begin vtr_pwd := str_2_bit(vpwd); vtr_pwd := substrb(vtr_pwd,4)||substrb(vtr_pwd,1,3); vvalue := 0; vdb_pwd := null; for i in 1..(lengthb(vtr_pwd)/4) loop vtemp1 := substrb(vtr_pwd,(i-1)*4+1,4); for j in 1..4 loop vvalue := vvalue + to_number(substrb(vtemp1,j,1)) * power(2,j-1); dbms_output.put_line(j||' '||vvalue); end loop; vdb_pwd := to_char(vvalue) ||vdb_pwd; vvalue := 0; end loop; return(vdb_pwd); END; /
OK, after reviewing the, I don't think you'll be able to write a function of decryption for him.
The first thing he does is take the ascii value of each character in the password and converts them into a binary string. The code it uses is far too complex and can be simplified, but which is not a problem here.
I've recreated the first step of SQL like this...
SQL > ed
A written file afiedt.buf
1 with chr_val like)
2. Select level l
3, dump('password',10,level,1) in the dmp
4, to_number (substrb (dump('password',10,level,1), instr (dump('password',10,level,1),' ', 1) + 1)) as chr_val
5, ascii (substr('password',level,1)) as chr_val - equivalent of extraction of useless dump
6 double
7. connect by level<=>=>
8 )
9, r (l, b, ch, chr_val, result, vtemp) as
10 (select l, 0 b, chr (chr_val), chr_val)
11, cast (null as varchar2 (8)) as a result
12, chr_val as vtemp
13 of chr_val
14 union of all the
15 select l, b + 1, b, ch, chr_val
16, to_char (mod(vtemp,2)) | result as a result
17, trunc(vtemp/2) as vtemp
18 r
where the 19 b + 1<=>=>
(20) depth search first by l, defined b seq
21, as)
22 select l, ch, chr_val, str_to_bit result
23 r
where the 24 b = 8
25 arrested by l, seq
26 )
27 select listagg (ch) within the Group (order) as password
28, listagg (chr_val, ',') within the Group (order) byte_vals
29, listagg (str_to_bit) within the Group (order) bit_vals
30 sec.
SQL > /.
PASSWORD BYTE_VALS BIT_VALS
--------------- ---------------------------------------- ----------------------------------------------------------------------------------------------------
password 0111000001100001011100110111001101110111011011110111001001100100 112,97,115,115,119,111,114,100
Then he takes this string binary ("bit_vals" in my example) and does the following:
1. take the first 3 bits of left and to transpose on the right end of the string.
2 chops the resultant bit string upward into sections of 4 bits (which is known as a 'nibble' inside)
3. for each bit in the nibble, he treats the bits in binary reverse to normal and gives them a value of 1,2,4 or 8 from left to right for each bit set to 1
4. for each nibble it adds the value of 1,2,4,8 bits to give a value from 0 to 15
To show that the use SQL...
SQL > byte (select ' 0111000001100001011100110111001101110111011011110111001001100100' as pieces of double)
2, swap3bit as (-take the binary string and put the first bits (high) 3 as a (low) bit of the right hand side)
3. Select bytes.bits
4, substr (bit 4) | substr (bits, 1, 3) as init_substr
5 bytes
6 )
7, split4 as (-chop the string of bits nibbles (half bytes - 4 bits))
8. Select level l
9, substr (init_substr, ((level-1) * 4) + 1, 4) as a nibble
swap3bit 10
11. connect by level<=>=>
12 )
13, bitpowers (select l
14, snack
15, to_number (substr(nibble,1,1)) * power (2, 1-1) as bitval1
16, to_number (substr(nibble,2,1)) * power (2, 2-1) as bitval2
17, to_number (substr(nibble,3,1)) * power (2, 3-1) as bitval3
18, to_number (substr(nibble,4,1)) * power (2, 4-1) as bitval4
19, to_number (substr(nibble,1,1)) * power (2, 1-1) +.
20 to_number (substr (nibble, 2, 1)) * power (2, 2-1) +.
21 to_number (substr (nibble, 3, 1)) * power (2, 3-1) +.
22 to_number (substr (nibble, 4, 1)) * power (2, 4-1) as total_val
23 of split4
24 )
25 select * from bitpowers
26.
L NIBB BITVAL1 BITVAL2 BITVAL3 BITVAL4 TOTAL_VAL
---------- ---- ---------- ---------- ---------- ---------- ----------
1 1000 1 0 0 0 1
2 0011 0 0 4 8 12
3 0000 0 0 0 0 0
4 1011 1 0 4 8 13
5 1001 1 0 0 8 9
6 1011 1 0 4 8 13
7 1001 1 0 0 8 9
8 1011 1 0 4 8 13
9 1011 1 0 4 8 13
10 1011 1 0 4 8 13
11 0111 0 2 4 8 14
12 1011 1 0 4 8 13
13 1001 1 0 0 8 9
14 0011 0 0 4 8 12
15 0010 0 0 4 0 4
16 0011 0 0 4 8 12
16 selected lines.
These final values are then re-combination as strings in reverse order so that you get then:
'12' |' 4'||' 12' |' 9'||' 13'... and so on.
In SQL...
SQL > byte (select ' 0111000001100001011100110111001101110111011011110111001001100100' as pieces of double)
2, swap3bit as (-take the binary string and put the first bits (high) 3 as a (low) bit of the right hand side)
3. Select bytes.bits
4, substr (bit 4) | substr (bits, 1, 3) as init_substr
5 bytes
6 )
7, split4 as (-chop the string of bits nibbles (half bytes - 4 bits))
8. Select level l
9, substr (init_substr, ((level-1) * 4) + 1, 4) as a nibble
swap3bit 10
11. connect by level<=>=>
12 )
13, bitpowers (select l
14, snack
15, to_number (substr(nibble,1,1)) * power (2, 1-1) as bitval1
16, to_number (substr(nibble,2,1)) * power (2, 2-1) as bitval2
17, to_number (substr(nibble,3,1)) * power (2, 3-1) as bitval3
18, to_number (substr(nibble,4,1)) * power (2, 4-1) as bitval4
19, to_number (substr(nibble,1,1)) * power (2, 1-1) +.
20 to_number (substr (nibble, 2, 1)) * power (2, 2-1) +.
21 to_number (substr (nibble, 3, 1)) * power (2, 3-1) +.
22 to_number (substr (nibble, 4, 1)) * power (2, 4-1) as total_val
23 of split4
24 )
25 select listagg (to_char (total_val)) the Group (order of the desc) as pwd
26 of bitpowers
27.
PWD
-------------------------------------------------------------------------------------------------------------------
12412913141313139139130121
Now, the problem of decryption is that these numbers are concatenated without padding for a fixed number of digits by value, so you don't know if it was
'12' |' 4'||' 12' |' 9'||' 13'... and so forth as we did it, or whether he was
'1'||' 2'||' 4'||' 12' |' 9'||' 1'||' 3'... and so on, or any other combination of values from 0 to 15
There is essentially no information to allow you to divide the string upwards in the correct components to allow the whole process be reversed.
So, you are out of luck... no chance of decrypting it.
-
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.
-
Listagg function excdding 4000 characters
Hi all
Thank youOracle 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?
Rod.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.
-
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
-
I have a few sql querries who call many functions. The reason for function calls is that there are many records of children that can be returned by the function and it's actually concatonting all together in 1 channel and back. Because I called a bunch of functions in the query, in my opinion, his achievement of my performance. Is it possible to eliminate the service and into sql or a better way to do this right?
IE select emp_name, emp_id, get_med_visit_outcomes1 (emp_id), get_med_visit_outcomes2 (emp_id), get_med_visit_outcomes3 (emp_id),.
WCP
FUNCTION get_med_visit_outcomes (l_pk_id in varchar2) return VARCHAR2 IS
l_outcomes varchar2 (32000);
l_cnt number: = 0;
CURSOR get_med_visit_outcomes IS
Select B.med_visit_outcome
of med_visit_outcome B, stu_med_visit_outcome A
where A.fk_stu_med_visit = l_pk_id
and B.pk_id = A.fk_med_visit_outcome
order by 1;
BEGIN
FOR x in get_med_visit_outcomes LOOP
l_cnt: = l_cnt + 1;
If l_cnt = 1 then null;
l_outcomes: = x.med_visit_outcome;
on the other
l_outcomes: = l_outcomes | ', ' || x.med_visit_outcome;
end if;
END LOOP;
RETURN (nvl(l_outcomes,'-'));
END;If you are on version 11.2, LISTAGG is good for these problems:
select emp_name, emp_id, nvl(( select listagg(B.med_visit_outcome,',') within group (order by B.med_visit_outcome) from med_visit_outcome B, stu_med_visit_outcome A where A.fk_stu_med_visit = emp.emp_id and B.pk_id = A.fk_med_visit_outcome ),'-') outcomes1 from emp
If you are on older than 11.2 versions, you can see here the various other techniques [url http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php].
-
Listagg function displays the keyword not found error message
is version of Oracle 11 g
can you please suggest me to find exactly the problemcreate or replace function fn_months_attended return number is v_array varchar2(1000); begin select LISTAGG(c.act_id,',') within group (order by c.act_id desc) INTO V_ARRAY from programmes a,campaigns b,activities c where a.pro_id=b.cam_pro_id and b.cam_id=c.act_act_id order by act_id DESC ; return v_array; end; Error i received Error(6,3): PL/SQL: SQL Statement ignored Error(6,39): PL/SQL: ORA-00923: FROM keyword not found where expected
Hello
In the LIST of 11 GR 1 tot material. function does not work. It works in only 11 GR 2.
Kind regards
Champion. -
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 ;
Maybe you are looking for
-
Noteboot it recharges on the cover
Hi, when I close the lid of my spectrum 14 3200-er this shutsdowns or restarts and does not switch mode of sleep as expected. The laptop is two months old. Power options are intact. The problem is two or three days ago. What should I do? Event log Wi
-
can't run/debug -! ApolloLaunchDelegate.fileDoesNotExist!
I installed Flash Builder 4 (test), the AIR SDK 2.5 and the tableOS SDK for air and that you have followed the steps to generate the AIRHelloWorld example provided by RIM. When I try to debug the project I get the following error: ! ApolloLaunchDele
-
the keyboard does not have to return the system to the standby mode
Windows 7 Home Premium 64-bit system. The fundamental problem is that, after working properly for more than a year and a half, this Win7 machine suddenly stopped enlightenment of the mode before using the keyboard a few months ago. It still immediate
-
Recorded movie has no video, audio only
I downloaded Movie Maker live 2012 in Windows 7. I tried to save movies in all formats, but it plays only no video and audio. He played well in the preview, however.