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
   regexp_substr(sessie."rollen", 'CN=A_role') "A_role"
   from ( 
select '
'   "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

Does anyone have an idea how to do this in SQL?

best regards Mike

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=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
    <s:Envelope xmlns:s="">
          <ActivityId CorrelationId="4fc67c0d-4416-4c1f-92c5-0d6624fb41fd" 
       <s:Body xmlns:xsi="" xmlns:xsd="">
          <FacilitySiteInteractionList xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">
                <EndDate xsi:nil="true"/>
                <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName>
                <EndDate xsi:nil="true"/>
                <ProgramFacilitySiteName>Hedwall Inc.</ProgramFacilitySiteName>
          <TotalRowCount xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">2</TotalRowCount>
    I need to retrieve the Id of the node FacilitySiteInteraction - in this case, the values are 78104 and 78105.

    I tried to use extractvalue just, but he hesitates with error ORA-19025.
    select 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
    If I use just extracted I see there the rub
    select extract(x,'//FacilitySiteInteractionList/FacilitySiteInteraction/Id',
    from my_tab;
    <Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78105</Id><Id xmlns="urn:WA.Ecy.ADS.FacilitySite.Services">78104</Id>
    The format of the XML document does not have to consider another records/lines.

    So, the next thing I tried was using the value of the iterator:
    select extractvalue(x,'//FacilitySiteInteractionList/FacilitySiteInteraction[2]/Id',
    from my_tab;
    The downside of what I see is that I must first enter the TotalRowCount value and then more wrap XML Document TotalRowCount times
    in order to get these values. So I was wondering if it is a more effective approach to enter these data?

    Thank you, Tony
    SQL>  with t as (
    select xmltype('
                Hedwall Inc.
                Hedwall Inc.
    ') xml from dual
    select x.* from t t, xmltable('declare namespace e="urn:WA.Ecy.ADS.FacilitySite.Services";
                                 //e:Id' passing t.xml.extract('//FacilitySiteInteraction','xmlns="urn:WA.Ecy.ADS.FacilitySite.Services"')
                                 columns Id int path '.') x
    2 rows selected.
  • 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.
     PROCEDURE ProcedureA (acct IN number, o_cur OUT T_CURSOR)
          Open o_cur for
           SELECT A, B, C, D, E, F FROM DEMO;
     END ProcedureA
     PROCEDURE ProcedureB (param1 IN number, param2 IN number)
     get_cursor                 T_CURSOR;
     ProcedureA(111, get_cursor);
    How to extract the values of proceedings in ProcedureB? And also I want to get only columns A and B in ProcedureB.

    How to extract the values of proceedings in ProcedureB?
    Try something like this

    TYPE rectype IS RECORD (colA  demo.a%TYPE, colB demo.b%TYPE    );
         rec1  rectype; 
      FETCH get_cursor   INTO rec1;
      EXIT WHEN get_cursor%NOTFOUND;
         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;

    <? XML version = "1.0"? >
    rowset <>
    < ROW >

    How to extract the values inside each tag?

    XML file has the following data...

    rowset <>
    < ROW >
    < > 9600 BAUD_RATE < / BAUD_RATE >
    < / ROW >
    < / LINES > ';

    I use the Oracle 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?

                 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)
    Thanks in advance!


    Try 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.

  • How to choose the value of a string are numeric together and words of letters (for example, TEST)

    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 [email protected]$
    YOUR T 123456

    I want the results of the query as below.
    TEST 123456
    TEST 34567

    And 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


    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:27

    cursor curGetxx (inpl_chr_tsb_item in SGM_INV_ITEM_ATTRIBUTES.attribute12%type)
    MSI. Segment1
    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);

    Open curGetxx (l_chr_tsb_item);
    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);

  • 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.

  • How to pass multiple values of payload through the contextual event - jdev


    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...


  • XMLTABLE - how to extract the value of the escape of a node as-is sequence


    How can I me XMLTABLE leave the string value of a node like the version with escape sequence, rather than unescaping it?

    select extract(xmltype('<root><test>&lt;unset&gt;</test></root>'), '/root/test/text()').getstringval() col1 from dual
    union all
    select col1
    from   xmltable('/root' passing xmltype('<root><test>&lt;unset&gt;</test></root>')
                    col1 varchar2(20) path 'test');
    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.

    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:11

    You 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> select cast(col1 as varchar2(20))
      2  from xmltable(
      3         '/root'
      4         passing xmltype('<unset>')
      5           columns col1 xmltype path 'test/text()'
      6       ) ;
  • 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!

    you need to write it as:

    Select col1, col2, col3 from table1 where col1 in (: param1)

    It works for me.


  • ID - value in XML format. How to extract the value based on the id?


    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?


    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(
     ) xml_clob
     FROM dual
    SELECT extractvalue(x.xml_clob, 'root/resource[id="123"]/value')
    FROM x
    WHERE ...
  • How to extract the values of previous header?


    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,


    It's pretty generic:

    in my query, replace the Tag with your real Table (I don't have the table!):

    SELECT Interface_Id,
              'Header = '
           || (SELECT VALUE
               FROM    q1
               WHERE  q1.num = (SELECT MAX(num)
                                FROM    q2
                                WHERE  q2.num < q.num
                                AND    row_type = 'Header')) header
    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),

    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!


    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
    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


    .    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%'


  • 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 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

  • The connections to use

    Hello I recently bought a Mac Pro (end 2013) to a friend.  I am now running Windows via Bootcamp 10 and buy two of these Dell Ultrasharps U2515H products/ehouse1/0000000

  • my device does not appear in "computer".

    I recently did a factory restore on my dell 1525 inspiron and when I pluged my usb device, it loaded the necessary drivers and then it said my device is ready for use. However, when itry to find my device in the 'computer' it isn't here! I know that

  • Windows 7 does not connect to the internet after the clean install

    I did a clean install on my Windows 7 computer, but means doing so my computer not connect to internet more that connection drivers were lost. I'm going back between Web sites up-to-date, but without success. I someone could direct me to the link wit

  • SG200 - 26 - DHCP

    Hi all I just want to confirm something. The switch above perhaps a DHCP server? IM limited to virtual resources and cannot create an another VM (for now) to be a DHCP server, it is in our test lab, so I can't add a dhcp server to one of the current

  • changed the look on page of the plugin to the old look im using the new update 50.0

    changed the look on the plugin page back to the old page. IM using the new updated 50.0 thanks anthony reed Prov. ri