Another REGEXP question: how to extract multiple values from a string
Hi, how can I retrieve multiple values to a string with RegExp with Oracle SQL constructs?Have looked at the various examples, I cannot understand this.
the following Sql code
select
regexp_substr(sessie."rollen", 'CN=A_role') "A_role"
from (
select '
CN=A_role,OU=a_org_unit,OU=another_org_unit,DC=bz,DC=ad,DC=min,DC=local
CN=Another_role,OU=some_org_unit,DC=bz,DC=ad,DC=min,DC=local
CN=Users,OU=Dep,DC=bz,DC=ad,DC=min,DC=local
' "rollen" from dual
) sessie;
Returns CN = A_role.I want him back all of the CN = concatenated values with a semicolon and stripped of the CN = bit.
So: A_role; Another_role; Users .
Any help would be much appreciated. Here I use database 11g 11.2.0.2.0.
Does anyone have an idea how to do this in SQL?
best regards Mike
Hello
If using Oracle 11 g
with tst
as (select 'CN=A_role,OU=a_org_unit,OU=another_org_unit,DC=bz,DC=ad,DC=min,DC=local,'
||'CN=Another_role,OU=some_org_unit,DC=bz,DC=ad,DC=min,DC=local,'
||'CN=Users,OU=Dep,DC=bz,DC=ad,DC=min,DC=local' as rollen
from dual
)
select listagg(sub, ',') within group (order by rn) as res
from (select regexp_substr(rollen, '(CN=)([[:alnum:]_]+)',1,rownum,'i',2) sub, rownum rn
from tst
connect by level <=length(rollen)
)
where sub is not null
Tags: Database
Similar Questions
-
Difficult to extract multiple values from an XML document
I have the following XML Document
I need to retrieve the Id of the node FacilitySiteInteraction - in this case, the values are 78104 and 78105.<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <ActivityId CorrelationId="4fc67c0d-4416-4c1f-92c5-0d6624fb41fd" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">30ccb32d-d6f5-4442-a41a-1eb735112501</ActivityId> </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <FacilitySiteInteractionList xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"> <FacilitySiteInteraction> <Id>78105</Id> <StartDate>2009-07-31T00:00:00</StartDate> <StatusCode>65</StatusCode> <InteractionTypeCode>WQGSWI</InteractionTypeCode> <FacilitySiteId>14951</FacilitySiteId> <CurrentSystemProgramName>WATQUAL</CurrentSystemProgramName> <CurrentSystemName>WPLCS</CurrentSystemName> <FederalProgramId/> <EndDate xsi:nil="true"/> <InteractionId>78105</InteractionId> <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName> <ModifiedDate>2009-07-31T07:30:57.99</ModifiedDate> <ModifiedByName>taus461</ModifiedByName> <CreatedDate>2009-07-31T07:30:57.99</CreatedDate> <FS_FEATUREs/> </FacilitySiteInteraction> <FacilitySiteInteraction> <Id>78104</Id> <StartDate>2009-07-01T00:00:00</StartDate> <StatusCode>65</StatusCode> <InteractionTypeCode>WQMJIND</InteractionTypeCode> <FacilitySiteId>14951</FacilitySiteId> <CurrentSystemProgramName>WATQUAL</CurrentSystemProgramName> <CurrentSystemName>WPLCS</CurrentSystemName> <FederalProgramId/> <EndDate xsi:nil="true"/> <InteractionId>78104</InteractionId> <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName> <ModifiedDate>2009-07-31T07:24:02.76</ModifiedDate> <ModifiedByName>taus461</ModifiedByName> <CreatedDate>2009-07-31T07:24:02.76</CreatedDate> <FS_FEATUREs/> </FacilitySiteInteraction> </FacilitySiteInteractionList> <TotalRowCount xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">2</TotalRowCount> </s:Body> </s:Envelope>
I tried to use extractvalue just, but he hesitates with error ORA-19025.
If I use just extracted I see there the rubselect extractvalue(x,'//FacilitySiteInteractionList/FacilitySiteInteraction/Id','xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; ERROR at line 2: ORA-19025: EXTRACTVALUE returns value of only one node -- note: column my_tab.x is an xmltype data type
The format of the XML document does not have to consider another records/lines.select extract(x,'//FacilitySiteInteractionList/FacilitySiteInteraction/Id', 'xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; <Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78105</Id><Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78104</Id>
So, the next thing I tried was using the value of the iterator:
The downside of what I see is that I must first enter the TotalRowCount value and then more wrap XML Document TotalRowCount timesselect extractvalue(x,'//FacilitySiteInteractionList/FacilitySiteInteraction[2]/Id', 'xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"') from my_tab; 78104
in order to get these values. So I was wondering if it is a more effective approach to enter these data?
Thank you, TonySQL> with t as ( select xmltype('
30ccb32d-d6f5-4442-a41a-1eb735112501 78105 2009-07-31T00:00:00 65 WQGSWI 14951 WATQUAL WPLCS 78105 Hedwall Inc. 2009-07-31T07:30:57.99 taus461 2009-07-31T07:30:57.99 78104 2009-07-01T00:00:00 65 WQMJIND 14951 WATQUAL WPLCS 78104 Hedwall Inc. 2009-07-31T07:24:02.76 taus461 2009-07-31T07:24:02.76 2 -
Procedure to another procedure call, how to extract values
I have couple of procedure in a package and I try to call proceedings in procedureb.
How to extract the values of proceedings in ProcedureB? And also I want to get only columns A and B in ProcedureB.TYPE T_CURSOR IS REF CURSOR; PROCEDURE ProcedureA (acct IN number, o_cur OUT T_CURSOR) AS BEGIN Open o_cur for SELECT A, B, C, D, E, F FROM DEMO; END ProcedureA PROCEDURE ProcedureB (param1 IN number, param2 IN number) AS get_cursor T_CURSOR; BEGIN ProcedureA(111, get_cursor); END;
>
How to extract the values of proceedings in ProcedureB?
>
Try something like thisTYPE rectype IS RECORD (colA demo.a%TYPE, colB demo.b%TYPE ); rec1 rectype; LOOP FETCH get_cursor INTO rec1; EXIT WHEN get_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(rec1.colA); END LOOP; DBMS_OUTPUT.PUT_LINE('end test');
-
How to extract the values of XMLTYPE column,
SQL > create table temporary global xmtype_tab (xmlfile xmltype);
SQL > select * from all_directories;
SYS RESTOREDIR/home / / dbimptask /.
insert into xmtype_tab values (xmltype (dbms_xslprocessor.read2clob ('RESTOREDIR ','LAS_SETUP.xml ')));
1 line of creation.
SQL > select * from xmtype_tab;
XMLFILE
--------------------------------------------------------------------------------
<? XML version = "1.0"? >
rowset <>
< ROW >
< DATA_CAPTURE_ON > 1 < / DATA_CAPTURE_ON >
How to extract the values inside each tag?
XML file has the following data...
rowset <>
< ROW >
< DATA_CAPTURE_ON > 1 < / DATA_CAPTURE_ON >
< > 9600 BAUD_RATE < / BAUD_RATE >
< ACK_TIMEOUT > 1 < / ACK_TIMEOUT >
< TUBE_TRAVEL_LIMIT > 4 < / TUBE_TRAVEL_LIMIT >
< SEND_SID_TIMEOUT > 1 < / SEND_SID_TIMEOUT >
< INDEX_Q_TIMEOUT > 2 < / INDEX_Q_TIMEOUT >
< HW_HANDSHAKING > 1 < / HW_HANDSHAKING >
< / ROW >
< / LINES > ';
I use the Oracle 10.2.0.3 version...Why does this work?
You are missing the tag of the ROWSET:
select extractvalue (xmlfile, '/ROWSET/ROW/BAUD_RATE') baud_rate from xmltype_tab where existsnode (xmlfile, '/ROWSET/ROW/BAUD_RATE') = 1;
-
Return multiple values from a table
Hi there I'm working on a bit of sql that returns values when they exist in a table.
The code I have returns the correct value when there is an entry in the tbl_studentmodules table, as soon as there is more than one entry in this table it does display no line at all: (.)
Can someone tell how to return multiple values?
Thanks in advance!select modulename from tbl_modulefeedback where 1 = (select count(*) from tbl_studentmodules where upper(:APP_USER) = upper(student_id)) and 1 = (select count(*) from tbl_modulefeedback, tbl_studentmodules where tbl_modulefeedback.modulecode = tbl_studentmodules.modulecode)
AshleighTry this:
select modulename from tbl_modulefeedback where 1 <= (select count(*) from tbl_studentmodules where upper(:APP_USER) = upper(student_id)) and 1 <= (select count(*) from tbl_modulefeedback, tbl_studentmodules where tbl_modulefeedback.modulecode = tbl_studentmodules.modulecode)
When you ask questions, please enter CREATE TABLE and INSERT some commands to make it easier to help you.
-
Hi all
How to choose the value of a string are letters (for example, TEST) and all numeric...
for example
TEST 123456
TEST 34567
123456 ABCD
1234 TEST
TESTING 12345
TEST 1@234$
YOUR T 123456I want the results of the query as below.
TEST 123456
TEST 34567And I tried to use regexp_like in this case but without success. See the code below.
SELECT * FROM TABLE WHERE regexp_like (Description, ' [TEST] % & [[: digit:]] + $');How can I do this, please answer.
Thank you
WF
If you want to return only the rows that contain the string 'TEST', followed by zero or more space characters, followed by one or more digits?
How about this:
SELECT *.
FROM my_table
WHERE REGEXP_LIKE(description,'^TEST\s*\d+$')
-
How to select multiple values in a single field.
Hi all
I once select stmt as below
==================================
SELECT msi.segment1,
IN l_chr_omc_item
OF SGM_INV_ITEM_ATTRIBUTES SIIA, msi mtl_system_items
WHERE msi.inventory_item_id = siia.inventory_item_id
AND siia.attribute12 = l_chr_tsb_item;
======================================
I need to print some l_chr_omc_item, but if the above query retrieves multiple values of the l_chr_omc_item for a l_chr_tsb_item so I need to print all the values. How to get all these values in a single rank.
Thanks in advance.
Published by: Shivaji M on June 28, 2009 23:18
Published by: Shivaji M on June 28, 2009 23:27cursor curGetxx (inpl_chr_tsb_item in SGM_INV_ITEM_ATTRIBUTES.attribute12%type)
is
SELECT
MSI. Segment1
Of
SGM_INV_ITEM_ATTRIBUTES SIIA
msi mtl_system_items
WHERE msi.inventory_item_id = siia.inventory_item_id
AND siia.attribute12 = inpl_chr_tsb_item;l_chr_omc_item SGM_INV_ITEM_ATTRIBUTES.attribute12%type;
vStrl_chr_omc_item varchar (500);Start
Open curGetxx (l_chr_tsb_item);
loop
extract the curGetxx in l_chr_omc_item;
When the output curGetxx % NOTFOUND;
vStrl_chr_omc_item: = concat (l_chr_omc_item, ',')
dbms_output.put_line (l_chr_omc_item);
end loop;
vStrl_chr_omc_item: = substr (vStrl_chr_omc_item, 1, length (vStrl_chr_omc_item)-1);
end;
/ -
How to extract individual values of TCP packet?
Hi all!
IM facing a situation where I have to extract individual values to insert into a sql database.
IM sucessfully receiving the package and I need to insert values lie between {xxxxxxxxxxxxxxxx}, each value name (column name) is bounded between "xxxxxxxx" and also its value.
IM - sticking the received packet:
{'Address': '0xC800A8C0', 'Channel': 0, 'Description': 'DDNS', 'Event': "Update", "SerialID": "000b3d016ce3", "StartTime": "2011-12-01 20:04:51", 'Status': 'Start', 'Type': "Journal" ""}
How can I retrieve the column names and values of the string received?
for example: "Address": "0cC800A8C0" - the name of the column is address and the value is 0cC800A8C0, etc., etc. each field is separated by a "," and each row is enclosed between {}
I need to insert only 0cC800A8C0 in the address column (and other values), but without "" and without:... Please note that the channel: 0, a value of 0 is not "" because it is a numeric value, the rest are strings.
any help on this?
Thanks in advance!
You can go there.
-
Hello:
How to configure contextual events publish several values of payload?
On click of a button, I'm declaritively publish a contextual event, which works very well when a single value is passed to the event handler.
My event handler method has the signature of:
eventHandler (String)
But now I also have an oracle.jbo.domain.Number, so my new eventHandler looks like this:
eventHandler (Number, String)
How to pass two values during editing of the event and how to place the payload with multiple values for the new eventHandler?
All article or code would be greatly appreciated.
Thanks for the help.You define a bean holding your values and pass an instance of the bean as a payload...
Timo
-
XMLTABLE - how to extract the value of the escape of a node as-is sequence
Hello
How can I me XMLTABLE leave the string value of a node like the version with escape sequence, rather than unescaping it?
E.g.:
NB. you will need to hit rΘpondre α and then quote my post to see the actual text; For the life of me, I can't get the forum properly displays things. In short, the string returned by the EXTRACT is escaped, while the XMLTABLE chain is unescaped.select extract(xmltype('<root><test><unset></test></root>'), '/root/test/text()').getstringval() col1 from dual union all select col1 from xmltable('/root' passing xmltype('<root><test><unset></test></root>') columns col1 varchar2(20) path 'test'); COL1 --------------------- <unset> <unset>
ETA: I looked through the standards xml from the list of available functions, and nothing seems relevant. {noformat} * scratches head * {noformat}
Published by: Boneist on March 19, 2013 14:11You can emulate what do I EXTRACT / getStringVal () by projecting the node text() as XMLType and type-casting to VARCHAR2 in the SELECT clause:
SQL> set scan off SQL> SQL> select cast(col1 as varchar2(20)) 2 from xmltable( 3 '/root' 4 passing xmltype('
') 5 columns col1 xmltype path 'test/text()' 6 ) ; CAST(COL1ASVARCHAR2(20)) ------------------------ <unset><unset> -
How to pass multiple values to a data model parameter
I have a data model, where I put a setting like this.
Select col1, col2, col3 from table1 where col1 =: param1
This works very well for a single value that I pass the param1 parameter.
How can I get this to work when I want to send multiple values for param1. I already checked the box "Multiple values" and tried to change the sql for this code.
Select col1, col2, col3 from table1 where col1 in: param1
Looks like I'm missing something here.
Thanks in advance!
Krisyou need to write it as:
Select col1, col2, col3 from table1 where col1 in (: param1)
It works for me.
Klaus
-
ID - value in XML format. How to extract the value based on the id?
Hello
I have a XML type
< root >
< resource >
< id > 123 / < ID >
< value > CBA < / value >
< / resource >
< resource >
< id > 456 / < ID >
def < value > < / value >
< / resource >
< / root >
It is stored in a column of XMLTYPE as a CLOB.
Now, I want to get a particular value based on one id.
I tried to use the following syntax
([Select case when existsnode(x.XML_CLOB,'/Root/Resource[Id="123"]') = 1
then extractValue(x.XML_CLOB,'/Root/Resource/Value')
but "/ Root / / value of resource" can mean either of the 2 values. How to solve this?Hello
If the element 'id' is unique you just specify XPath to the 'value' on the basis of extractvalue (given that you are pregnant of a single node):
WITH x AS ( SELECT xmltype( '
123 abc 456 def -
How to extract the values of previous header?
Hello
loading a flat file, I have a table (simplified example) as follows
Interface line Id Type value line Num
1 1 4 header
1 line 1 2
1 2 3 line
1 5 4 header
1 line 19 5
1 line 3 6
1 7 7 header
1 line 66 8
1 33 9 header
1 line 2 10
Can anyone tell me with a single piece of SQL I'm looking for the record header for each line.
for example, in my example
Line 2, 3 = Header 4
Line 5, 6 = header 5
Line 8 = Header 7
Line 10 = Header 33
Thanks for your comments,
Robert.It's pretty generic:
in my query, replace the
Tag with your real Table (I don't have the table!): SELECT Interface_Id, Row_type, num, 'Header = ' || (SELECT VALUE FROM
q1 WHERE q1.num = (SELECT MAX(num) FROM q2 WHERE q2.num < q.num AND row_type = 'Header')) header FROM WHERE row_type = 'Line' -
Return multiple values from a function in a SELECT statement
I hope I've provided enough information here. If not, let me know what I'm missing.
I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).
Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.
For example, right now, I have:
Table 1:
sequence_number NUMBER (10),
name varchar (30),
...
Table2:
Table1_seq NUMBER (10),
action_seq NUMBER (10),
action_date DATE,
action_office VARCHAR (3),
action_value VARCHAR (60),
...
I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.
The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
RP.action_date (sequence_number) action_date,
RP.action_office (sequence_number) action_office,
RP.action_value (sequence_number) action_value
FROM table1
Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?
Any suggestions?
Thank you very much!Hello
What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:
WITH got_rnum AS ( SELECT action_seq, action_dt, action_office, action_type, action_value , ROW_NUMBER () OVER ( ORDER BY action_date , action_seq , action_serial ) AS rnum FROM table2 WHERE action_code = 'AB' AND action_office LIKE 'E' -- Is this right? ) SELECT action_seq, action_dt, action_office, action_type, action_value FROM got_rnum WHERE rnum = 1 ;
As written, this returns a single line (at most).
I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
In this case, add a PARTITION BY clause to the ROW_NUMBER function.
If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
As I don't have your tables, I'll show you the use of the tables in the scott schema.
This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.CREATE OR REPLACE VIEW senior_emp AS WITH got_rnum AS ( SELECT d.deptno , d.dname , e.empno , e.ename , e.hiredate , ROW_NUMBER () OVER ( PARTITION BY d.deptno ORDER BY e.hiredate , e.empno ) AS rnum FROM scott.dept d JOIN scott.emp e ON d.deptno = e.deptno ) SELECT deptno , dname , empno , ename , hiredate FROM got_rnum WHERE rnum = 1 ; SELECT * FROM senior_emp ;
Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE ---------- -------------- ---------- ---------- --------- 10 ACCOUNTING 7782 CLARK 09-JUN-81 20 RESEARCH 7369 SMITH 17-DEC-80 30 SALES 7499 ALLEN 20-FEB-81
Moreover, one of the conditions to the query you posted has been
action_office LIKE 'E'
which equals
action_office = 'E'
(AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
Did you mean say that or did you mean something like this:action_office LIKE 'E%'
Instead?
-
How to extract the signal from the waveform of my power level designated?
Hi all
How can I extract the signal of the waveform accroding to the power level? I read the Trigger & Gate .vi, but this vi retrieves the signal duration. I want to extract the signal depending on the power level.
As shown in the following figures, the signal I want to deal with is between 130000 to 140000, if I Zoom, I can see the useful signal is between 135400 to 138200. The question is how to extract the signal in the area?
I tried the sub_NoiseEst_And_Chop_Shell.vi in the example of Packet_based_link also, but this Subvi seems to be a bit slow. Can someone give me the best advice? Thanks in advance!
I'm working on something similar, but have not had time to fully develop.
My idea was to use an envelope detector (low pass filter) and then use a detection of energy VI on the envelope.
Here is where I left
Maybe you are looking for
-
WANT 750se: USB charging port
I have a HP 750-100se ENVY. The Office has 4 ports USB at the back and 4 top / front, a total of 4 ports USB 3.0 divided 50-50. USB 3.0, two albums identified by an SS has a Flash to identify it. It is my understanding that the "BOLD" lightning USB p
-
Re: principal components analysis in LabVIEW
I want to the PCA of the FFT data (signal of known amplitude and time). I'm using labview 2009.I tried using the built-in pca.vi; but the difference in size of data. I am a student PCA for the 1st time in my life.please help.i do my last year on this
-
Do I really need these things from Microsoft on my computer?
I am running so slow on my computer lately, I just want to rid of so many things. I have this huge list of things Microsoft - I have no idea of what they are, or wht they do! Can someone tell me what is safe to delete & what I should keep please? Tha
-
slog2info w expects more to show the output
I rebooted just my Dev Alpha (A, with 10.0.9.2320) and immediately after, like I always do, I connected via SSH and tried running "slog2info w. Normally it export any existing output (which there are none immediately after a reboot), then the blocks,
-
Cannot print Web pages using network printer.
I have a dell computer in 2012 and I am connected to a network printer. I am able to print from Word, Excel, pdf documents, but I am not able to print something directly from the web. Y at - there someone who can help and give ideas as to what is cau