17.6 ColumnFunction Name Precedence

Chapter 17
Calling PL/SQL Functions in SQL
 

17.6 Column/Function Name Precedence

If your function has the same name as a table column in your SELECT statement and it has no parameters, then the column takes precedence over the function.

The employee table has a column named "salary." Suppose you create a function named salary as well:

CREATE TABLE employee (employee_id NUMBER, ... , salary NUMBER, ...); FUNCTION salary RETURN NUMBER;

Then a SELECT statement referencing salary always refers to the column and not the function:

SELECT salary INTO calculated_salary FROM employee;

If you want to override the column precedence, you must qualify the name of the function with the name of the schema that owns the function, as follows:

SELECT scott.salary INTO calculated_salary FROM employee;

This now executes the function instead of retrieving the column value.


17.5 Calling Packaged Functions in SQL17.7 Realities: Calling PL/SQL Functions in SQL

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.



Oracle PL/SQL Programming
Oracle PL/SQL Programming: Covers Versions Through Oracle Database 11g Release 2 (Animal Guide)
ISBN: 0596514468
EAN: 2147483647
Year: 2004
Pages: 234
Authors: Steven Feuerstein, Bill Pribyl
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net