Вы находитесь на странице: 1из 3

INSERT INTO EMPLOYEE values (1,'John','Peter','M',28,'2010-04-14','Abc

street',NULL);
INSERT INTO EMPLOYEE values (2,'Kevin','Calc','M',38,'2019-10-24','Xyz',1);
INSERT INTO EMPLOYEE values (3,'Emly','Sam','F',35,'2017-01-18','Bangalore',1);
INSERT INTO EMPLOYEE values (4,'Sophia','Michael','F',24,'2010-03-24','Mysore',2);
INSERT INTO EMPLOYEE values (5,'William','Edvin','M',58,'2004-04-09','Xyz',1);
INSERT INTO EMPLOYEE values (6,'Jonh','Michel','M',45,'2017-01-18','Bangalore',2);
INSERT INTO EMPLOYEE values (7,'Agila','Jorge','F',32,'2010-04-14','Mysore',3);
INSERT INTO EMPLOYEE values (8,'Anna','Peter','F',28,'2000-10-03','Chennai',3);
INSERT INTO EMPLOYEE values (9,'John','Samual','M',44,'2011-12-11','Xyz',1);
INSERT INTO EMPLOYEE values (10,'Josh','Kathrin','M',51,'2017-05-22','Abc
street',2);
INSERT INTO EMPLOYEE values (11,'Ria','Pop','M',27,'2015-02-13','Abc street',1);
INSERT INTO EMPLOYEE values (12,'Jessy','William','F',24,'2010-04-
14','Bangalore',3);
INSERT INTO EMPLOYEE values (13,'Alan','Sam','M',55,'2019-10-24','Abc street',2);
INSERT INTO EMPLOYEE values (14,'Kelly','Calc','M',36,'2010-04-14','Bangalore',6);
INSERT INTO EMPLOYEE values (15,'Rahel','Emman','M',48,'2019-10-24','Chennai',1);

INSERT INTO EMP_SAL values (1,'US',20000);


INSERT INTO EMP_SAL values (2,'DE',7899);
INSERT INTO EMP_SAL values (3,'US',75000);
INSERT INTO EMP_SAL values (4,'IN',50000);
INSERT INTO EMP_SAL values (5,'US',45000);
INSERT INTO EMP_SAL values (6,'DE',9000);
INSERT INTO EMP_SAL values (7,'IN',50000);
INSERT INTO EMP_SAL values (8,'DE',38000);
INSERT INTO EMP_SALvalues (9,'IN',NULL);
INSERT INTO EMP_SAL values (10,NULL,NULL);
INSERT INTO EMP_SALvalues (11,'US',85000);
INSERT INTO EMP_SAL values (12,'DE',9000);
INSERT INTO EMP_SAL values (13,'IN',40000);
INSERT INTO EMP_SAL values (14,'US',75000);
INSERT INTO EMP_SAL values (15,'IN',35000);

create type "TT_VEHICLE1" as Table


(
veh_id INTEGER ,
veh_name VARCHAR(25)
);

create procedure TT_PROCEDURE1 ( OUT OUTPUT_TABLE TT_VEHICLE1 )


as begin
OUTPUT_TABLE = Select VEH_ID,VEH_NAME
from vehicle;
END;

CALL TT_PROCEDURE1(?);

-------------------------------------------

create procedure test_Sal()


as
BEGIN

DECLARE tot_sal integer;

SELECT SUM(salary) INTO tot_Sal FROM emp_sal WHERE country = 'US';


SELECT :tot_Sal FROM DUMMY;

END;

call test_sal;

--------------------------------------

create function extra_sal(im_sal integer, im_hike integer)


returns new_sal integer
language sqlscript
sql security invoker
as
begin
new_sal := :im_sal + :im_sal * (:im_hike / 100);
end;

create function tax_cal(im_new_sal integer, im_tax_per integer)


returns tax_new_sal integer
language sqlscript
sql security invoker
as
begin
tax_new_sal = im_new_sal - im_new_sal*(im_tax_per/100);
end;

select empid, tax_cal(extra_sal(salary, 45),20) as last_salary from emp_sal;

----------------------------------------------------------------------

create function get_emp_sal(im_country nvarchar(2))


returns table (empid integer,name nvarchar(30),managerid integer,salary integer)
language sqlscript
sql security invoker as
begin
return select emp.empid, concat(fname,lname) as name, managerid,salary
from employee as emp
inner join emp_sal as sal
on emp.empid = sal.empid
where country = :im_country;

end;

select * from get_emp_sal('US');

----------------------------------------------------------------------
create type tt_sal100 as table ( empid integer,country nvarchar(2),salary
integer );
create function get_emp_sal1(im_country nvarchar(2))
returns tt_sal100
as begin
return select * from emp_sal where country = :im_country;

end;

select * from get_emp_sal1('US');

select * from emp_sal where country = 'US';


--------------------------------------------------------------------------
CREATE PROCEDURE get_emp_by_filter(

IN im_filter_string VARCHAR(50),

out ex_emp employee )

LANGUAGE SQLSCRIPT

SQL SECURITY INVOKER

READS SQL DATA AS

BEGIN

ex_emp = APPLY_FILTER(employee, :im_filter_string) ;

END;

call get_emp_by_filter(im_filter_string => '"FNAME" LIKE ''%a%''', EX_EMP => ?);


call get_emp_by_filter(im_filter_string => '"LNAME" LIKE ''%a%''', EX_EMP => ?);

-------------------------------------------------------------------

create procedure insert_emps(in empid integer,in country nvarchar(2),in salary


integer, out message nvarchar(100))
as begin
declare exit handler
for sqlexception
select ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE from dummy;

insert into emp_sal values(:empid,:country,:salary);


message := 'Emp' || :empid || 'Salary inserted';
end;

CALL INSERT_EMPS(39,'JP',4500,?);

SELECT * FROM EMPLOYEE;

---------------------------------------------------------------------

create procedure select_insert( )


as begin
declare tt_tab employee;
tt_tab = select * from employee ;
insert into emp200 select * from :tt_tab;
end;

call select_insert();