Problem using the list separated by commas with nested table element

Hello

I have a list separated by commas like this:
H23004,H24005,T7231,T8231,T9231
And want to create a function that creates a where clause clause for each element with an output like this:
UPPER('H23004') IN (UPPER(charge))
OR UPPER('H23005') IN (UPPER(charge))
OR UPPER('T7231') IN (UPPER(charge))
OR UPPER('T8231') IN (UPPER(charge))
OR UPPER('T9231') IN (UPPER(charge))
Here's my test function that is not working properly:
create or replace function FNC_LIST_TO_WHERE_CLAUSE(v_list in VARCHAR2) return varchar2 is
 -- declaration of list type
 TYPE batch_type IS TABLE OF pr_stamm.charge%TYPE;
 -- variable for Batches
 v_batch batch_type := batch_type('''' || replace(v_list,',',''',''') || '''');
 return_script varchar2(1000);

 BEGIN
 -- loop as long as there are objects left
 FOR i IN v_batch.FIRST .. v_batch.LAST
 LOOP
   --DBMS_OUTPUT.PUT_LINE(offices(i));
   -- create where clause
   IF i = 1 THEN
     return_script := 'UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
   ELSE
     return_script := return_script || ' OR UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
   END IF;
 END LOOP;

 return (return_script);
 end;
The out put looks like this:
UPPER('H23004','H24005','T7231','T8231','T9231') IN (UPPER(charge))
I don't know what I did wrong? It calculates the amount of the incorrect array element! (v_batch. Must be 5)
v_batch. FIRST = 1
v_batch. LAST = 1

Kind regards

Tobias

Try this...

declare
text varchar2 (1000): = "H23004, H24005, T7231, T8231, T9231;
v_where varchar2 (1000);
Start
Text: = text | «, » ;
While instr (text, ',') <> 0
loop
v_where: = v_where | ' UPPER ("': substr (Text, 1, InStr(Text,',',1)-1) |") ' IN (UPPER (load)) OR ';
text: = substr (text, instr(text,',',1) + 1);
end loop;
v_where: = substr (v_where, 1, length (v_where)-3);
dbms_output.put_line (v_where);
end;

convert it to function...

Tags: Database

Similar Questions

  • REGEXP_SUBSTR for the list delimited by commas with null values

    Hello

    I have a column that stores a list of values comma-delimited. Some of these values in the list may be null. I'm having some trouble trying to extract the values using the REGEXP_SUBSTR function when null values are present. Here are two things I've tried:
    SELECT
       REGEXP_SUBSTR (val, '[^,]*', 1, 1) pos1
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 2) pos2
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 3) pos3
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 4) pos4
      ,REGEXP_SUBSTR (val, '[^,]*', 1, 5) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    
    POS P POS P P
    --- - --- - -
    AAA   BBB
    SELECT
       REGEXP_SUBSTR (val, '[^,]+', 1, 1) pos1
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 2) pos2
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 3) pos3
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 4) pos4
      ,REGEXP_SUBSTR (val, '[^,]+', 1, 5) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    
    POS POS POS POS P
    --- --- --- --- -
    AAA BBB DDD FFF
    As you can see that neither calls work correctly. Anyone know how to change the regular expression pattern to handle null values? I tried various other models but could not get anyone to work in all cases.

    Thank you

    Martin
    -----
    http://www.ClariFit.com
    http://www.TalkApex.com

    Hi, Martin,.

    That's what you want:

    SELECT
       RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 1), ',') pos1
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 2), ',') pos2
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 3), ',') pos3
      ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 4), ',') pos4
      ,RTRIM (REGEXP_SUBSTR (val || ','
                          , '[^,]*,', 1, 5), ',') pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    

    The query above works in Oracle 10 or 11, but in Oracle 11, you can also do it with only REGEXP_SUBSTR, without using RTRIM:

    SELECT
       REGEXP_SUBSTR (val, '([^,]*),|$', 1, 1, NULL, 1) pos1
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 2, NULL, 1) pos2
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 3, NULL, 1) pos3
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 4, NULL, 1) pos4
      ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 5, NULL, 1) pos5
    FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
    

    The problem with your first request was that he was looking for sub channels of 0 or more non-virgules. There was as a substring. consisting of 3 characters starting at position 1, he returned "AAA", as expected. Then there was an another substring, the 0 characters, starting at position 4, so it returned NULL. Then, there was a substring of 3 characters starting at position 5, so he returned 'BBB '.

    The problem with your 2nd request was that he was looking for 1 or more non-virgules. 'DDD' is the 3rd this substring.

    Published by: Frank Kulash, on February 16, 2012 11:36
    Added Oracle 11 example

  • list separated by commas - extraction of each element in an array?

    Is there a quick way to make a field that contains a list of items separated by commas and put them in a table or perhaps separate variables?

    for example.

    a single line in the database contains the field [matches_with] and would generally contain the following elements:

    rings, bracelets, necklaces

    I need to be put in a variable

    < cfset item1 = 'rings' >

    < cfset item2 = 'bracelets' >

    < cfset item3 = necklaces >

    or if its more simple, put them in a table

    agenda [1] = 'rings '.

    point [2] = "bracelets".

    point [3] = "necklaces."

    There is a built-in ListToArray function to CF.

  • Find the occurrence of the word in a list separated by commas

    Hello

    I need to find the first occurrence of a word in a list separated by commas.

    Example list:
    monster,daemon,shark,bambi,sky
    Now I'm looking for the word: bambi
    Result should be the first calculation of the event: 4

    Now I'm looking for the word: Monster
    Result should be the first calculation of the event: 1

    Hope you can help.

    Tobias

    Hi, Tobias,.

    This can be more efficient, because it does not use CONNECT BY or regular expressions. Instead of splitting the string to the level of every comma, just find the target string and count how many commas occur in front of her.

    WITH     got_found_pos          AS
    (
         SELECT     list_txt
         ,     INSTR ( ',' || list_txt || ','
                    , ',bambi,'
                    )          AS found_pos
         FROM    table_x
    )
    SELECT     list_txt
    ,     found_pos + 1
                - LENGTH ( REPLACE ( SUBSTR (list_txt, 1, found_pos)
                                      , ','
                             )
                      )          AS item_num
    ,     found_pos
    FROM    got_found_pos
    WHERE     found_pos     > 0
    ;
    

    Delimited lsits storage is usually a bad idea in a relational database. It is best to store each item in the list on a separate line.

  • 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.
    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
    Result set is stored in a table.
    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 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 query

    Use 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

  • Convert the string separated by commas in the rows

    Dear gurus,

    I want to convert the string separated by commas in the rows to insert in the collection.

    for example, the string 1234,2323,23232,2343,34234
    Higher up in the chain must be converted to ranks in order to insert into the table or the collection

    Thanks in advance
    Sanjeev

    String in rows separated to convert the comma.

    with t
    as
    (
    select '1234,2323,23232,2343,34234' as txt from dual
    )
    select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
      from t
     connect by level <= length(regexp_replace(txt,'[^,]*'))+1
    
  • I have a psc 1350 HP which cannot me use the scanner, due to incompatibility with Internet Explorer 8.

    I have a psc 1350 HP which cannot me use the scanner, due to incompatibility with Internet Explorer 8.  When I use their "fix", it turns out that my screen blue and green. Aid others?

    Your support for the product is unfortunately - the manufacturer of the product.

    Suppose you tried everything here:
    http://h20000.www2.HP.com/bizsupport/TechSupport/document.jsp?lang=en&cc=us&TaskID=110&prodSeriesId=306884&prodTypeId=18972&ObjectID=c00802504

  • I installed Vista in a Virtualbox VM and the product key does not work, how to fix this? I use the same product key supplied with the computer originally.

    I bought a Dell Precision T3400 of Dell Financial Services and it came with Vista Business installed.  I installed a new hard drive and installed Vista in a Virtualbox VM by using the recovery disk that came with the computer, and the product key does not work for activation.  I get a message that says I need to activate Windows, but he says that the product key is not valid.  How can I fix it?

    Thank you

    If you have reinstalled the OEM of Vista Business copy on the new hard drive, as Bill says you can't also use it in a virtual machine.

    You can only reuse your OEM of Vista professional copy if it is no longer used on the computer. Do you have what operating system installed on the new hard drive? It was an upgrade copy or complete the license?

    If you used a license to upgrade to another edition of Windows to replace your copy of company then Vista Business license is still in use (for upgrade) and you cannot reuse it in your virtual machine.

    However if you replaced Vista business with a copy of the full license of another edition then you are able to use the OEM copy in a virtual machine, but only on the same computer. You must use the product key from COA to the label on the computer. The product key is put in the copy OEM cannot find the SLIC table on the host motherboard. You must use the phone activation from within the virtual machine. Click on start in Vista Business and typing "slui 4. Do not meet the audio guests until it asks you if you want to speak to an agent. Explain that you have completely replaced the OEM copy with a copy of the full license of the new windows and now want to use the OEM copy in a virtual machine on the same computer. Agent will then give you the activation string. Remember that the virtual machine is not transferable to any other computer.

    This information is offered by Darin Smith (MSFT) and the team of Windows licenses, November 18, 2011.

  • problems using the snap have amd, playback of Jpeg files

    Original title: I'm having problems using the component feature snap-in.

    Sometimes a single document disappears. When this happens while the document program is managed by then will not work. The document seems to be flying around the office. The last time this happened I had a doc JPEG upward and now I can't see what is JPEG. I don't know why the document wants to fly around, and I don't know how to get my use of the JPEG back.

    Hey Graham,.

    To view all jpeg images in the Viewer Windows photo or any other photo software visualization, you must configure this software as a default value in the default programs.

    Check out the link that allows you to configure the program as default.

    http://Windows.Microsoft.com/en-in/Windows7/change-which-programs-Windows-uses-by-default

    You can try to run the Aero Troubleshooter and see if that makes a difference.

    http://Windows.Microsoft.com/en-in/Windows7/open-the-Aero-Troubleshooter

    If the problem persists, provide us newspapers observer of events, as well as the error message if you receive a message.

    http://Windows.Microsoft.com/en-in/Windows7/open-Event-Viewer

  • Query to find the Pages and the list of permissions associated with a particular role in PS

    I want a query to find the Pages and the list of permissions associated with specific roles in PS.

    For example, if we see the role of manager accounts payable, it conatins Pages and the list of permissions.

    But, to get everything in EXCEL sheet by Manuel priocess's BIG job. So, can someone give me the query.

    Please try under queries

    The roles assigned to the list of Perm:

    SELECT B.ROLENAME

    OF PSCLASSDEFN A, PSROLECLASS B

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1).

    List of Perm pages can access:

    SELECT B.MENUNAME, B.BARNAME, B.BARITEMNAME, B.PNLITEMNAME, C.PAGEACCESSDESCR, B.DISPLAYONLY

    OF PSCLASSDEFN A, PSAUTHITEM B, PSPGEACCESSDESC C

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1

    AND B.BARITEMNAME > ' '

    AND B.AUTHORIZEDACTIONS = C.AUTHORIZEDACTIONS)

  • I'm having a problem using the slideshow module in LR 6.3. The slideshow contains the background image as one of the images to display. Earlier, I had created a slideshow of practice and the background image was not displayed as an image in itself. How to

    I'm having a problem using the slideshow module in LR 6.3. The slideshow contains the background image as one of the images to display. Earlier, I have created a slideshow of practice and the background image was not displayed as an image in itself. How to make it behave?

    Another approach, perhaps a little more elegant (?). Create a collection that includes images for the slideshow. Include the background image in the collection. Drag the background image in the Panel to designate. Then, remove this image from the collection and create the slide show. I just tried and it works, too.

  • Can I use the library of creative cloud with Illustrator CS5

    Can I use the library of creative cloud with Illustrator CS5

    Hi Ilys Ravel,

    No, CC libraries function is available in version CC 20141 sur-quartiers.

    Sanjay...

  • Delete option does not appear in the list when I right click on any element

    Original title: Please help friends

    In my laptop remove option does not work...

    I m not to delete something which in my hard drive laptop because delete option does not appear in the list when I right click on any element...
    Also does not work with the button remove from my Matthew...
    It is the only work when I cut this point and stick to the desktop, now I can delete...
    I also try to install Windows again but the result is the same
    Please help friends if you can...
               
    Thanks in advance

    It is not working...

    I already tried...

    But now my problem has been solved...

  • ORA-00904 with nested tables

    Hello. I have a problem of creating tables with nested tables.
    After you have created a few types, I would create a table based on these, but I get

    SQL error: ORA-00904: invalid identifier
    + 00904. 00000 - '% s: invalid identifier ' +.

    over and over again. This is my SQL code:

    1 create or replace TYPE t_indirizzo () AS OBJECT
    via VARCHAR (45), 2
    3 NUMBER,
    4 cap INTEGER (5).
    5 Città varchar (30),
    6 provincia varchar (30),
    region 7 varchar (30)
    )

    8 create or replace TYPE t_telefono () AS OBJECT
    9 num_tel Number (15)
    )

    10 create or replace TYPE t_listaTelefono AS TABLE OF THE t_telefono

    11 create or replace TYPE t_cliente () AS OBJECT
    12 cod_cliente NUMBER (8).
    13 address t_indirizzo,
    14 email varchar (30),
    Telefono 15 t_listaTelefono
    (16) NOT FINAL

    17 CREATE TABLE client (t_cliente)
    18 cod_cliente NOT NULL,
    19 address NOT NULL,
    email 20 NOT NULL,
    21 PRIMARY KEY (cod_cliente)
    (22) TABLE IMBRIQUE 'telefono' STORE AS 'numTelCli_tab '.
    23 RETURN VALUE

    My version of Oracle is 10.2.0. Thank you in advance.

    Published by: user11231503 on 2.35 giu-8-2009

    so, just to be sure, run this:

    create or replace TYPE t_indirizzo AS OBJECT (
    via VARCHAR(45),
    numero NUMBER,
    cap INTEGER(5),
    citta VARCHAR(30),
    provincia VARCHAR(30),
    regione VARCHAR(30)
    );
    / 
    
    create or replace TYPE t_telefono AS OBJECT (
    num_tel NUMBER(15)
    );
    / 
    
    create or replace TYPE t_listaTelefono AS TABLE OF t_telefono
    / 
    
    create or replace TYPE t_cliente AS OBJECT (
    cod_cliente NUMBER(8),
    indirizzo t_indirizzo,
    email VARCHAR(30),
    telefono t_listaTelefono
    ) NOT FINAL;
    / 
    
    CREATE TABLE cliente OF t_cliente(
    cod_cliente NOT NULL,
    indirizzo NOT NULL,
    email NOT NULL,
    PRIMARY KEY (cod_cliente)
    ) nested table telefono store as numTelCli_tab
    return as value
    /
     
    

Maybe you are looking for