How to split string separated by commas and pass to the clause of the select statement

Referring to article How to divide string separated by commas, then pass to clause of a select statement, tquery that there the following plan:

Query1:

select * from emp where ename in (
    select regexp_substr('SMITH,ALLEN,WARD,JONES','[^,]+', 1, level) from dual
    connect by regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level) is not null );

Base1:

Plan hash value: 4242290184


--------------------------------------------------------------------------------------------
| Id  | Operation                       | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |          |     1 |   133 |     7  (29)| 00:00:01 |
|*  1 |  HASH JOIN                      |          |     1 |   133 |     7  (29)| 00:00:01 |
|   2 |   VIEW                          | VW_NSO_1 |     1 |    46 |     3  (34)| 00:00:01 |
|   3 |    HASH UNIQUE                  |          |     1 |       |     3  (34)| 00:00:01 |
|*  4 |     CONNECT BY WITHOUT FILTERING|          |       |       |            |          |
|   5 |      FAST DUAL                  |          |     1 |       |     2   (0)| 00:00:01 |
|   6 |   TABLE ACCESS FULL             | EMP      |    14 |  1218 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - access("ENAME"="$nso_col_1")
   4 - filter( REGEXP_SUBSTR ('SMITH,ALLEN,WARD,JONES','[^,]+',1,LEVEL) IS NOT NULL)

However, the following query generates the plan I want:

Query2:

select * from emp where ename in ('SMITH','ALLEN','WARD','JONES');

Plan2:

Plan hash value: 3956160932


--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     4 |   348 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| EMP  |     4 |   348 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter("ENAME"='ALLEN' OR "ENAME"='JONES' OR "ENAME"='SMITH' OR
              "ENAME"='WARD')

Can I change the query1 query for plan2?

As Juliet was mentioned in the first SQL that you generate from the ENAME list that you must pass in the IN clause when executing. But in the second SQL, it passed as a static value. So first SQL must do more work. So you see a different execution plan.

But this is a work around to get what you are looking for. But I can't say it's a foolproof method. But anyway here you go.

SQL > var ename_list varchar2 (100)
SQL > exec: ename_list: = 'SMITH, ALLEN, WARD, JONES ';

PL/SQL procedure successfully completed.

SQL > select *.
2 of PEM
where the 3 «,» | : ename_list | ',' like '%', | Ename | ',%';

EMPNO, ENAME, JOB HIREDATE DEPTNO ID COM SAL MGR
---------- ------ --------- ---------- --------- ---------- ---------- ---------- ----------
7369 SMITH COMMITTED 7902 2975 2 APRIL 81 0 20
7499 ALLEN 7698 1600 20 FEBRUARY SALESMAN 81 300 30
7521 WARD 7698 1250 22 FEBRUARY SALESMAN 81 500 30
7566 JONES MANAGER 7839 2975 2 APRIL 81 0 20

SQL > select * from table (dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------------------
SQL_ID, 848zhvbvgf7d6, number of children 0
-------------------------------------
Select * from emp where «,» | : ename_list | ',' like '%', | Ename
|| ',%'

Hash value of plan: 2872589290

--------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT |      |       |       |     2 (100) |          |
|*  1 |  TABLE ACCESS FULL | EMP |     1.    38.     2 (0) | 00:00:01 |
--------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):
---------------------------------------------------

1 - filter(','||:ENAME_LIST||',' LIKE '%,'||") ENAME "|", %')

19 selected lines.

SQL >

Tags: Database

Similar Questions

  • command evaluated Pivot and UnPivot in the select statement

    My research assessing the order of the select statement is below.
     1 from
     2 where (Join condition)
     3 start with
     4 connect by
     5 where (filter of rows)
     6 group by
     7 having
     8 model
     9 select
    10 order by
    My question is Where clause Pivot and UnPivot clause ?

    http://download.Oracle.com/docs/CD/E16338_01/server.112/e10592/statements_10002.htm

    Well the pivot is applied to a single table or an inline or a view - so it's going to be like any other table or view in the list - it will be first

    select b.BUSINESS_OBJECT_CATEGORY_DESCR, a.c, a.d
    from
     (select PAY_METHOD_TYPE_CODE, BUSINESS_OBJECT_CATEGORY_CODE
      from target_odi.business_object_pay_methods)
     pivot (count(PAY_METHOD_TYPE_CODE)
             for PAY_METHOD_TYPE_CODE in  ('D' as d, 'C' as c)) a ,
    target_odi.business_object_categories  b
    where a.BUSINESS_OBJECT_CATEGORY_CODE = b.BUSINESS_OBJECT_CATEGORY_CODE
    

    So for the SQL above the pivot is first assessed before the join between A and B.

  • Insert and update by the select statement

    Hi all
    How can I insert and update in an oracle 10g database table
    by a select statement. do not merge.

    Florian wrote:
    Hi all
    How can I insert and update in an oracle 10g database table
    by a select statement. do not merge.
    >

    How can I insert and update in a table of database oracle 10g via a select statement. do not merge.

    Do you mean by using subqueries?

    Something like

    insert into whatever
      ...select statement
    
     update whatever
        set (column, column) = (select column, column ...)
    

    There is a lot of information on this topic in the online documentation

  • String separated by commas as input and display output

    Hello

    I have a requirement that I have to take a string separated by commas as entry (may be in a table?) and display the output.

    For example, executions should be like this:

    Please enter the string separated by commas:

    A, B, C, D (entries of the user)

    Output must be

    You entered:
    A
    B
    C
    D


    How can do us in PL/SQL?

    Thank you
    Pramod
    /* Formatted on 2012/06/12 09:22 (Formatter Plus v4.8.8) */
    SELECT     REGEXP_SUBSTR ('A,B,C,D', '[^,]+', 1, LEVEL) AS re
          FROM DUAL
    CONNECT BY LEVEL <= NVL (LENGTH (REGEXP_REPLACE ('A,B,C,D', '[^,]', NULL)), 0) + 1;
    
  • 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
    
  • QUERY: separated by commas vlues checkbox in the category

    ID category name ( separated by commas vlues checkbox in the category )

    001 abc 1.2

    XYZ 002 2.3

    zzz 003 0.1

    QUESTION:

    I want to get the recoreds of these categories who category 1 and 0 ...

    Select *.

    TABLE

    Where?

    I thank you,

    Should standardize to have a mapping table instead:

    Map

    ==========

    Category ID

    1 001

    2 001

    2 002

    3 002

    003 0

    1 003

    Then, you use a JOIN to get matching records:

    SELECT Table.*

    JOIN INTERNAL TABLE

    Card WE Table.Id = Map.Id

    WHERE Map.Category IN (0, 1)

    To do this with your current data model, you must do something like this:

    SELECT *.

    TABLE

    WHERE ',' category + ',' LIKE ' %, 0, %'

    OR ',' category + ',' LIKE ' % 1% '

  • How can I fix lines horizontal randomly and glitter for the LCD screens for HP Pavilion dv5 Vista?

    How can I correct random lines horizontal and glitter for the LCD screens for windows vista HP Pavilion dv5? Only, it happens randomly and can get all a few minutes at a time every few hours. The entire screen white and black and horizontal lines will appear during the flickering on the half top of the screen only. Nothing else changes. My sound is immutable, and none of my screens change the size or location. However, they may appear up and down during the flashing. Can someone give me an idea of what is wrong? I looked on Google for possible corrections, but most of them seem to be for refresh rate and I don't have a notch for this and can't change it according to the steps they offer.

    Read my initial response on what it takes to please.

    "See if this helps you:

    These lines indicate corruption graphics driver or lack of graphic material.

    Go to the HP Web site > Search a drivers and download article > search your laptop model number > your operating system > drivers for it: either video / graphic / Chipset (according to the wording it) > download and install the drivers.

    http://WWW8.HP.com/us/en/support-drivers.html

    If that fixed it, it seems to me be a problem of graphic material.

    Because it's a laptop; If under warranty, contact HP.

    If is not under warranty, contact a repair shop, local. »

    See you soon.

  • In Windows XP, I could choose a file (or files), then go to Edit, and then invert the selection. How do I do that in Windows 7?

    Original title: invert the selection

    In Windows XP, I could choose a file (or files), then go to Edit, and then invert the selection.  How do I do that in Windows 7?

    I think Alt-E-I is also the shortcut for this feature.

  • How can I leave my desktop screen and go to the screen where I can click on the icons to go to the websites I want?

    How can I leave my desktop screen and go to the screen where I can click on the icons to go to the websites I want?

    Hello

    Please, move your cursor to the bottom left. You will see a small photo with the screen full of apps, then click on that and you will be taken to this screen,
    It will be useful.
    Josh.
  • How to make logical AND and or in the IF statement

    Hi all
    I use Oracle 10 g and I want to implement logical AND and OR in the IF STATEMENT how can I do?

    Thanks in advance :)

    I don't see what that has to do with the forms, but let's go anyway:

    IF (1=2 AND 2=2)  -- this returns FALSE
    OR ( 1=1 )  -- this returns TRUE
    THEN
    ...
    

    You can do hundreds of combinations, so it is impossible to tell what you statement should be.

  • How to use the Type of Oracle Table values in the Select statement.

    Hello

    I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.

    For example, try something like the following:

    TYPE t_record () IS RENDERING
    ID TABLEA.ID%type,
    NO TABLEA.NO%type

    );
    v_record t_record;
    T_table TYPE IS the v_record TABLE % TYPE;
    v_table t_table;

    -Code to fill the values of v_table here.

    SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
    WHERE ID IN (i) v_table USER.USER;

    I want to know how to use the Type of Oracle Table values in the Select statement.

    Something like this:

    create or replace type t_record as  object (
    id number,
    no number
    )
    /
    
    CREATE or replace type t_table AS TABLE OF t_record;
    /
    
    set serveroutput on
    declare
    
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    
    begin
    
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
    
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
    
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
    
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /
    

    No test!

    P;

    Published by: bluefrog on March 5, 2010 17:08

  • Are made and shipped to the United States at the Canada Apple books and so have shipping and additional costs due to the change of currency?

    Are made and shipped to the United States at the Canada Apple books and so have shipping and additional costs due to the change of currency? A book of dollar $50 USA could go to over $ 100.

    Apple print products are quoted and charged in the local currency

    and the calculation of your Exchange rate is whack too - the CD is $0.77 USD - no $0.. (50) but the exchange rate is not serious since quotes and fees are in local currency

    LN

  • I bought an iPhone 6s and more in the United States, now its screen is broken, I live in China, personal APPLE let me come back to the United States for maintenance!  So ridiculous, help! Thank you!

    I bought an iPhone 6s and more in the United States, now its screen is broken, I live in China, personal APPLE let me come back to the United States for maintenance!  So ridiculous, help! Thank you!

    the iPhone may be served only in the country where it was purchased. Nothing strange in this situation. You can ask your friends or relatives in US to take your device at the Apple Store it.

  • How to ask the user to type in the select statement

    Hello

    Can anyone tell me the syntax of the select statement where I can ask the user to enter the value.

    for example, I try to use belowthing, but it displays error

    Select * from emp where empname =: empname

    SP2-0552: Bind "empname' undeclared variable.


    2. is there a dictionary of data table to see all pl/sql procedures and corresponding code?


    Thank you
    Sri

    Try:

    select * from emp where empname='&empname';
    

    L.

  • How to pass parameter in the function using the select statement?

    Hello

    I had a problem. I can't pass as parameter to the function by using the select statement. But it can pass as a parameter using the "code". How can I solve this problem?

    For example,.
    Select * from table (SplitFunction ('HS750020, HS750021')) < < < this work.

    but

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) < < < do not work.

    Thank you for trying to help him. Thank you.

    Select * from table (SplitFunction (select LOT_NO in the TRACER_SEARCH_SCHEDULE where JOB_ID = '36'))< do="" not="">

    Try like this

    select * from table(select splitfunction(lot_no) from tracer_search_schedule where job_id='36')
    

    Just make sure that your subquery returns only 1 row.

Maybe you are looking for

  • Move the bar on the bookmarks bar

    I wonder if it is possible to move the menu bar of the bookmarks bar, or if need is, move all items from bookmarks to the menu bar bar and then drag the menu on the tabs bar. There was once an add-on called "Interface user fix" that allow me to do th

  • Satellite C855-5347 - strange temperature problem

    I have an old C855 5347 of 3 years with a strange temporary problem, right of the touch pad between her and the corner got warm enough. I wonder what is in this area that make heat. Speccy time show Ok, all vents are clear. Any ideas appreciated! Phi

  • How to release the FGV Instrument

    Hello! I have a varaible gloabal funtional (FGV) (under LabVIEW teststand I call) who has an enum def of strict type with reading, writing, and closing. The initilizes is performed by a Boolean unitzilized shift register cheching if the vi initilized

  • Error message when closing Outlook Express 6.0

    Hello Sometimes I get an error message when I close off Outlook Express version 6.0. It asks if I want to debug the program and also asks me if I want to send an error report to Microsoft. There is also a link to click if I want to see the details of

  • My computer will not download an update, then stop not

    Original title: no closures My computer will not download an update, then stop not