In my function below I am trying to understand why it only returns BLAH if I pass in 01356666 and then a null value for anything else passed in. My expectation was that it would return BLAH regardless of what was passed in since I reset the str_mgrin_out after I do the SELECT INTO. I have been testing this in Oracle 10g.
CREATE OR REPLACE FUNCTION GET_MANAGERGIN2 (str_empgin_in IN varchar2)
RETURN varchar2
AS
str_mgrgin_out varchar2(10);
BEGIN
SELECT 'FOO' INTO str_mgrgin_out FROM dual WHERE str_empgin_in = '01356666';
str_mgrgin_out := 'BLAH';
RETURN str_mgrgin_out;
END GET_MANAGERGIN2;
/
-- Returns null but expecting BLAH
SELECT GET_MANAGERGIN2('00356666') FROM dual;
-- Returns BLAH
SELECT GET_MANAGERGIN2('01356666') FROM dual;
I’d assume that this is because if the
SELECT INTOdoesn’t return exactly one value intostr_mgrgin_outit’ll throw an exception, so thestr_mgrgin_out := 'BLAH';line never gets executed.I think the error would be
ORA-01403.Try adding an exception handler at the end as:
You might have to surround it with a
BEGIN...ENDas well so it would be: