dbTalk Databases Forums  

equal names of: parameter of procedure - columns of table

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


Discuss equal names of: parameter of procedure - columns of table in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Werner Hofmann
 
Posts: n/a

Default equal names of: parameter of procedure - columns of table - 05-23-2005 , 04:43 AM






Hallo,

is there an way, to make a difference between the parameter of a
procedure and the column name of a table if the name is equal?

in firebird it is no problem, because in a sql statement I have to use
colon in from of a variable for example:

select * from machines m where m.age > :age

when I write in Oracle
select * from machines m where m.age > age

then this is not doing what I want.
I would be lucky if I don't need to rename my variable names and there
is another way to get what I want.

Thank you,
Werner Hofmann

Reply With Quote
  #2  
Old   
andrewst@onetel.com
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-23-2005 , 05:52 AM






Werner Hofmann wrote:
Quote:
Hallo,

is there an way, to make a difference between the parameter of a
procedure and the column name of a table if the name is equal?
You can do this:

procedure my proc (age in number) is
begin
select * from machines m where m.age > myproc.age;
....



Reply With Quote
  #3  
Old   
Sybrand Bakker
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-23-2005 , 07:38 AM



On Mon, 23 May 2005 11:43:13 +0200, Werner Hofmann
<superomega (AT) t-online (DOT) de> wrote:

Quote:
then this is not doing what I want.
I would be lucky if I don't need to rename my variable names and there
is another way to get what I want.
There is not. Obviously, the error starts with assuming there is.




--
Sybrand Bakker, Senior Oracle DBA


Reply With Quote
  #4  
Old   
andrewst@onetel.com
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-23-2005 , 09:07 AM



Sybrand Bakker wrote:
Quote:
I would be lucky if I don't need to rename my variable names and
there
is another way to get what I want.

There is not. Obviously, the error starts with assuming there is.
Except that there is. Here's a working example:

SQL> create or replace function get_name (empno in number)
2 return varchar2
3 is
4 ename emp.ename%type;
5 begin
6 select emp.ename into get_name.ename
7 from emp
8 where emp.empno = get_name.empno;
9 return get_name.ename;
10 end;
11 /

Function created.

SQL> select get_name(7900) from dual;

GET_NAME(7900)
--------------------------------------------------------------------------------
JAMES

**NOT** that I am advocating doing this if it is avoidable. The scope
for error is much greater than if a different naming convention is used
for parameters.



Reply With Quote
  #5  
Old   
Sybrand Bakker
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-23-2005 , 11:55 AM



On 23 May 2005 07:07:17 -0700, andrewst (AT) onetel (DOT) com wrote:

Quote:
Except that there is. Here's a working example:
In the OP's case, it would still mean, he would need to change
everything, wouldn't he?
So what is the difference in that case between doing this properly,
and implementing this hack?


--
Sybrand Bakker, Senior Oracle DBA


Reply With Quote
  #6  
Old   
andrewst@onetel.com
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-23-2005 , 04:47 PM



Sybrand Bakker wrote:
Quote:
On 23 May 2005 07:07:17 -0700, andrewst (AT) onetel (DOT) com wrote:

Except that there is. Here's a working example:

In the OP's case, it would still mean, he would need to change
everything, wouldn't he?
So what is the difference in that case between doing this properly,
and implementing this hack?
1) I already said I wouldn't advocate this approach if it could be
avoided.

2) There is nothing "improper" or "hack"-like about using a feature
simply because you apparently didn't know about it.

3) The difference would be if he already has published package specs
that use parameters with such names, and referenced them in code. This
approach will allow him to change only the internals of the package
body.



Reply With Quote
  #7  
Old   
Werner Hofmann
 
Posts: n/a

Default Re: equal names of: parameter of procedure - columns of table - 05-24-2005 , 02:37 AM



andrewst (AT) onetel (DOT) com wrote:
Quote:
Werner Hofmann wrote:

Hallo,

is there an way, to make a difference between the parameter of a
procedure and the column name of a table if the name is equal?


You can do this:

procedure my proc (age in number) is
begin
select * from machines m where m.age > myproc.age;
...

Thank you it's working


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.