Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Variables in SELECT statement

MrGibbageFeb 19 2013 — edited Feb 19 2013
I was given a SQL query to help me develop another query that will need to do something similar. The query I was given I believe is a stored procedure. It is PL/SQL and has a SELECT statement that looks like
SELECT :var1 AS var1
FROM t1
WHERE
:var1 = 1
In the past I have seen where variables can be used in the WHERE clause like
SELECT c1 
FROM t1
WHERE
c1 = :my_column_value
and this makes sense to me. Usually :my_column_value is declared in the DECLARE block of the PL/SQL. In the query I was given, :my_column_value is not declared in any DECLARE blocks (maybe I wasn't given the entire code??). But even if it was, that would be even more confusing because in the DECLARE block it could be assigned one value and then set to another value in the WHERE clause???

The first query doesn't make sense to me and when I run it as plain SQL I get an error like "SP2-0552: Bind variable "var1" not declared. I am guessing that such a syntax is not valid for regular SQL?

The only thing I can gather that the first query does is something along the lines of

SELECT 1 as var1

so it will output a 1 for every row. Not always that interesting of a query, but it is needed sometimes, I know. But I still don't understand this type of assignment.

So what's going on here? I'd be happy to look it up and read about it myself, but I don't know what to search for. Hopefully someone here can point me in the right direction. Thanks :)

Comments

807591
does the program not print "executing cmd" ?
ok, first, what do you think should happen, and second, what is happening really?

you arent doing anything with the input and output streams of your program.. so i dont know what you expect
807591
I should have been thinking about it a little bit longer. After I added a
waitFor()
and redirected the output as it is described in the article I posted the link to, everything worked as it should.
1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 19 2013
Added on Feb 19 2013
5 comments
4,197 views