Please help me fix this SQL query...

Hi, please consider following:
create table test (col varchar2 (255))
insert into test values ("TERM").
Insert test values ("VOLUME");

Select the test pass where pass in ('TIME', 'VOLUME');
This property returns the rows.

but my input string is a comma-separated list:
DURATION, VOLUME

so I try
Select the test pass where col to (replace (' DURATION, VOLUME, ',' "'," '));
but no result. Or:
Select the test pass where col in ("' | replace (' DURATION, VOLUME, ','" ', "') |") ') ;

However
Select "' | Replace (' DURATION, VOLUME, ',' "'," ') | " ' the double
gives "DURATION", "VOLUME".

then why does it work?

hope you can help. Thank you

convert stringlist in lines and then use in the clause...

SELECT col
   FROM test
  WHERE col IN
  (SELECT    *
     FROM
    (SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1 , INSTR (txt, ',', 1, level+1 ) - INSTR (txt, ',', 1, level) -1 ) ) AS token
       FROM
      ( SELECT ','||'DURATION,VOLUME'||',' AS txt FROM dual
      )
      CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1
    )
  )

Ravi Kumar

Tags: Database

Similar Questions

  • Please help me write this SQL query...

    Hi everyone,
    
    Please help me in this query.
    A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and
    if they have (M and D) i need to select type M,and if they have only type D i have to select that.
    For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag)
    
    Patient table
    =============
    
    Patient_id          First_name    last_name
    
    1                   sanjay        kumar
    2                   ajay          singh
    3                   Mike          John
    
    
    Adress table
    ============
    
    address_id       patient_id       adresss       city       type       startdate        enddate      valid_flg
    
    1                   1             6222         dsadsa           P          01/01/2007       01/01/2010
    2                   1             63333        dsad             M          01/02/2006       01/01/2007      N
    3                   1             64564         fdf              M          01/01/2008       07/01/2009      
    4                   1             654757       fsdfsa          D          01/02/2008       09/10/2009  
    5                   2             fsdfsd       fsdfsd            M          01/03/2007       09/10/2009   
    6                   2             jhkjk        dsad              D          01/01/2007       10/10/2010   
    7                   3             asfd         sfds               D          01/02/2008       10/10/2009      
    
    
    output
    =====
    
    1        sanjay       kumar            6222       dsadsa      P          01/01/2007        01/01/2010     
    2        ajay         singh            fsdfsd     fsdfsd       M          01/03/2007        09/10/2009 
    3        mike         john              asfd       sfds        D          01/02/2008        10/10/2009
    Thanks in advance
    Phani

    Hello, Fabienne,.

    This race for you (twisted code of Sarma):

    SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    

    Edit, currently in the trial:

    With Patient AS (
    SELECT 1  Patient_id , 'sanjay' First_name, 'kumar'  last_name FROM DUAL UNION ALL
    SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL
    SELECT 3, 'Mike', 'John' FROM DUAL),
    Address AS (
    SELECT 1   address_id, 1  patient_id, '6222'    address, 'dsadsa'   city, 'P'  type, to_date('01/01/2007', 'DD/MM/YYYY')  startdate, to_date('01/01/2010', 'DD/MM/YYYY')  enddate, NULL  valid_flg FROM DUAL UNION ALL
    SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'),  ' N'  FROM DUAL UNION ALL
    SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
    SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
    SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL)
    -- end test data
     SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
     FROM (
      SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
                 ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                          WHEN  'M' THEN 2
                                                                          WHEN  'D' THEN 3
                                                                        END) rn
        FROM  patient p
        JOIN  address a ON (p.patient_id = a.patient_id )
       WHERE NVL(valid_flg, 'X') != 'N'
         AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
         )
    WHERE rn = 1; 
    
    PATIENT_ID FIRST_ LAST_ ADDRESS CITY   TY STARTDATE ENDDATE
    ---------- ------ ----- ------- ------ -- --------- ---------
             1 sanjay kumar 6222    dsadsa P  01-JAN-07 01-JAN-10
             2 ajay   singh fsdfsd  fsdfsd M  01-MAR-07 09-OCT-09
             3 Mike   John  asfd     sfds  D 01-FEB-08 10-OCT-09
    
  • Please help me with this SQL query

    I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.

    The three paintings are as below

    < pre >
    Country
    Location_id country
    LOC1 Spain
    loc2 England
    LOC3 Spain
    loc4 USA
    loc5 Italy
    loc6 USA
    loc7 USA
    < / pre >
    < pre >


    User
    user_id location_id
    loc1 U1
    loc1 U2
    loc2 U3
    loc2 U4
    loc1 U5
    U6 loc3
    < / pre >
    < pre >


    Publish
    user_id post_id
    P1 u1
    P2 u1
    U2 P3
    P4 u3
    P5 u1
    P6 u2
    < / pre >

    I am trying to write a SQL query - for each country of the users, showing the average number of positions

    I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
    But, I'm having a difficulty to this format SQL. Could someone help me please with this request.

    Thank you.

    Select
    Country.Country,
    Count (*) Totalpostspercountry,
    Count (distinct post.user_id) Totaldistincuserspercountry,
    count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
    Of
    countries, have, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    Country.country group

    The output is like this for your sample data - hope that's what you're looking for :)

    COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
    In England, 1, 1, 1.
    Spain, 5, 2, 2.5.

  • When I try to defrag, a window opens and closes and a file download-security warning. A loop repeats. Other programs to do the same thing. Please help me fix this loop? SOS?

    When I run defrag, an IE window opens and closes and a file download-security warning comes up and asks me to run or save the file name: c:\windows\system32 dfrgui.exe, if I hit then another warning of IE - sec stands up and says 'the Publisher could not be verified. Are you sure that you want to run. I struck and the loop repeats. I run a diag of the F10 boot menu with dell. They say that its software and non-material, pay! Microsoft says that Dell is responsible. Other programs to do the same thing. I've updated and rerun my AVG security without error. We are automatically updated, and no other programs were added. Please help me fix this loop? SOS?

    Vista - open file - security warning
    http://www.Vistax64.com/Vista-security/125044-open-file-security-warning.html

    How to repair the operating system and how to restore the configuration of the operating system to an earlier point in time in Windows Vista
    http://support.Microsoft.com/kb/936212/#appliesTo

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
    http://support.Microsoft.com/default.aspx/KB/929135

    Your programs launch properly from Safe Mode?  Or Normal Mode if you create another user to test with?

    Vista advanced boot options
    http://Techblissonline.com/Vista-advanced-boot-options/

    Try running ChkDsk to check your drive for errors. Right click on your drive icon / properties / tools / error checking.  Try first by checking do not each box (that it will run in read-only mode) to see if it reports any problems file or hard drive.  If so, restart it by checking both boxes and restart to allow him to attempt to fix any problems found.

    I see a lot of recommendations here for programs such as -

    Malwarebytes' Anti-Malware
    http://www.Malwarebytes.org/MBAM.php

    SuperAntispyware
    http://SUPERAntiSpyware.com/

  • Please explain to me this sql query

    Select * from emp e
    where 2 > (select count (sal) from emp where the e.sal < sal)

    It gives higher and the second highest salary, but how it works I HAV eno no idea please let me know briefly.

    Hello
    is
    Welcome to the forum!

    Thus, you have a query like

    SELECT  *
    FROM    emp     e
    WHERE   2 > x;
    

    and you want to understand how it works. I guess the part that you don't understand is so x, x display.

    SELECT  e.*
    ,       x
    FROM    emp     e
    WHERE   2 > x;
    

    Since the clause WHERE eliminates most of the lines, we will not use a WHERE clause for now. Also, we will simply display a couple of columns, just so that we can concentrate on the important parts better. We will only display the sal (because the query has something to do with the highest sal) and something unique on each line, like ename. Is, try to run something like this:

    SELECT       ename, sal
    ,       (
             SELECT  COUNT (sal)
             FROM    emp
             WHERE   e.sal     < sal
           )     AS x
    FROM       emp     e
    ORDER BY  sal
    ;
    

    Output:

    ENAME             SAL          X
    ---------- ---------- ----------
    SMITH             800         13
    JAMES             950         12
    ADAMS            1100         11
    WARD             1250          9
    MARTIN           1250          9
    MILLER           1300          8
    TURNER           1500          7
    ALLEN            1600          6
    CLARK            2450          5
    BLAKE            2850          4
    JONES            2975          3
    SCOTT            3000          1
    FORD             3000          1
    KING             5000          0
    

    You see what x is now? This is the number of lines where sal is higher than sal on the current line.
    Nobody has one of its KING sal, so x = 0 to the rank of KING.
    Only 1 person (that is, the KING) has a higher sal of SCOTT, so x = 1 on the line for SCOTT.
    13 persons (that is, everyone except SMITH) has a greater sal then SMITH, so x = 13 on the BOF SMITH line.

  • How to prevent a user not to access a table of perticular? This user has select any table privilege. Please help me solve this problem.

    Hello

    How to prevent a user not to access a table special (xxx)?

    This user has SELECT a TABLE ALL privilege. I need to restrict to only not for access xxx to the table, but this table is not existed in its own schema.

    But there is access able as select * from schema.table;

    How can I revoke this privilege.

    Please help me solve this problem.

    Thank you

    Lacombe

    1623609 wrote:

    How can I select privilege on specific tables at the same time?

    I want to create a new user and grants the right to select for tables, except a table (xxxx).

    It will be possible without the keystone of the database?

    One way, in several sql

    coil doit.sql

    Select ' grant select on ' | owner: '. ' || table_name |' to someuser. »

    from dba_tables

    where

    spool off

    Then sanity check "doit.sql" and execute it.

  • I sent by email informing you that my computer crashed last month and now I'm ready to download the creative cloud again.  Please help me on this.  I have not used the program while paying for him.  hoping for your immediate answer on what to do. Peut

    I sent by email informing you that my computer crashed last month and now I'm ready to download the creative cloud again.  Please help me on this.  I have not used the program while paying for him.  hoping for your immediate answer on what to do. Can I download the free trial version and apply my account on it and fix it on your side?  Kindly get back to me as soon as possible because I need it for my school work and tasks.  Thank you.

    Uninstall anything cc which can be installed. »

    Restart your computer.

    clean a http://www.adobe.com/support/contact/cscleanertool.html

    Restart your computer

    install the cc desktop application, use of the desktop application cloud creative to manage your applications and services

  • Please let me know how I can add a new column with a constraint not null, table already has data, without falling off the table... Please help me on this issue...

    Hello

    I have an emp_job_det with a, b, c columns table. Note that this TABLE ALREADY has DATA OF THESE COLUMNS

    IAM now add a new column "D" with forced not null

    Fistly I alter the table by adding the single column "D", if I do, the entire column would be created with alll of nulls for the column DEFAULT D

    ALTER table emp_job_det Add number D; -do note not null CONSTRAINT is not added

    Second... If I try to add the constraint not null, get an eoor as already conatained null values...

    (GOLD)

    In other words, if I put the query

    ALTER table emp_job_det Add number D NOT NULL; -THROWS ERROR AS TABLE ALREADY CONTAINS DATA

    So my question is how how can I add a new column with a constraint not null, table already has the data, without falling off the table

    Please help me on this issue...

    Add the column without constraint, then fill the column. Once all the rows in the table are given in the new column, and then add the constraint not null.

  • Please help me fix the script

    I try to write a script by my slef but not work

    app.findGrepPreferencest = firstLineIndent:8, leftIndent:8;

    app.changeGrepPreferences = firstLineIndent:8, leftIndent:16;

    app.changeGrep ();

    app.findGrepPreferences = app.changeGrepPreferences = null;

    Can someone please help me fix the script, please.

    Hello

    Try this.

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.firstLineIndent = '8 ';

    app.findGrepPreferences.leftIndent = '8 ';

    app.changeGrepPreferences.firstLineIndent = '8 ';

    app.changeGrepPreferences.leftIndent = "16pt;

    app.changeGrep ();

    app.findGrepPreferences = app.changeGrepPreferences = null;

    Kind regards

    Cognet

  • Please help me fix my script!

    Please help me fix my script

    I use this script that copy from the adobe forum:

    app.findGrepPreferences.findWhat = "\\r";

    app.changeGrepPreferences.changeTo = "\\r\\r";

    app.changeGrep ();

    app.findGrepPreferences = app.changeGrepPreferences = null;

    to change my back one or two, but it will always change all my documents.

    How can I tell the script that I only want to change the selection?

    Hello

    Note the syntax ==> target changeGrep()

    If the target is app ==> it runs through the entire application of the ways each open document

    If the target is doc ==> it runs through all doc

    It can be called for textFrame, story, paragraph..., any text object.

    In your use case

    App.Selection [0] .changeGrep ();

    or browse the selection and appeal

    App.Selection [i] .changeGrep ();

    Jarek

  • Need help to write the SQL query

    Hello
    Please help me to write a query. My requirement is as below.

    Hello
    I have a table say XYZ in the following format.

    product_id local min_order_quntity
    ========================================
    1 en 10
    1 ch 10
    2 en 20
    2 ch 20
    3 en 30
    3 ch 30
    4 en 40
    4 NC 10

    Now I want to find the product_id where min_order_quantity is different for cn and locale

    now I want the result of the following

    product_id local min_order_quantity
    =============================================
    4          en          40
    4 ch 10

    This is different for local in and cn for product_id 4 min_order_quantity

    min_order_quantity should be the same for both the locale(en,ch) for any product_id.

    I want to find the product_id where min_order_quantity is different for ch and fr local

    Thank you..

    Hello

    This query should do the job

    select * from xyz t1
    where exists ( select 1 from xyz t2 where t2.product_id = t1.product_id and
                   t2.locale != t1.locale and t2.min_order_quantity != t1.min_order_quantity );
    

    See you soon

  • After updating my iPhone 6 (9.3.4) the WiFi signal becomes very low! I did everything, but the problem does not stop! I don't a not update my other devices &amp; their very good WiFi signals. Please help me solve this terrible problem...

    After updating my iPhone 6 (9.3.4) the WiFi signal becomes very low! I did everything, but the problem does not stop! I don't a not update my other devices & their very good WiFi signals. Please help me solve this terrible problem...

    Here's a tip for the user on the problems of Wi - Fi. Suggest from the top and bottom. Maybe one of them will help you.

    (1) restart you device.

    (2) resetting the network settings: settings > general > reset > reset network settings. Join the network again.

    (3) reboot router/Modem: unplug power for 2 minutes and reconnect. Update the Firmware on the router (support Web site of the manufacturer for a new FW check). Also try different bands (2.4 GHz and 5 GHz) and different bandwidths (recommended for 2.4 to 20 MHz bandwidth). Channels 1, 6 or 11 are recommended for 2.4 band.

    (4) change of Google DNS: settings > Wi - Fi > click the network, delete all the numbers under DNS and enter 8.8.8.8 or otherwise 8.8.4.4

    (5) disable the prioritization of device on the router if this feature is available. Also turn off all apps to VPN and retest the Wi - Fi.

    (6) determine if other wireless network devices work well (other iOS devices, Mac, PC).

    (7) try the device on another network, i.e., neighbors, the public coffee house, etc.

    (8) backup and restore the device using iTunes. Try to restore as New first and test it. If ok try to restore the backup (the backup may be corrupted).

    https://support.Apple.com/en-us/HT201252

    (9) go to the Apple store for the evaluation of the material. The Wi - Fi chip or the antenna could be faulty.

    Council: https://discussions.apple.com/docs/DOC-9892

  • The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    Hi kdwis,

    Going to try view > toolbars and activation of the Bar of Navigation and in the bookmarks toolbar.

    Hope this helps!

  • I can't shoot at a site in the usual browser... in navigation private. I can pull up in other browsers and could pull up 2 weeks ago... now I can't. Please help me solve this problem?

    Question
    I can't shoot at a site in the usual browser... in navigation private. I can pull up in other browsers and could pull up 2 weeks ago... now I can't. Please help me solve this problem? Also, I can' signed in 'members only' in private browsing mode.

    Clear the cache and cookies from sites that cause problems.

    "Clear the Cache":

    • Tools > Options > advanced > network > storage (Cache) offline: 'clear now '.

    'Delete Cookies' sites causing problems:

    • Tools > Options > privacy > Cookies: "show the Cookies".
  • I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicated. So please help me find this problem.

    I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicate. So please help me find this problem.

    Hey there, I guess your question is "how to determine if my iphone is true or false. If Yes, then if you go here https://selfsolve.apple.com/agreementWarrantyDynamic.do just enter your serial number and code and if his 'real', then it will show you the model of the Iphone and guaranteed dates. If this isn't the case, then you know the rest. If this is not the case then try to download apps from the app store and run or can it connect to itunes. Tell me what best worked: D - Jon

