Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: how can i exeucte stored function in sqlplus program.
> > I made PL/SQL code like below and stored oracle.
> >
> > $ cat func.sql
> > create function emp_insert ( my_empno in emp.empno%type, my_ename in
> > emp.ename%type ) return boolean as
> > begin
> > insert into emp( empno, ename ) values( my_empno, my_ename );
> > return true;
> > exception
> > when others then
> > return false;
> > end;
> > /
> >
> >
> > --------------------------------------------------------------------------
> --
> --
> ignored.
You can call function in a sql statement as,
select emp_insert( 200, 'you' ) from dual;
*BUT* in your case it will not work as you are returning a BOOLEAN. If you change return type to NUMBER/VARCHAR2 and return 1/'TRUE' and 0/'FALSE' then you can use the above statement.
The other way would be to leave it the way it is and use PLSQL block,
SET SERVEROUT ON
DECLARE
return_ BOOLEAN;
BEGIN
return_ := emp_insert ( 200, 'you' );
IF (return_) THEN
DBMS_OUTPUT.PUT_LINE('TRUE');
ELSE
DBMS_OUTPUT.PUT_LINE('FALSE');
END IF;
END;
/
Received on Mon Jul 22 2002 - 16:57:39 CDT
![]() |
![]() |