DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Storing select query result into array and using in another query.

  1. #1
    Join Date
    Jul 2009
    Posts
    3

    Storing select query result into array and using in another query.

    Hi,

    I am looking to simplify the below query,

    DELETE FROM A WHERE A1 IN (SELECT ID FROM B WHERE BID=0) OR A2 IN (SELECT ID FROM B WHERE BID=0)


    Since both the inner queries are same,I want to extract out to a local variable and then use it.

    Say,

    Array var = SELECT ID FROM B WHERE BID=0;

    And then ,

    DELETE FROM A WHERE A1 IN (var) OR A2 IN (var)

    How to do this using SQLPLUS?Please advice.

    Thanks,

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    The closest solution would be to resort to cursors.

    Depending on table size, percentage of deletes over total population and available indexes this might be either a great idea or a performance nightmare.
    Last edited by PAVB; 08-08-2009 at 04:17 AM.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Hi,

    DELETE FROM A WHERE A1 IN (SELECT ID FROM B WHERE BID=0) OR A2 IN (SELECT ID FROM B WHERE BID=0)

    can be rewritten as:

    Code:
    delete from a 
    where exists 
             (select 'x' from b
               where b.bid = 0 and
                        b.id in (a.a1, a.a2) 
             )

  4. #4
    Join Date
    Aug 2009
    Posts
    5
    hello!I'm new to oracle triggers.
    I'm currently making "when-validate-item"
    where it will prompt a message verifying that the input data is actually what the user want to input.
    this is my code:
    Declare
    BEGIN
    SELECT CPL_DTL FROM COIL_HISTORY
    IF CPL_DTL='ST'
    THEN
    MESSAGE ('This coil undergone side trimming.')
    else
    MESSAGE ('This coil undergone side trimming.')
    EXCEPTION
    WHEN OTHERS THEN MESSAGE('Your input is wrong!);
    END;
    ____________
    the result I want is like this:
    Please input ' ST' for side trimming and 'NST' for no side trimming
    CPL_DTL:_______

    Once the user input 'ST' a window will prompt:
    "The coil has undergone Side Trimming (ST). "
    with ok and cancel button.
    How should I code it..?
    Thanks!

  5. #5
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,492
    lancee,
    You should start your own thread on this matter!
    Do NOT hijack somene else's thread.
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  6. #6
    Join Date
    Aug 2009
    Posts
    5
    Im really sorry. My mistake.. I thought this will make a new post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width