This function have an input and an output parameter. But he won't return

It's function. Pls check in Scott & Tiger database.

CREATE OR REPLACE Function SamFunc
(EmpNo IN Varchar2)
Return of tank is
Val Varchar (500);
Begin

Start
Select Ename Into Val From Emp
Where EmpNo = EmpNo; -: 7369.
And DeptNo = '20';   : Deptno
Return Val;
Exception
When No_Data_Found then
Val: = NULL;
While others then
Val: = NULL;
end;

Return Val;
End;

Someone help me
Where EmpNo = EmpNo;

Oracle will assume you want that each line, because empno will always be equal to empno.
Do not use a parameter with the same name as a column or use a namespace

Where emp.EmpNo = SamFunc.EmpNo;

And you hide the TOO_MANY_ROWS error with your

When Others Then
Val := NULL;

You will never see an error.

If you want to hide a NO_DATA_FOUND then you can write

When No_Data_Found Then
RETURN NULL;

But never use a WHEN OTHERS THEN NULL;

Concerning
Marcus

Edited by: Marwim the 04.10.2010 13:38

Tags: Database

Similar Questions

Maybe you are looking for