Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Qualifying column names and variable names

Re: Qualifying column names and variable names

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Mon, 11 May 1998 10:44:54 GMT
Message-ID: <3557d608.13504137@192.86.155.100>


A copy of this was sent to gennick_at_worldnet.att.net (Jonathan Gennick) (if that email address didn't require changing) On Mon, 11 May 1998 03:40:06 GMT, you wrote:

>I have the following table:
>
>SQL> describe employee;
> Name Null? Type
> ------------------------------- -------- ----
> EMPLOYEE_ID NOT NULL NUMBER
[snip]

>
>I write the following PL/SQL block:
><<block_label>>
>DECLARE
> employee_id number := 110;
>BEGIN
> FOR my_employee IN (
> SELECT *
> FROM employee
> WHERE employee_id = block_label.employee_id
> ) LOOP

[snip]
>
>How can I qualify the second reference to "employee_id" in
>the where clause of the SELECT statement so that it refers
>to the employee_id that I have declared in my block? As it
>stands now, "WHERE employee_id = employee_id" looks only at
>the values in each record. I know that I can label the
>block, and then write:
>
> WHERE employee_id = block_label.employee_id
>
>Is there an alternative way, or must I label the block?
>
>

You must label the block as you have discovered. I myself prefer to use a naming convention for pl/sql variables. Parameters passed to a routine start with p_, local variables in a procedure or block start with l_, global variables in package bodies/specs start with g_. that way, it is easier to tell the difference between variables and database columns. You will forget to name the block or qualify a reference some day... Using the naming convention helps to avoid that.  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Mon May 11 1998 - 05:44:54 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US