Check var PL/SQL in an if STATEMENT with a list of values returned by a SELECT?

I have a variable in my PL/SQL code, and I want to check if the value of the var is in a list of values. This list of values I want to get directly from a select statement. I can do something like below:
IF (v_var1 in (select col1 from <table> where <condition>))
THEN
   <do something>
ELSE
   <do something else>
END IF;

And rownum = v_loop will not work for rownum anything to 1.

You can try something like:

SELECT COUNT (1) INTO v_row_count FROM  WHERE ;

IF (v_row_count = 0)
THEN
   
ELSE
   v_loop := 1;
   FOR I IN (SELECT col1 FROM 
WHERE ) LOOP v_sel_val1 := I.col1; IF (v_var1 = v_sel_val1) THEN END IF; END LOOP;

Tags: Database

Similar Questions

  • Output to aid in State of the list of values given

    with param_list

    as (select "1,2,3" rang the double).

    like tab (select 1 double id)

    Union of all the

    Select 2 double)

    Select * from tab

    where id in (1,2,3);

    is running, but I want something like that where in another table to string as 1,2,3 that will pass as value to filter the result, is it possible something like that

    with param_list

    as (select "1,2,3" rang the double).

    like tab (select 1 double id)

    Union of all the

    Select 2 double)

    Select * from tab

    where id in (select rang param_list);

    Thank you it worked, I was doing stupid error in query

    with param_list

    (select "1,2,3" as rang double),

    like tab (select 1 double id)

    Union of all the

    Select 2 double)

    Select * from tab where id in)

    SELECT

    REGEXP_SUBSTR(rang, '[^,]+', 1, Level) AS single_element

    DE)

    SELECT ROWNUM AS ID

    rang

    OF param_list

    )

    CONNECTION BY INSTR (rang, ',', 1, LEVEL 1) > 0

    AND id = PRIOR id

    AND PRIOR DBMS_RANDOM. VALUE IS NOT NULL);

    This is the working one, please give me advice

  • Problem adding a variable with a list of values in SQL

    Does anyone have an idea why it works->

SELECT DISTINCT (countryLong) AS CountryLong
Of ipcountry
WHERE countryShort IN ('US', 'UK')
ORDER BY countryLong

But it does not work->

< CFSET target_country = "" WE","UK"" >

