highest value in columns separated by commas
I have a table with data as shown below
trx_numbers trx_dates trx_ref
01616145/01616332/01616459 | 2014-11-13/2014-11-19/2014-11-24 | 2014090001 |
01616145/01616332/01616459 | 2014-11-13/2014-11-19/2014-11-24 | 2014120768 |
I need a sql to extract higher and corresponding date for each trx_ref
in the example above: 2014090001 - 2014-11-24 - 01616459
First advice would be to build something like a decent datamodel...
To solve your problem with your 'model', you could do (ORACLE 11.2):
WITH the DATA (trx_numbers, trx_dates, trx_ref)
AS (SELECT ' 01616145/01616332/01616459','2014-11-13/2014-11-19/2014-11-24',2014090001 UNION double, ALL)
SELECT ' double 01616145/01616332/01616459','2014-11-13/2014-11-19/2014-11-24',2014120768)
separator AS (SELECT trx_ref
to_number (regexp_substr(trx_numbers,'[^/]+',1,LEVEL)) AS trx_number,
, to_date (regexp_substr(trx_dates,'[^/]+',1,LEVEL), 'YYYY-MM-DD') AS trx_date
FROM THE DATA
CONNECT BY LEVEL<= (regexp_count(trx_numbers,'/')="" +="">=>
AND trx_ref = PRIOR trx_ref
AND PRIOR sys_guid() IS NOT NULL)
SELECT trx_ref
MAX (trx_date) KEEP (DENSE_RANK FIRST ORDER BY trx_date DESC) as trx_date
MAX (trx_number) KEEP (DENSE_RANK FIRST ORDER BY trx_date DESC) as trx_number
BETWEEN the separator
Trx_ref group
/
HTH
Tags: Database
Similar Questions
-
the list of columns separated by commas of a dictionary table table
I use the following question.
CONNECT_BY_ROOT SELECT table_name TopLevel, level,
connect_by_isleaf IS_Node_leaf,
substr (SYS_CONNECT_BY_PATH (column_name, ','), 2) column_name
Of all_tab_cols
where connect_by_isleaf = 1
and column_id < (select max (column_id) + 1 all_tab_cols
where table_name = 'Table_test')
and column_id > (select min (column_id) - all_tab_cols 1
where table_name = 'Table_test')
START WITH table_name = "Table_test."
CONNECT BY PRIOR column_id = nocycle (column_id - 1).
AND table_name = "Table_test."
The only problem with this query is that it goes into infinite loop. Can someone suggest a better solution?Why you ask all_tab_cols, I think will realize you that it will pull all tables in your database.
If you want to retrieve the name of the table and the columns (separated by commas) your schema, you must query user_tab_cols.
and here is the sql code
select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names from (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn from user_tab_cols) where connect_by_isleaf = 1 start with rn=1 connect by prior rn=rn-1 and prior table_name = table_name /
Or, you can use all_tab_cols to query a specific table by passing the name of the table and the name of the owner
PRAZY@11gR1> desc test Name ------------------------------------------- NUM NUM2 PRAZY@11gR1> select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names from (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn from all_tab_cols where owner='PRAZY' and table_name = 'TEST') where connect_by_isleaf = 1 start with rn=1 connect by prior rn=rn-1 and prior table_name = table_name / PRAZY@11gR1> / TABLE_NAME COLUMN_NAMES ------------------------------ ---------------------------------------- TEST NUM,NUM2 Elapsed: 00:00:00.01
HTH,
PrazyPublished by: Prazy on April 28, 2010 10:23
-
problem with column separated by commas
I'm running into a problem with the following table structure
CREATE TABLE «DETAILS»
(
'ID' NUMBER (22.0) NOT NULL,
VARCHAR2 (150 CHAR) 'NAME' NOT NULL,
"COVER" VARCHAR2 (150 CHAR) NOT NULL
);
Insert into EXPORT_TABLE (ID, NAME, COVER) values (252613546, 'VCONBU', ', 252612938,');
Insert into EXPORT_TABLE (ID, NAME, COVER) values (252613549, 'SPMABU', ', 252612932,');
INSERT INTO EXPORT_TABLE (ID, NAME, COVER) VALUES (252612938, 'HOSTEDTG', NULL);
Insert into EXPORT_TABLE (ID, NAME, COVER) values (252612932, 'INSTG', null);
Insert into EXPORT_TABLE (ID, NAME, COVER) values (367708813, 'ICF_1', ', 252613546,');
Insert into EXPORT_TABLE (ID, NAME, COVER) values (364413059, 'CSWSPT', ', 252613549,');
commit;
Output
ID NAME COVER 252613546 VCONBU HOSTEDTG 252613549 SPMABU INSTG 252612938 HOSTEDTG 252612932 INSTG 367708813 ICF_1 VCONBU 364413059 CSWSPT SPMABU Hello
You may want a self-join, like this:
SELECT c.id
c.name
p.name AS cover
Of export_table c
LEFT JOIN export_table p WE «,» | p.ID
|| ',' = c.lid
;
-
Oracle 10.2.0.1
Windows XP
I have a table that stores the data of our customers. When I said:
Select city, city_code as CS, count (*) as the early group of customers by city, city_code:
It returns:
Power required:CITY CS TOT ---------------------------------------- -- ---------- Delhi 01 23 Bangalore 02 36 Mumbai 03 33 Hyderabad 04 8 Jaipur 00 2 Patna 00 1 Chennai 05 114
Means that if Tot for a city is between 1,5; I want to get these IDS to customer (from the customer table itself)CITY CS TOT IDS ---------------------------------------- -- ---------- ---------------------- Jaipur 01 2 393,405 Patna 02 1 200
separated by commas as above, so that I can know who are the customers, because all the
cities whose number is < = 5, there are errors in the name of the city.
Thank you.NOT TESTED! not having do not have database access
select city,city_code,tot,substr(sys_connect_by_path(to_char(customer_id),','),2) ids from (select c.customer_id,c.city,c.city_code,e.tot, row_number() over (partition by c.city,c.city_code order by customer_id) the_row from customers c, (select city,city_code,count(*) tot from customers group by city,city_code having count(*) <= 5 ) e where e.city = c.city and e.city_code = c.city_code ) where connect_by_isleaf = 1 start with the_row = 1 connect by prior the_row + 1 = the_row and prior city = city and prior city_code = city_code and prior tot = tot
Concerning
Etbin
-
Display values in the columns separated by commas.
Hello world
Table 1
col1 col2 ID1 Name1 ID2 name2 ID3 Name3 Table 2
col1 col2 RQ1 1 RQ2 3, 2 rQ3 2, 3 Result table
col1 col2 RQ1 Name1 RQ2 Name2, Name3 rQ3 name2, Name3 Based on table 1 and table 2 to create a view to produce a result array.
Ideas experts!
Little things...
First of all, given in TABLE1. Col1 stores values as ID1, ID2... But the associated column in TABLE2. Col2 stores the value in the form 1, 2... Is this correct? Then, the data into TABLE2. Col2 is not the right way to store your data. TABLE2 is not standardized. And it is a very bad way to design a database.
Says you can try this solution here I Unpivot firstly the list of values in TABLE2. Col2 in lines and then enclose it with TABLE1 and finally make an aggregation of chain. It is a solution prior 11g. If you are on 11g and above, you can use functions like UNPIVOT and LISTAGG wisely.
with table1
as
(
Select "id1" col1, col2 "Name1" Union double all the
Select "id2" col1, col2 "Name2" Union double all the
Select 'id3' col1, col2 "Name3" of the double
),
Table2
as
(
Select "rq1" col1, col2 '1' of any Union double
Select "rq2" col1, col2 '3.2' of any union double
Select "rq3" col1, col2 '2.3 ' double '.
)
table2_expand
as
(
Select col1
, regexp_substr (col2, ' [^,] +', 1, level) col2
level lvl
from table2 t2
connect
by level<= length(col2)="" -="" length(replace(col2,="" ','))="" +="">=>
and col1 = col1 prior
and prior sys_guid() is not null
)
Select col1, ltrim (sys_connect_by_path (col2, ',') ',') col2
BeO
Select t2.col1, t1.col2, row_number() over NWR (partition by order of t2.col1 of t2.lvl)
FROM table1 t1
Join the t2 table2_expand
on t1.col1 = 'id ' | T2.col2
)
where connect_by_isleaf = 1
beginning
with rno = 1
connect
by rno = prior rno + 1
and col1 = col1 prior
-
Splitting data separated by commas
Hi friends,
I have a few million records that must be formatted as data and need your help with this.
Actual data in the csv file:
«30375516451 ',' June 3, 2013 23:31:33 ","June 4, 13"," Tag #: 2490544Sharjah - White 33708 ", 'Al Garhoud bridge nine', 'Abu Dhabi', '4.00»»'
Value using request, separated by commas:
Select
Replace (replace (replace (replace (test_value,'"', null"), chr (13), null), chr (160), null), chr (10), null) "test_value"
of the test
where to_number (length (test_value) - length (replace(test_value,',',''))) in (3.6);
Output:
30375516451, 03-Jun-2013 23:31:33, 4 June 13, Tag #: 2490565Sharjah - white 33708, new Al Garhoud bridge Abu Dhabi, 4.00
Need to change a part with highest result of the query to make it entirely comma separated:
Tag #: 2490565Sharjah - White 33708,.
Output:
2490565, Sharjah, 33708 white,-remove the space before the comma: white 33708,.
Power required:
30375516451, 03-Jun-2013 23:31:33, June 4, 13, 2490544, Sharjah, white 33708, Al Garhoud new bridge, Abu Dhabi, 4.00
Sample data:
CREATE TABLE TEST (TEST_VALUE VARCHAR2 (4000));
INSERT INTO TEST VALUES (' "30375516451","June 3, 2013 23:31:33", "June 4, 13","Tag #: 2490565Sharjah - White 33708", "Al Garhoud bridge nine", "Abu Dhabi", "4.00" ' ");
Thank you
with the trial as)
Select "" 30375516451 ',' June 3, 2013 23:31:33 ","June 4, 13"," Tag #: 2490544Sharjah - 33708 white ', 'Al Garhoud New Bridge', 'Abu Dhabi', '4.00' ' test_value»
of the double
)
Select regexp_replace)
regexp_replace)
test_value,
'( *")| [' || Chr (13) | Chr (160) | Chr (10) | ']',
NULL,
1,
0,
« n »
),
'Tag #:(\d+)(.+) - ([^,]+)',
'\1,\2,\3 '.
) test_value
of the test
/TEST_VALUE
--------------------------------------------------------------------------------------------------------------
30375516451, 03-Jun-2013 23:31:33, 04-Jun-13, 2490544, Sharjah, White 33708, new Al Garhoud bridge Abu Dhabi, 4.00SQL >
SY.
-
Hello
I use apex 5.
I used the shuttle to load the list of values of SQL query.now I want to get the list of the selected values on the right side of the shuttle to a textfield.values should be separated by commas.
Please someone tell me how to do this.
Thank you
Hi geslin,.
Garza says:
I use apex 5.
I used the shuttle to load the list of values of SQL query.now I want to get the list of the selected values on the right side of the shuttle to a textfield.values should be separated by commas.
Please someone tell me how to do this.
You can do it by using dynamic action.
Create a dynamic action on the onchange event of your Shuttle point (say P1_SHUTTLE) to get the values to select in the text element (say P1_TEXT) as follows:
Name: give a name
Event: change
Selection type: item (s)
Article (s): P1_SHUTTLE (select your Shuttle point)
Condition: is not null
Action: Execute the PL/SQL Code
Fire on loading the Page: No.
PL/SQL code
BEGIN :P1_TEXT := REPLACE(:P1_SHUTTLE,':',','); END;
Page items to submit: P1_SHUTTLE
Page referred to return: P1_TEXT
Kind regards
Kiran
-
Value separated by commas in a table column to get each field separtely?
Hello
I have the table that a column has values separated by commas in it. This table is populated using SQL LOADER, which is staging table.
I need to retrieve the records of these values separated by commas.
format of. CSV file is as -
A separate file of pipes.
DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2|
DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5|
DHCP-1-1-3. WNLB-CMTS-01-1.
DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3|
DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7|
CREATE TABLE link_data (dhcp_token VARCHAR2 (30), cmts_to_add VARCHAR2 (200), cmts_to_remove VARCHAR2 (200));
insert into link_data values ('dhcp-1-1-1','wnlb-cmts-01-1,wnlb-cmts-02-2',null);
insert into link_data values ('dhcp-1-1-2','wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5',null);
insert into link_data values ('dhcp-1-1-3','wnlb-cmts-01-1',null);
insert into link_data values ('dhcp-1-1-4','wnlb-cmts-05-8,wnlb-cmts-05-6,wnlb-cmts-05-0,wnlb-cmts-03-3',null);
insert into link_data values ('dhcp-1-1-5','wnlb-cmts-02-2,wnlb-cmts-04-4,wnlb-cmts-05-7',null);
Here the cmts_to_add column has comma separted
I need values such as -.
> for wnlb-cmts-01-1,wnlb-cmts-02-2 > > wnlb-CMTS-01-1
> > wnlb-CMTS-02-2
> for wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5 > > wnlb-CMTS-03-3
> > wnlb-CMTS-04-4
> > wnlb-CMTS-05-5
And so on...
I do this because it's the staging table and I load data into the main tables using this table.
This second field contain different values as the simple comma-delimited string.
I need to write a PLSQL block to insert into the main table after checking as if dhcp-1-1-1 and wnlb-CMTS-01-1 is present in the main table so not to introduce other insert a new record.
To meet this requirement, I need to get the distinct value of the cmts_to_add column to insert into DB.
the value will be inserted as dhcp-1-1-1_TO_wnlb-cmts-01-1 and dhcp-1-1-1_TO_wnlb-cmts-02-2 for the first row of the array of link_data.
The process will also be same for the rest of the lines.
I use the function substrt and instr for this problem, but its does not work.
declare
cursor c_link is select * from link_data.
l_rec_link link_data % rowtype;
l_dhcp varchar2 (30);
l_cmts varchar2 (20000);
l_cmts_1 varchar2 (32000);
Start
Open c_link;
loop
extract the c_link in l_rec_link;
l_cmts: = l_rec_link.cmts_to_add;
loop
l_cmts_1: = substr (l_cmts, 1, instr(l_cmts,',')-1);
dbms_output.put_line (l_cmts_1);
end loop;
dbms_output.put_line(l_dhcp||) e '|| l_cmts);
When the output c_link % notfound;
end loop;
exception
while others then
Dbms_output.put_line ('ERROR' |) SQLERRM);
end;
Its a peusdo code I write, but it also gives me the wrong answer it gives me error ORA-20000: ORU-10027: buffer overflow, limit of 20000 bytes
I am using-
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Please tell me if my problem isn't clear!
Hello
little 'trick': Add a comma at the end of the chain... So it's easier to deal with the fact that there are zero, one, or N components...
CREATE TABLE link_data (dhcp_token VARCHAR2 (30), cmts_to_add VARCHAR2 (200), cmts_to_remove VARCHAR2 (200));
insert into link_data values ('dhcp-1-1-1','wnlb-cmts-01-1,wnlb-cmts-02-2',null);
insert into link_data values ('dhcp-1-1-2','wnlb-cmts-03-3,wnlb-cmts-04-4,wnlb-cmts-05-5',null);
insert into link_data values ('dhcp-1-1-3','wnlb-cmts-01-1',null);
insert into link_data values ('dhcp-1-1-4','wnlb-cmts-05-8,wnlb-cmts-05-6,wnlb-cmts-05-0,wnlb-cmts-03-3',null);
insert into link_data values ('dhcp-1-1-5','wnlb-cmts-02-2,wnlb-cmts-04-4,wnlb-cmts-05-7',null);
COMMIT;SET SERVEROUT ON
DECLARE
l_cmts VARCHAR2 (200 CHAR);
l_cmts_1 VARCHAR2 (200 CHAR);
BEGIN
FOR r IN (SELECT dhcp_token, cmts_to_add |) ',' cmts
OF link_data
)
LOOP
l_cmts: = r.cmts;
l_cmts_1: = SUBSTR (l_cmts, 1, INSTR (l_cmts, ",") - 1);
While l_cmts_1 IS NOT NULL
LOOP
DBMS_OUTPUT. Put_line (r.dhcp_token |) '|' || l_cmts_1);
l_cmts: = SUBSTR (l_cmts, INSTR (l_cmts, ",") + 1);
l_cmts_1: = SUBSTR (l_cmts, 1, INSTR (l_cmts, ",") - 1);
END LOOP;
END LOOP;
END;
/
DHCP-1-1-1. WNLB-CMTS-01-1
DHCP-1-1-1. WNLB-CMTS-02-2
DHCP-1-1-2. WNLB-CMTS-03-3
DHCP-1-1-2. WNLB-CMTS-04-4
DHCP-1-1-2. WNLB-CMTS-05-5
DHCP-1-1-3. WNLB-CMTS-01-1
DHCP-1-1-4. WNLB-CMTS-05-8
DHCP-1-1-4. WNLB-CMTS-05-6
DHCP-1-1-4. WNLB-CMTS-05-0
DHCP-1-1-4. WNLB-CMTS-03-3
DHCP-1-1-5 | WNLB-CMTS-02-2
DHCP-1-1-5 | WNLB-CMTS-04-4
DHCP-1-1-5 | WNLB-CMTS-05-7Best regards
Bruno Vroman.
-
Hello
I have 3 tables with the following structure.
create table a_os_lang_stls
(ID NUMBER )
SWB_NUMBER VARCHAR2 (30),
Pc_NUMBER VARCHAR2 (30),
PC_FLAG TANK (1),
INSTALLATION_ord NUMBER ,
SP_OR_LATER_VSN TANK (1),
Platform VARCHAR2 (4000),
OS VARCHAR2 (4000),
LANG VARCHAR2 (4000),
LOSS_OF_FUNC_REASON_TXT VARCHAR2 (4000),
CREATION_DATE DATE ,
MODIFIED_DATE DATE ,
CREATED_BY VARCHAR2 (100 BYTE),
MODIFIED_BY VARCHAR2 (100 BYTE)
);
Insert in a_os_lang_stls
values (1 'SWB1' 'SWB0','P',1 of ','11118,14,16,234,124' '12,26,17,24,35''34,28,45,67,123,95',USER, NULL, NULL, NULL, SYSDATE);
Insert in a_os_lang_stls
values (2,'SWB1' 'SWB2','P',2 of ','111,20,14,16,124''11,26,18,24,35''35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);
insert into a_os_lang_stls
values (3,'SWB1','SWB3','C', 1,'','11118,14,16,234,124','12,26,17,24,35',' 35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);
insert into a_os_lang_stls
values (4,'SWB1','SWB4','C', 2,'','111,20,14,16,124','11,26,18,24,35'' 34,28,45,67,123,95, SYSDATE, NULL, NULL, NULL, USER)
CREATE TABLE os_dtls
(
OSCODE VARCHAR2 (10 BYTE),
ID NUMBER DEFAULT NULL,
AG_OSCODE VARCHAR2 (250 BYTE),
);
insert into os_dtls
values ('HUX', 12, 'HP UNIX');
insert into os_dtls
values('SUX',26,'SOLARIS');
insert into os_dtls
values ('LUX', 17, 'LINUX');
CREATE TABLE lang_dtls
(
LANGCD TANK (2 BYTE),
LANGNAME VARCHAR2 (255 BYTE),
ID NUMBER DEFAULT 1 NOT NULL
);
insert into lang_dtls
values ('ENG', 'ENGLISH UK', 35);
insert into lang_dtls
values ('UEG', 'USA ENGLISH', 27);
insert into lang_dtls
values('FR','FRENCH',45);
Information on the database:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
PL/SQL version 11.1.0.7.0 - Production
Production base 11.1.0.7.0
AMT for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
I have to write a procedure like this
procedure os_lang_info (P_SB_NO IN varchar2, p_pcur sys_refcursor, p_ccur, sys_refcursor );
The requirement is to get the details for a given swb_no where pc_flag is P or C pass like 2 different sys_refcursor. But the value of column of bones and lang I need to map to the os_dtls and lang_dtls tables to get the ag_oscode and langname respectively for the corresponding id then through sys_refcursor.
So sys_refcursor structure will be
Open the p_pcur for
Select * from a_os_lang_stls
where swb_number = p_sb_no
and PC_FLAG = 'P' ;
so the output will resemble the following
1 , « SWB1 » , « SWB0 » , 'P' , 1 , 'S' , '11118,14,16,234,124' , «HP UNIX,SOLARIS,LINUX,... « , "UK ENGLISH,US ENGLISH,FRENCH,...» ', NULL, NULL, NULL, USER, SYSDATE
I must get the id separated by commas of column bone and lang and map to the corresponding table to get the names separated by commas of the bones and langs and pass it as a component of sys_refcursor.
Open the p_ccur for
Select * from a_os_lang_stls
where swb_number = p_sb_no
and PC_FLAG = 'C';
Could someone please help me how to convert the value separated by commas in a comma separated value new map to another table and pass it as part of the sys_refcursor.
Thanks in advance.
Kind regards
SB2011
Hello. Here are the queries for the two sys_refcursors.
(1) FOR THE FLAG = 'P '.
SELECT T1.ID,
T1. SWB_NUMBER,
T1. PC_NUMBER,
T1. PC_FLAG,
T1. INSTALLATION_ORD,
T1. SP_OR_LATER_VSN,
T1. PLATFORM,
T1. OS_CODE,
T2. LANG_CODE
DE)
SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() os_id
Of a_os_lang_stls t, xmltable (os) t1) T1.
OS_dtls T2
WHERE T2.ID = T1. OS_ID
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T1 PLATFORM),
(SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() lang_id
Of a_os_lang_stls t, xmltable (lang) t1) T1.
lang_dtls T2
WHERE T2.ID = T1.lang_id
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T2 PLATFORM)
WHERE T1.ID = T2.ID
AND T1. SWB_NUMBER = T2. SWB_NUMBER
AND T1. PC_NUMBER = T2. PC_NUMBER
AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD
AND T1. PLATFORM = T2. PLATFORM
AND T1. PC_FLAG = "P";
(2) PC_FLAG FOR = 'C '.
SELECT T1.ID,
T1. SWB_NUMBER,
T1. PC_NUMBER,
T1. PC_FLAG,
T1. INSTALLATION_ORD,
T1. SP_OR_LATER_VSN,
T1. PLATFORM,
T1. OS_CODE,
T2. LANG_CODE
DE)
SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() os_id
Of a_os_lang_stls t, xmltable (os) t1) T1.
OS_dtls T2
WHERE T2.ID = T1. OS_ID
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T1 PLATFORM),
(SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() lang_id
Of a_os_lang_stls t, xmltable (lang) t1) T1.
lang_dtls T2
WHERE T2.ID = T1.lang_id
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T2 PLATFORM)
WHERE T1.ID = T2.ID
AND T1. SWB_NUMBER = T2. SWB_NUMBER
AND T1. PC_NUMBER = T2. PC_NUMBER
AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD
AND T1. PLATFORM = T2. PLATFORM
AND T1. PC_FLAG = 'C ';
-
have a column that has values separated by commas... and I'm s
Have a column that has values separated by commas... and I'm trying to separate.
I am trying to create a stored procedure... The 11g xe version. apex .and version 4...
Here is the part of the code... I can't do a procedure. causes my intervention consist with the clause...
create or replace procedure ins_adv_invoice
(mmagazine_no number, madvtno number, missueno number, varchar2, varchar2, varchar2 msalesman_code mpagenumber msection)
is
cursor cx is with testa as
(select name of the advertiser pagenumber)
Select regexp_substr (pagenumber, ' [^,] +', 1, rownum) result
the advertiser
connect by level < = length (regexp_replace (pagenumber, ' [^,] + "")) + 1
where advt_no = madvtno;
Start
for xxx CX
loop
insert into adv_invoice (magazine_no, advtno, adissue, section, opinion, salesman_code)
values (mmagazine_no, madvtno, missueno, msection, xxx.result, msalesman_code);
end loop;
end;
But when I run the present... it creates no procedure. . I receive he following error...
LINE/COL ERROR
-------- ----------------------------------------------------
5/14 PL/SQL: statement ignored
9/69 PL/SQL: ORA-00933: SQL not correctly completed command
SQL >
Still not able to understand... If anyone can help...
Thank youChange the query to swap the last two lines:
... cursor cx is with testa as (select pagenumber name from advertiser) select regexp_substr(pagenumber, '[^,]+', 1, rownum) result from advertiser where advt_no = madvtno connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1; ...
-
Select the column of values such as 1 row of values (separated by commas)
Hi all
I've got a column of values:
2062
2063
2072
2073
etc...
How to choose these values as a single line (separated by commas)?
Here is my test scenario:
select '2062' as bacc from dual union all select '2063' as bacc from dual union all select '2072' as bacc from dual union all select '2073' as bacc from dual
http://rogertroller.blogspot.com/2009/10/5-ways-to-aggregate-columns-into-comma.html
There is an option is missing... the new oracle 11g listagg function
HTH
-
Separated by commas as columns
The text below table can values separated by commas and want to divide it into parts and display them as different columns.
For example
I'm able to do with the CASE statement, but I was wondering if it can be done in a different way.
CREATE TABLE T)
ID NUMBER 4,
TEXT VARCHAR2 (100)
);
INSERT INTO T VALUES (1, 'ALL, biased');
INSERT INTO T VALUES (2, 'ALL, Zero');
INSERT INTO T VALUES (3, 'STAT, NOSTAT');
INSERT INTO T values (4, 'ONEVALUE');
SELECT id, text,
CASE WHEN INSTR (text, ',') > 0 THEN
SUBSTR (text, 1, (INSTR(text,',')-1))
ON THE OTHER
TEXT
END part_1
CASE WHEN INSTR (text, ',') > 0 THEN
SUBSTR (text, INSTR (text, ",") + 1, LENGTH (text))
ON THE OTHER
NULL VALUE
END Part_2
T;
Hello
MyOAF wrote:
The text below table can values separated by commas, and you want to divide it into parts & post them as different columns.
For example
I'm able to do with the CASE statement, but I was wondering if it can be done in a different way.
CREATE TABLE T)
ID NUMBER 4,
TEXT VARCHAR2 (100)
);
INSERT INTO T VALUES (1, 'ALL, biased');
INSERT INTO T VALUES (2, 'ALL, Zero');
INSERT INTO T VALUES (3, 'STAT, NOSTAT');
INSERT INTO T values (4, 'ONEVALUE');
SELECT id, text,
CASE WHEN INSTR (text, ',') > 0 THEN
SUBSTR (text, 1, (INSTR(text,',')-1))
ON THE OTHER
TEXT
END part_1
CASE WHEN INSTR (text, ',') > 0 THEN
SUBSTR (text, INSTR (text, ",") + 1, LENGTH (text))
ON THE OTHER
NULL VALUE
END Part_2
T;
Here's one way:
WITH got_comma_pos AS
(
SELECT id, text
, INSTR (text |) ','
, ','
) AS comma_pos
T
)
SELECT id, text
, SUBSTR (text, 1, comma_pos - 1) AS part_1
SUBSTR (text, comma_pos + 1) AS part_2
OF got_comma_pos
ORDER BY id
;
You can also use regular expressions, but it will be slower.
-
How to store the values separated by commas
Hi all
I have a table named discount, with discount_id (number data type) as one of the columns.
The user gives an entry as the value separated by commas, (ex: '123,27890,3543')
I use built-in proc that separates the values separated by commas.
Result set is stored in a table.DECLARE l_input VARCHAR2 (4000) := '123,27890,3543'; l_count BINARY_INTEGER; l_array DBMS_UTILITY.lname_array; BEGIN DBMS_UTILITY.comma_to_table ( list => REGEXP_REPLACE (l_input, '(^|,)', '\1x'), tablen => l_count, tab => l_array); DBMS_OUTPUT.put_line (l_count); FOR i IN 1 .. l_count LOOP DBMS_OUTPUT.put_line ( 'Element ' || TO_CHAR (i) || ' of array contains: ' || SUBSTR (l_array (i), 2)); END LOOP; END; Result: 3 Element 1 of array contains: 123 Element 2 of array contains: 27890 Element 3 of array contains: 3543
I would like to do a select on the table of discounts
Select * discount where discount_id (123, 27890 3543).
I am looking for options,
I need to create a new physical table as
Create table new_table (identification number) and bulk insert in this table.
Select * discount where discount_id in (select distinct id of new_table).
or
Is there a better way?
THX
Rod.Hello, SamFisher.
May be the recursive subquery factoring help you?WITH test(f1, n) AS (select '12, 15, 235', 1 from dual UNION all select f1, n + 1 from test where n < regexp_count('12, 15, 235', ',') + 1) SELECT regexp_substr(f1, '[^, ]+', 1, n) f FROM test
-
How to search for a particular text values separated by commas
Hello
I have a table for example. TB_Fruits.
In that I have a FruitsName (Varchar) column
In this column I store the string of values separated by commas.
Select FruitsName in the tb_fruits;
Result: orange, banana, Apple
Now the question is suppose that if I try inserting one of these fruits once again name, then it must not allow me to insert.
Suppose that now if I try to insert ('grapes, banana')
or
(Apple, grape")
the orange, banana, Apple may be in any position.
How to check if one of these names exist already or not in the fruitsname column?
I can't use INstr function here as or. because the position is not fixed chain even not.
Appreciate any help.Hmm, OK, the BASIC_LEXER in the documentation is specified is useful to "spaces separate languages". So not really a good suggestion from my side ;-)
Okay, so a few different choices, you can play with:
SQL> create table tb_fruits ( 2 fruitsname varchar2(60) 3 ) 4 / Table created. SQL> begin 2 insert into tb_fruits values ('BANANA,APPLE'); 3 insert into tb_fruits values ('YELLOW BANANA,ORANGE'); 4 insert into tb_fruits values ('GREEN APPLE,YELLOW ORANGE'); 5 insert into tb_fruits values ('APPLE,GREEN BANANA'); 6 commit; 7 end; 8 / PL/SQL procedure successfully completed.
Option 1:
Make a outdated AS operator. It just won't be fast because it's more likely will be full table scan (or scan restricted index full).
SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'APPLE'||',%' 4 / FRUITSNAME ------------------------------------------------------------ BANANA,APPLE APPLE,GREEN BANANA SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'BANANA'||',%' 4 / FRUITSNAME ------------------------------------------------------------ BANANA,APPLE SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'YELLOW BANANA'||',%' 4 / FRUITSNAME ------------------------------------------------------------ YELLOW BANANA,ORANGE
Option 2:
Transform your data and replace the spaces with underscores. Which may or may not be a possibility for you. If your other data contains no underscores, you might fool your user interface using a view that replaces underscores with spaces when you select and a trigger before insert that replaces spaces with underscores to insert or update. Then, you can use the TEXT index.
SQL> create table tb_fruits2 as 2 select replace(fruitsname,' ','_') fruitsname 3 from tb_fruits 4 / Table created. SQL> begin 2 ctx_ddl.create_preference('mylex', 'BASIC_LEXER'); 3 ctx_ddl.set_attribute('mylex', 'printjoins', '_-'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> create index fruitsname_idx on tb_fruits2 (fruitsname) 2 indextype is ctxsys.ctxcat 3 parameters ( 4 'stoplist ctxsys.empty_stoplist 5 LEXER mylex' 6 ) 7 / Index created. SQL> select fruitsname 2 from tb_fruits2 3 where catsearch(fruitsname,replace('YELLOW BANANA',' ','_'),null) > 0 4 / FRUITSNAME ------------------------------------------------------------ YELLOW_BANANA,ORANGE
(I used CTXCAT rather then CONTEXT indexes to keep simple search syntax, avoid SYNCHRONIZATION problems and others. You can use CONTEXT or CTXCAT as desired.)
Option 3:
Transform your data in XML format instead of values separated by commas. Then create a XMLIndex.
SQL> create table tb_fruits3 as 2 select xmltype('
') fruitsname 3 from tb_fruits 4 / Table created. SQL> create index fruitsname_xmlidx on tb_fruits3 (fruitsname) 2 indextype is xdb.xmlindex 3 / Index created. SQL> select fruitsname 2 from tb_fruits3 3 where xmlexists('$f/l[w="YELLOW BANANA"]' passing fruitsname as "f") 4 / FRUITSNAME --------------------------------------------------------------------------------'||replace(fruitsname,',',' ')||' YELLOW BANANA ORANGE (I used just 'l' for 'list of the words' and 'w' for 'word').
Option 4:
Create your own [url http://docs.oracle.com/cd/E11882_01/text.112/e24436/cdatadic.htm#i1008347] USER_LEXER instead of a variant of BASIC_LEXER. This would require allows you to create your own stored procedures for the index to be used, in which case you have complete control over what you set in the form of a token.
That's the different options I can think of right now ;-)
-
How to get the values separated by commas of multiple records in table
How to get the values separated by commas of multiple records in table
for example
name address age sex
a 12 m e
b hh 12 f
BB c 13 h
I need to get output as a, b, c from a queryUse the query as below he works for me, change the names of tables and columns
SELECT SUBSTR (SYS_CONNECT_BY_PATH (PROXY_EMAIL, ','), 2) csv FROM (SELECT PROXY_EMAIL, ROW_NUMBER () ON the rn (ORDER OF PROXY_EMAIL), COUNT (*) NTC (STARS_PROXY_ASSIGNMENT) WHERE EMPLID = #EMPLID) WHERE rn = cnt START WITH rn = 1 CONNECT BY rn = rn + 1 ADVANCE
Maybe you are looking for
-
Firefox crashes at startup and then iPhone resprings the springboard
I had to reinstall firefox, because whenever I launched the app, it would break and then my iPhone would respring the springboard. I could not in it to turn on incident reports, but I turned on them now after reinstallation.
-
We cannot talk on the phone with headphones?
I was listening to music and received a call, so I responded with my headphones on and the person on the other end could not hear me. I had to unplug the headphones so to speak. To ensure that this was the case I placed a call and plugged the headpho
-
When I go to the Microsoft Virtual Academy and click one of the links/videos they have, a loading page/bar appears and stays like that for a while. A few days ago, I was able to access the content without any complications. But as of today, I get the
-
Why my keyboard does this and windows search results opens upward?
When I stop I itype ith is ihappens. I Island ispacebar ispaces i and iadds i 'i', i and island iletter Island I iletter I have 'I' ispaces. I have there ish ift I ideas inot iwork iand Island iw windows iexplorer iw Iman ikeeps ipopp ing iup.
-
Acer One S1002 WLAN connection Bruno sich jede Minute. Was ist die Chinese?
Hallo, ich habe mein Windows Tablett PC in 2016 Juli so. In 2 Wochen war einfach und ich habe zur repair geschickt verschwendet WLAN. Jetzt unterbreche sich jede Minute die connection WLAN. d.h. jede Minute muss ich wieder um Internet only zu verbind