Maybe you are looking for

  • HP 255 G4: Start Menu

    HelloI just bought this laptop when I opened it shows me just the start menu. Is this normal? I don't know what to do.Should I return it?Thank you!

  • HP ENVY 700-414: BIOS for HP envy 700 414

    When you use the bios update site I find only bios for 2af3 and 2b 17... ssid SSID is not my ssid. My ssid is 2af7. would it not be possible to get a link to the latest bios for that motherboard. Thank you!

  • Pavilion dv7-4030er: update driver video dv7-4030er for Win7

    Where can I get video driver for my dv7-4030er switchable graphics? The last of them for Win7 x 64 has FIVE YEARS on hp.com. 1 year support is OK for HP? Latest AMD drivers (and ALL AMD drivers) do not work. LeshCat with its pilots customized UNIFIL

  • Close the form

    Lenovo ThinkPad T500 95% of the time I use the laptop connected to a flat screen of plugin, a keyboard and a mouse. Question 1 Is it possible to close the laptop screen / lid put the laptop to sleep, either keep the laptop that works with the screen

  • How can I install Windows Xp with Windows Vista?

    INSTALLATION OF WINDOWS XP WITH WINDOWS VISTA? I HAVE WINDOW VISTA HOME PREMIUM 32-BIT IN MY SYSTEM, BUT SOME OF MY SOFTWARE IMPORTANT DO NOT INSTALL VISTA SO I TRY TO INSTALL WINDOWS XP WITH VISTA BUT IT DOES NOT WORK.AFTER AWHILE, I SEE THE TYPE OF