SELECT DISTINCT (countryLong) AS CountryLong
Of ipcountry
WHERE countryShort IN (#target_country #)
ORDER BY countryLong

When I run the list as a variable I get an error, an incorrect syntax near 'US '.

(CF8 - MS SQL2005)

Thank you

Mark

In fact, I posted an example by e-mail. But as usual my answer forum. Strangely, he worked a few days ago. In any case at least once.  Must have been a fluke.  Anyway here's what response should have looked like:

But if you use cfqueryparam instead, you don't have to worry about quoting values

...

WHERE countryShort IN ( )

  • How to check if the entity is in a State of "busy".

    Hello

    I am trying to add a new virtual machine to a paralytic, using recomposevApp. At the same time several other threads also try redialing and add a virtual machine at the same TIME. And then I remove the TIME where the virtual machine has been added. It is originally several exceptions.

    • No access to the entity
    • Entity is busy completing a transaction.
    • The operation is not allowed, please contact your administrator vcloud.

    I want to know, how can I check if the TIME at which a virtual machine must be added, is busy or not?

    I want to check if the vapp is in a stable condition before you add a virtual machine.

    Other ideas are welcome. Please help as soon as possible.

    Thanks in advance.

    Mansie

    You can check if a vApp is busy in two ways:

    (1) obtain the vApp, observe the element inside the vApp and check for all tasks in the 'running' State: If there is a running task, then the vApp is busy and cannot be reconstructed

    (2) using the query service, you can run a query of vApp (GET/api/query? type = adminVApp) to get all the vApps (or interested in a filter by name to get the VAPP): inside the query results is a Boolean field named "isBusy" showing that the VAPP is occupied or not.

    Kind regards

    Todor Todorov

  • PL/SQL and Case &lt; href &gt; statement

    I have just a bit of code in Pl/SQL, and since I had to put this Case statement with javascript I can't get the correct syntax. Can someone please help with the ' and ' in this statement?

    Thank you

    {code}

    v_query: = "SELECT";

    v_query: =.
    v_query | Case when sd.sd_id = 1 then ' < a href = "javascript:fnc_tabAddUser (v1); ' > '
    || "< img src =" #WORKSPACE_IMAGES #sd.png ">"
    || "< /a >."
    end as open_sd | "category", | ' s1.sub_cat_1,'| '. S2.sub_cat_2,' | "program", | "sd.sd_name," | "sd.sd_date," | "s2.synopsis," | "sd.sd_id,";

    {code}

    Basically, most of the v_query is her go and where clauses but here is simply the select clause. I can post the whole code if it helps. Everything works fine until I entered the Case statement and I believe that my syntax is off. Also, I tried to read and find similar code and some mentioned using Htp.p but I don't know if necessary.

    Published by: Res Ipsa on June 22, 2011 11:49

    Published by: Res Ipsa on June 22, 2011 11:49

    Published by: Res Ipsa on June 22, 2011 11:50

    There was also a problem with your order of. There was no space for text is released which looks like this:

    '', 1) > 0ORDER BY 1 DESC 
    

    This gives a shot. I don't bother to do the tables, so it may not always work.

    DECLARE
       v_query   VARCHAR2 (4000);
       v_search_string VARCHAR2(4000);
    
    BEGIN
        v_search_string :=
        '
            '||:p1_search_string||'
             
               transform((TOKENS, "{", "}", " "))
               transform((TOKENS, "{", "}", " ; "))
               transform((TOKENS, "{", "}", "AND"))
               transform((TOKENS, "{", "}", "ACCUM"))
             
           
          
        ';
    
       v_query := 'SELECT   ';
       IF :p1_search_string IS NOT NULL
       THEN
          v_query := v_query || 'score (1) relevance, ';
       ELSE
          v_query := v_query || '''100%'' relevance, ';
       END IF;
    
       v_query :=
          v_query || 'Case when sd.sd_id = 1 then '''''
                  || 'end as open_sd, category, s1.sub_cat_1, s2.sub_cat_2, '
                  || 'program, sd.sd_name, sd.sd_date, s2.synopsis, sd.sd_id, ';
    
       IF :p1_search_string IS NOT NULL
       THEN
          v_query :=
                v_query
             || 'NVL2 '
             || '(:p1_search_string, '
             || 'ctx_doc.snippet '
             || '(''docsx'', '
             || 'ROWID, '
             || 'NVL (:p1_search_string, ''%''), '
             || ''''', '
             || ''''' '
             || '), '
             || 'NULL '
             || ') snippet ';
       ELSE
          v_query := v_query || 'NULL snippet ';
       END IF;
    
       v_query := v_query
          || 'FROM from pri_cat p
              left join sub_cat_1 s1
              on p.cat_id = s1.cat_id
              left join sub_cat_2 s2
              on s1.sub_1_id = s2.sub_1_id
              left join select_program pro
              on s2.pro_id = pro.pro_id
              left join supplemental_direct sd
              on s2.sd_id = sd.sd_id  ';
    
       IF :p1_search_string IS NOT NULL
       THEN
          v_query := v_query || 'WHERE contains (synopsis, ''' || v_search_string || ''', 1) > 0';
       END IF;
    
       v_query := v_query || ' ORDER BY 1 DESC ';
       return(v_query);
    END;
    

    See you soon,.
    Janet Tyson

  • CASE of PL/SQL in the INSERT statement

    I'm trying to insert a record into a table, change the value of the field in the insert based on a condition. To simplify the code:
    DECLARE
    
      true_or_false BOOLEAN;
    
    BEGIN
    
      true_or_false := FALSE;
          
      INSERT INTO table1
      (column1)
      VALUES
      (CASE WHEN true_or_false = FALSE THEN 0 ELSE -1 END);
      
    END;
    It of something that I can do in SQL Server but do not understand the right Oracle syntax. Can someone help me please?

    If the BOOLEAN data type is allowed for the PL/SQL variable, it is not in a query.
    Something like that:

    SQL> DECLARE
      2    true_or_false BOOLEAN:= FALSE;
      3    var number;
      4  BEGIN
      5    if true_or_false then var:=-1; else var:=0; end if;
      6    INSERT INTO table1
      7    (column1)
      8    VALUES
      9    (var);
     10  END;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL> select * from table1;
    
       COLUMN1
    ----------
             0
    

    Nicolas.

  • Update of security for sql server sp3 KB94981 fails with error 2B 33

    Each update for SQL Server 2005 on my computer Vista Home Premuim fails. The most recent example is:

    Update of security for sql server sp3 KB94981 fails with error 2B 33

    for SP2, it was

    Security for sql server sp2 KB960089 update fails with error 6AA

    Other updates have been ad are successful, although I found out recently that it is the recovery disc option to create under maintenance contract. I fdound the recdisk.exe file, but running it does nothing.

    Mike

    Maybe check this forum:

    SQL Installation of Server & upgrade
    http://social.msdn.Microsoft.com/forums/en-us/sqlsetupandupgrade/threads/

    TaurArian [MVP] 2005-2010 - Update Services

  • Remove the statement with subquery with more than 1 columns

    Hi all

    I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.

    DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);

    Hello

    user12251389 wrote:

    I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.

    DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);

    Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

    If you ask about a DML operation, such as DELETE, and INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum:

    You want to keep only the maximum timestamp for the entire table, or you want the maximum timestamp for each distinct value of kpi_def_id?

    If it is just the maximum timestamp for the whole picture, then

    DELETE FROM kpi_logs

    WHERE the timestamp<>

    SELECT MAX (timestamp)

    OF kpi_logs

    );

    If you want to keep the maximum timestamp for each individual value phew kpi_def_id, then:

    DELETE FROM kpi_logs

    WHERE (kpi_def_id, timestamp NOT IN)

    SELECT kpi_def_id

    MAX (timestamp)

    OF kpi_logs

    GROUP BY kpi_def_id

    );

    assuming that no column can be NULL.

    Moreover, the TIMESTAMP is a data type, similar to this DAY.  You'll only cause confusion by saying it is a type of data when it is really another.  In addition, TIMESTAMP is a keyword from Oracle, is not a very good column name.  Why not give your column a name more meaningful, accurate, such as create_date or entry_dt?

  • Update statement with joins of tables and where Clause

    Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.

    Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.

    The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!



    1:

    Update PenaltyAll
    Set a.indicator = month (b.)
    of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
    where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20

    2:

    Update PenaltyAll
    adjustment indicator =
    (select to_char (b., 'MM')
    of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
    "where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
    (et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
    and b.apr < 20)

    Published by: sqlrookie on August 21, 2009 07:04

    I edited my post, that was my mistake, ANC you try now?

  • How can I get rid of a redirect virus. It is not DNS, I checked several times. I scanned my Mac with Malware bytes multiple times. He is yet to come. I am very confused. Help me!

    I'm on MacBook Pro (retina, 15 inch, mid-2015) how can I get rid of a redirect virus. I use Google Chrome. It is not DNS, I checked several times. I scanned my Mac with Malware bytes multiple times. He is yet to come. I am very confused. Help me!

    http://Syndication.ExoClick.com/splash.php?IDZone=1758202&type=8

    It's the kind of redirects that I get all the time

  • What would cause a SQL server to blue screen with FFFFF81001BA5198 code

    What would cause a SQL server to blue screen with FFFFF81001BA5198 code

    Hello

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the Windows Server forum. You can follow the link to your question:

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

  • The computer is very unstable... Should I reset the computer to the original state with Dell recovery

    As there is no support for Windows XP SP2 updates (I managed to get the Microsoft SP3) if I go back to my computer to the original state with recovery Dell how do I get Service Pack 2 and 3 again.  Deleted files gives access to the trash... they no longer heard by KIJIJI when I tried to place an ad that some well known hacker has been using my IP address.  This means that he can see literally everything I do on my computer.  Really need help

    overthehillandonaroll

    Run Windows Update after recovering the system.  It will offer you all the updates, including service packs.  Run repeatedly until it shows that no more updates to date are available. Boulder computer Maven
    Most Microsoft Valuable Professional

  • How can I check the ink levels in a printer-c410a with windows 8?

    How can I check the ink levels in a printer-c410a with windows 8?

    Hi Doug007,

    I see that your wanting to check ink levels.  I'd take a glance on the document below it shows alternate ways to check ink levels.

    Control of ink levels

    I hope this helps.

  • SQL to convert a row with 4 columns to 4 rows with 1 column

    Sorry, I know this question has been asked hundreds of times before!

    This is my starting SQL:

    set linesize 500
    
    with tbl_data AS
     (select 'N' argument1, 'Y' argument2, NULL argument3, 'Y' argument4 from dual)
    select * from tbl_data;
    
    
    ARGUMENT1 ARGUMENT2 ARGUMENT3 ARGUMENT4
    --------- --------- --------- ---------
    N         Y                   Y        
    

    Is it possible to enter the data in this format:

                    COL_HEADING
    ARGUMENT1       N
    ARGUMENT2       Y
    ARGUMENT3       
    ARGUMENT4       Y
    

    I have read comments UNPIVOT but can't really work on the syntax to get a single line with 4 columns to appear as 4 rows with 1 column.

    Sorry - I realize that I'm probably be lazy and stupid.

    Any advice much appreciated, thank you.

    Hello

    Here's a way to do it with UNPIVOT:

    SELECT *.

    OF tbl_data

    MUST INCLUDE NULL VALUES

    (col_heading

    FOR column-name IN (argument1

    argument2

    argument3

    argument4

    )

    )

    ;

    Output:

    COLUMN COL_HEADING

    --------- -----------

    ARGUMENT1 N

    ARGUMENT2 Y

    ARGUMENT3

    ARGUMENT4 Y

  • Case statement with a select &amp; date in

    Hello everyone,

    This is my first discussion, so please bare with me.

    I am trying to write a case statement with a select statement that compares the dates.

    When I write an instruction box with a select statement in it compares everything but dates it works fine.  Once the date is there, he collapses.

    Here is a super simple example of what I'm trying to do, "b.in_serv_dt" is a date

    Select unit_no,

    case when ((sélectionnez b.in_serv_dt de b unit_dept_comp_main où a.unit_id = b.unit_id et b.in_serv_dt) > = 1 January 2012 "") then "everybody wins."

    When ((sélectionnez b.in_serv_dt dans l'unit_dept_comp_main b où a.unit_id = b.unit_id et b.in_serv_dt) < = 1 January 2012 "") then "Nobody wins".

    end

    of ottawa_unitmain_v one

    Any help would be greatly appreciated

    Thank you very much

    Hello

    your statement of formatting:

    Select unit_no
    case when ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    and b.in_serv_dt
    ") > = JANUARY 1, 2012"
    ) and then "everybody wins."
    When ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    and b.in_serv_dt
    )<=>
    ) and then "no winner".
    end
    of ottawa_unitmain_v one

    I see "partial conditions": <... and="" b.in_serv_dt="">> that have no meaning.
    I guess it's a kind of "typo" and I ignore them.
    If the statement is:
    Select unit_no
    case when ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    ") > = JANUARY 1, 2012"
    ) and then "everybody wins."
    When ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    )<=>
    ) and then "no winner".
    end
    of ottawa_unitmain_v one

    I guess that the "b select" retrieve one line, through the design of database (forced...)

    As already written: be careful with data types: avoid "implicit conversions" (when you compare different data types, Oracle has convert the data type of the other side, a side example: "mystring = mynumber" is transformed into 'TO_NUMBER (mystring) = mynumber', or 'mydate = mystring' translates mydate = TO_DATE (mystring, ) ")
    Even better: use explicit conversions, use explicit formats when necessary.
    Best: use no conversion on columns from the constants, but use the correct data type for the constant.

    With this in mind:
    Select unit_no
    case when ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    ) > DATE = ' 2012-01-01'
    ) and then "everybody wins."
    When ((select b.in_serv_dt
    of unit_dept_comp_main b
    where a.unit_id = b.unit_id
    )<= date="">
    ) and then "no winner".
    end
    of ottawa_unitmain_v one
    But note that b.in_serv_dt EQUAL to 1 January 2012 (at 00:00:00) is OK for both WHEN the conditions; then the a "win."

    Now: the subselect statement is identical in the 2 options of the case... You could work differently: (I add the "ELSE" in case one line as NULL in_serv_dt;) I guess that an INNER JOIN is OK, maybe you need a LEFT OUTER JOIN (if some lines of A have no corresponding row in B)

    SELECT a.unit_no
    , CASE WHEN b.in_serv_dt > = DATE '' 2012-01-01
    THEN "everyone wins"
    WHEN b.in_serv_dt< date="">
    While "Nobody wins".
    ELSE ' who knows... ". »
    END who_wins
    Of ottawa_unitmain_v one
    INNER JOIN unit_dept_comp_main b
    ON a.unit_id = b.unit_id
    ;

    Best regards

    Bruno Vroman

  • Maybe you are looking for