Skip to content
Advertisement

SQL Oracle: Save variable from select with where statement

i’m using SQL Developer 19.1. I have a huge script with multiple subselect statements. It looks like this

i want to get var1 and var2 with a another select statements. How do i do that? i tried

but it seems like i cant use a where statement there. i also tried something with bind or @var1..

Do you guys have any idea what i could try next?

My goal is something like

Advertisement

Answer

If you want to keep using substitution variables you could use the column ... new_value functionality (the documentation is for SQL*Plus but mostly applies to SQL Developer; and focuses on using this for report titles but it’s more useful than that suggests):

Trivial example to show this in action; if the worksheet has:

then the script output pane shows:

Or you could use bind variables:

Notice that the references to var1 and var2 are now preceded by a colon to indicate a bind variable, rather than an ampersand to indicate a substitution variable; and that colon appear in the into :var1 part as well – that is still referring to the bind variable, not to a local PL/SQL variable.

Trivial example again; worksheet script:

gets output:

You can use print var1 if you want to see the value that was assigned by the anonymous PL/SQL block.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement