Pages

Saturday, January 31, 2009

Parameter naming problem in oracle function & Procedure..

                  Oracle Procedure and Functions are very much effective, developing N-tier application. Both of them can take parameter and function can return a value and procedure cant return. Here I got some problem with the naming system of parameters of functions & procedures.

                   Suppose the function has a parameter named employee_ID and you are working on a table where a column name is also employee_ID. And now suppose you have a query like this in your function.

select employee_name from employee_table where employee_id = employee_id;


Your intension may be to compare the column of the table to the parameter. Ok lets make it more clear to Oracle. Suppose your query is like the following now

select employee_name from employee_table et where et.employee_id = employee_id;


Still no way. You may be expecting only one row but you will get all the rows of your table. this query in fact will work just like following

select employee_name from employee_table et where et.employee_id = et.employee_id;




So here it is clear why you will get all the rows.

So what I want to say here is, It is always safe to use different name for parameters like param_employee_id so that oracle cant be confused with other names used in your tables. 

 

1 comment:

  1. Table alias use korle MySQL column name ar parameter name differentiate korte pare. Using some prefix "param" or so is a good practice

    ReplyDelete