dbTalk Databases Forums  

pl/sql forcing RHS of = in where clause to be variable?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss pl/sql forcing RHS of = in where clause to be variable? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mh@pixar.com
 
Posts: n/a

Default pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 03:59 PM






This code will compare a column to a variable:

declare myx number;
begin
select * from foo where x=myx;
end;

but suppose I have a variable with the same name as a column:

declare x number;
begin
select * from foo where x=x;
end;

This will compare column x with column x, and not with the
variable x, right? Is there syntax to force the rightmost
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 04:25 PM






mh (AT) pixar (DOT) com schrieb:
Quote:
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.
I don't think, you have too many choices.

Best regards

Maxim


Reply With Quote
  #3  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 04:25 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.
I don't think, you have too many choices.

Best regards

Maxim


Reply With Quote
  #4  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 04:25 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.
I don't think, you have too many choices.

Best regards

Maxim


Reply With Quote
  #5  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 04:25 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.
I don't think, you have too many choices.

Best regards

Maxim


Reply With Quote
  #6  
Old   
Urs Metzger
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 05:07 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
This code will compare a column to a variable:

declare myx number;
begin
select * from foo where x=myx;
end;

but suppose I have a variable with the same name as a column:

declare x number;
begin
select * from foo where x=x;
end;

This will compare column x with column x, and not with the
variable x, right? Is there syntax to force the rightmost
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.

Many TIA!
Mark

Use a block with a label:

SQL> create table t(x number);

Table created.

SQL> insert into t values(42);

1 row created.

SQL> set serverout on
SQL> declare
2 x number;
3 d number;
4 begin
5 select * into d from t where x = x;
6 dbms_output.put_line('d = ' || to_char(d));
7 end;
8 /
d = 42

PL/SQL procedure successfully completed.

SQL> begin
2 <<my_label>>
3 declare
4 x number := 5;
5 d number;
6 begin
7 select * into d from t where x = my_label.x;
8 dbms_output.put_line('d = ' || to_char(d));
9 end;
10 end my_label;
11 /
begin
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 7

hth,
Urs Metzger


Reply With Quote
  #7  
Old   
Urs Metzger
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 05:07 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
This code will compare a column to a variable:

declare myx number;
begin
select * from foo where x=myx;
end;

but suppose I have a variable with the same name as a column:

declare x number;
begin
select * from foo where x=x;
end;

This will compare column x with column x, and not with the
variable x, right? Is there syntax to force the rightmost
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.

Many TIA!
Mark

Use a block with a label:

SQL> create table t(x number);

Table created.

SQL> insert into t values(42);

1 row created.

SQL> set serverout on
SQL> declare
2 x number;
3 d number;
4 begin
5 select * into d from t where x = x;
6 dbms_output.put_line('d = ' || to_char(d));
7 end;
8 /
d = 42

PL/SQL procedure successfully completed.

SQL> begin
2 <<my_label>>
3 declare
4 x number := 5;
5 d number;
6 begin
7 select * into d from t where x = my_label.x;
8 dbms_output.put_line('d = ' || to_char(d));
9 end;
10 end my_label;
11 /
begin
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 7

hth,
Urs Metzger


Reply With Quote
  #8  
Old   
Urs Metzger
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 05:07 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
This code will compare a column to a variable:

declare myx number;
begin
select * from foo where x=myx;
end;

but suppose I have a variable with the same name as a column:

declare x number;
begin
select * from foo where x=x;
end;

This will compare column x with column x, and not with the
variable x, right? Is there syntax to force the rightmost
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.

Many TIA!
Mark

Use a block with a label:

SQL> create table t(x number);

Table created.

SQL> insert into t values(42);

1 row created.

SQL> set serverout on
SQL> declare
2 x number;
3 d number;
4 begin
5 select * into d from t where x = x;
6 dbms_output.put_line('d = ' || to_char(d));
7 end;
8 /
d = 42

PL/SQL procedure successfully completed.

SQL> begin
2 <<my_label>>
3 declare
4 x number := 5;
5 d number;
6 begin
7 select * into d from t where x = my_label.x;
8 dbms_output.put_line('d = ' || to_char(d));
9 end;
10 end my_label;
11 /
begin
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 7

hth,
Urs Metzger


Reply With Quote
  #9  
Old   
Urs Metzger
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 05:07 PM



mh (AT) pixar (DOT) com schrieb:
Quote:
This code will compare a column to a variable:

declare myx number;
begin
select * from foo where x=myx;
end;

but suppose I have a variable with the same name as a column:

declare x number;
begin
select * from foo where x=x;
end;

This will compare column x with column x, and not with the
variable x, right? Is there syntax to force the rightmost
x to be a variable? Or should I do

myx := x;
select * from foo where x=myx;

This is in the context of a parameter name of a public
function, so I don't want to do the obvious choice
of renaming the variable.

Many TIA!
Mark

Use a block with a label:

SQL> create table t(x number);

Table created.

SQL> insert into t values(42);

1 row created.

SQL> set serverout on
SQL> declare
2 x number;
3 d number;
4 begin
5 select * into d from t where x = x;
6 dbms_output.put_line('d = ' || to_char(d));
7 end;
8 /
d = 42

PL/SQL procedure successfully completed.

SQL> begin
2 <<my_label>>
3 declare
4 x number := 5;
5 d number;
6 begin
7 select * into d from t where x = my_label.x;
8 dbms_output.put_line('d = ' || to_char(d));
9 end;
10 end my_label;
11 /
begin
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 7

hth,
Urs Metzger


Reply With Quote
  #10  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: pl/sql forcing RHS of = in where clause to be variable? - 07-01-2008 , 05:11 PM



Urs Metzger schrieb:
Quote:
mh (AT) pixar (DOT) com schrieb:
Use a block with a label:
Urs Metzger
This could do the job for regular plsql variables, but if the actual one
is a function parameter, i think, you *have* to reassign.

Best regards

Maxim


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.