Toad World® Forums

Execute second select sql set based on first select SQL result

I have two SQL select statements, need to run the second select statements based on the first select gives results. If not, not do anything. I have only read access to production. I tried doing this in PL/SQL with create procedure statement in Toad but that gave me I do not have access. How can this be done with simple sql and parameters. I need to execute both select sql statements at the same time based on the condition I mentioned. Please provide snippet if possible. Thanks in advance.

Just a idea, but could you use an anonymous block for this?

Not 100% sure if this handles if statements but I’m pretty sure it does.

And I’m guessing it will run on read only permissions

Alan

On 22 Aug 2013, at 23:47, “PrimeMinister2050” bounce-PrimeMinister2050@toadworld.com wrote:

Execute second select sql set based on first select SQL result

Thread created by PrimeMinister2050
I have two SQL select statements, need to run the second select statements based on the first select gives results. If not, not do anything. I have only read access to production. I tried doing this in PL/SQL with create procedure statement in Toad but that gave me I do not have access. How can this be done with simple sql and parameters. I need to execute both select sql statements at the same time based on the condition I mentioned. Please provide snippet if possible. Thanks in advance.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or Unsubscribe from Toad for Oracle - General notifications altogether.

Toad for Oracle - Discussion Forum

Flag this post as spam/abuse.

Afternoon PrimeMinister2050,
Not your real name I presume! :wink:
On 22/08/13 23:47, PrimeMinister2050 wrote:

I have two SQL select statements, need to run the second select
statements based on the first select gives results. If not, not do
anything. I have only read access to production.
So, if I understand correctly, you want to run one statement and if there are any rows returned, run another one. A couple of questions:

  • do you need the results from the first one, or is it just a trigger for the second?
  • does the second one need to extract any values from the results of the first?
    If the answer is NO to both, the it might be possible to run the second with a WHERE EXISTS clause which includes the first.
    For example:
  1. select dummy from dual where dummy = ‘X’;
  2. select "Dummy is X’ from dual;
    So, in order to run the second one, only on a row being returned from the first, we could do this:
    select ‘Dummy is X’ as fred from dual
    where exists (select dummy from dual where dummy = ‘X’)
    Which returns:
    FRED