| |
|
Write the syntax to create a Function in SQL
Below is the syntax to create a Function in SQL:
Create [or Replace] Function [Schema.]FunctionName
(argument [in|out] datatype])
return datatype
is
[variables if any]
begin
[Statements...];
return [return value];
end;
See example below:
Create or Replace IsEligibleToVote(InputAge in number )
return varchar2
is
v_name t_citizen.varchar2%type;
v_age t_citizen.varchar2%type;
v_eligible varchar2 = 'no';
begin
if(InputAge > 18) then
v_name = &&inp1;
v_age = &&inp2;
insert into t_citizen values (v_name, v_age) ;
v_eligible='yes';
end if;
return v_eligible;
end;
SQL Queries
SQL
Create Table
DDL, Create, Alter, Drop commands
DML, Select, Insert, Update, Delete
Create Database
ACID Rules
Dual Table
NULL
Join, Inner, Outer, Left, Right, Full, Cartesian, Natural, Equi
Table, View and a Synonym?
Execute
Function
Stored Procedure
Syntax Stored Proc
Stored Procedure Vs. Function
| |