Beruflich Dokumente
Kultur Dokumente
a number:=104;
b varchar2(30);
begin
select last_name into b from employees where employee_id=a;
dbms_output.put_line('Employee Name Is:' || b);
end;
declare
a number:=104;
b employees.last_name%type;
c b%type;
begin
select last_name,job_id into b,c from employees
where employee_id=a;
dbms_output.put_line('Employee Name is:' ||chr(9)|| b ||chr(10) || 'His Desg is:'
||chr(9)||c);
end;
declare
a number:=105;
b employees%rowtype;
begin
select * into b from employees where employee_id=a;
dbms_output.put_line(b.first_name||chr(9)||b.last_name||chr(9)||b.job_id||chr(9)||
b.salary);
end;
declare
a number:=104;
begin
select last_name,job_id into :name,:job from employees
where employee_id=a;
end;
print or
select employee_id,last_name,salary,job_id from employees
where job_id=:job;
declare
a number:=105;
b employees%rowtype;
begin
select * into b from employees where employee_id=a;
dbms_output.put_line(b.first_name||chr(9)||b.last_name||chr(9)||b.job_id||chr(9)||
b.salary);
end;
declare
a number:=345;
b number:=2000;
begin
update employees set salary=salary+b where employee_id=a;
dbms_output.put_line(sql%rowcount|| ' rows updated');
end;
declare
a number;
b number;
begin
a:=10;
b:=20;
if a>b then
dbms_output.put_line(b || 'is greater than a');
else
dbms_output.put_line(a || 'is greater than b');
end if;
end;
DECLARE
grade CHAR(1) := UPPER('&grade');
appraisal VARCHAR2(20);
BEGIN
appraisal :=
CASE
WHEN grade = 'A' THEN 'Excellent'
WHEN grade IN ('B','C') THEN 'Good'
ELSE 'No such grade'
END;
DBMS_OUTPUT.PUT_LINE ('Grade: '|| grade || ' Appraisal ' || appraisal);
END;
SET SERVEROUTPUT ON
DECLARE
deptid NUMBER;
deptname VARCHAR2(20);
emps NUMBER;
mngid NUMBER:= 108;
BEGIN
CASE mngid
WHEN 108 THEN
SELECT department_id, department_name INTO deptid, deptname
FROM departments WHERE manager_id=108;
SELECT count(*) INTO emps FROM employees WHERE
department_id=deptid;
WHEN 200 THEN
SELECT department_id, department_name INTO deptid, deptname
FROM departments WHERE manager_id=200;
SELECT count(*) INTO emps FROM employees WHERE
department_id=deptid;
WHEN 121 THEN
SELECT department_id, department_name INTO deptid, deptname
FROM departments WHERE manager_id=121;
SELECT count(*) INTO emps FROM employees WHERE
department_id=deptid;
END CASE;
DBMS_OUTPUT.PUT_LINE ('You are working in the '|| deptname||' department. There are
'||emps ||' employees in this department');
END;
declare
a number:=0;
begin
loop
a:=a+1;
exit when a>10;
dbms_output.put_line(a);
end loop;
end;
declare
a number:=0;
begin
while a<10 loop
a:=a+1;
dbms_output.put_line(a);
end loop;
end;
begin
for a in 1..10
loop
dbms_output.put_line(a);
end loop;
end;
declare
a number;
b varchar2(200);
begin
select count(*) into a from employees;
for i in 1..a loop
select employee_id||' '||last_name||' '||salary||' '||job_id into b from(select
e.*,rownum x from employees e) where x=i;
dbms_output.put_line(b);
end loop;
end;
DECLARE
type t_rec is record
(v_sal number(8),
v_minsal number(8) default 1000,
v_hire_date employees.hire_date%type,
v_rec1 employees%rowtype);
v_myrec t_rec;
BEGIN
v_myrec.v_sal := v_myrec.v_minsal + 500;
v_myrec.v_hire_date := sysdate;
SELECT * INTO v_myrec.v_rec1
FROM employees WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE(v_myrec.v_rec1.last_name ||' '||
to_char(v_myrec.v_hire_date) ||' '|| to_char(v_myrec.v_sal));
END;
DECLARE
TYPE emp_table_type is table of
employees%ROWTYPE INDEX BY PLS_INTEGER;
my_emp_table emp_table_type;
max_count NUMBER(3):= 206;
BEGIN
FOR i IN 100..max_count
LOOP
SELECT * INTO my_emp_table(i) FROM employees
WHERE employee_id = i;
END LOOP;
FOR i IN my_emp_table.FIRST..my_emp_table.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(my_emp_table(i).last_name||chr(9)||
my_emp_table(i).job_id);
END LOOP;
END;
DECLARE
TYPE emp_table_type is table of
employees%ROWTYPE INDEX BY PLS_INTEGER;
my_emp_table emp_table_type;
BEGIN
SELECT * bulk collect INTO my_emp_table FROM employees;
FOR i IN my_emp_table.FIRST..my_emp_table.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(my_emp_table(i).last_name||chr(9)||
my_emp_table(i).job_id);
END LOOP;
END;
DECLARE
TYPE emp_table_type is table of
employees%ROWTYPE INDEX BY PLS_INTEGER;
my_emp_table emp_table_type;
BEGIN
SELECT * bulk collect INTO my_emp_table FROM employees;
FOR i IN my_emp_table.FIRST..my_emp_table.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(my_emp_table(i).last_name||chr(9)||
my_emp_table(i).job_id);
END LOOP;
END;
DECLARE
TYPE emp_table_type is table of
employees%ROWTYPE INDEX BY PLS_INTEGER;
my_emp_table emp_table_type;
BEGIN
SELECT * bulk collect INTO my_emp_table FROM employees;
DBMS_OUTPUT.PUT_LINE(my_emp_table(25).employee_id||chr(9)||
my_emp_table(25).last_name||chr(9)||my_emp_table(25).job_id);
END;
declare
CURSOR C1 is select employee_id,job_id,salary from emp_cur;
e c1%rowtype;
begin
open c1;
loop
fetch c1 into e;
exit when c1%notfound;
if e.job_id='IT_PROG' then
update emp_cur set salary=salary+1000 where employee_id=e.employee_id;
elsif e.job_id='SA_MAN' then
update emp_cur set salary=salary+1500 where employee_id=e.employee_id;
elsif e.job_id='ST_MAN' then
update emp_cur set salary=salary+1800 where employee_id=e.employee_id;
else
update emp_cur set salary=salary+2000 where employee_id=e.employee_id;
end if;
end loop;
close c1;
end;
declare
cursor c1 is select employee_id,last_name,salary from emp_cur;
e c1%rowtype;
begin
open c1;
fetch c1 into e;
while c1%found loop
dbms_output.put_line(e.employee_id||chr(9)||e.salary||chr(9)||e.last_name);
fetch c1 into e;
end loop;
close c1;
end;
declare
cursor c1 is select employee_id,last_name,salary from emp_cur;
begin
for e in c1 loop
dbms_output.put_line(e.employee_id||chr(9)||e.salary||chr(9)||e.last_name);
end loop;
end;
declare
cursor c1 is select * from departments;
cursor c2(dno number) is select * from employees where department_id=dno;
begin
for i in c1 loop
dbms_output.put_line(i.department_id||chr(9)||i.department_name||chr(9)||
i.location_id);
for j in c2(i.department_id) loop
dbms_output.put_line(j.employee_id||chr(9)||j.last_name||chr(9)||j.job_id);
end loop;
end loop;
end;
declare
cursor c1 is select employee_id,job_id,salary from emp_cur for update ;
e c1%rowtype;
begin
open c1;
loop
fetch c1 into e;
exit when c1%rowcount>108;
if e.job_id='IT_PROG' then
update emp_cur set salary=salary+925 where current of c1;
elsif e.job_id='SA_MAN' then
update emp_cur set salary=salary+1025 where current of c1;
elsif e.job_id='ST_MAN' then
update emp_cur set salary=salary+1525 where current of c1;
else
update emp_cur set salary=salary+2025 where current of c1;
end if;
end loop;
commit;
end;
DECLARE
v_lname VARCHAR2(15);
BEGIN
SELECT last_name INTO v_lname FROM employees WHERE
first_name='John';
DBMS_OUTPUT.PUT_LINE ('John''s last name is : ' ||v_lname);
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Your select statement retrieved multiple
rows. Consider using a cursor.');
END;
/
declare
a number:=50;
del_child exception;
pragma exception_init(del_child,-02292);
begin
delete from departments where department_id=a;
dbms_output.put_line(sql%rowcount||' '||' rows deleted ');
exception
when del_child then
dbms_output.put_line('Before deleting this record remove dependent records from
employees table');
end;
declare
a number:=567;
No_val exception;
begin
update employees set salary=salary+1000 where employee_id=a;
if sql%notfound then
raise no_val;
else
dbms_output.put_line(sql%rowcount|| ' rows updated ');
end if;
exception
when no_val then
dbms_output.put_line('Enter Valid Employee Number');
end;
declare
a number:=567;
begin
update employees set salary=salary+1000 where employee_id=a;
if sql%notfound then
raise_application_error(-20123,'Invalid Employee Number');
else
dbms_output.put_line(sql%rowcount|| ' rows updated ');
end if;
end;
IN APEX :
BEGIN
AR_PRO1;
END;
IN SQL*PLUS
EXEC AR_PRO1
In SQL * PLUS
VAR A VARCHAR2(50)
VAR B VARCHAR2(100)
VAR C NUMBER
EXEC AR_PRO3(123,:A,:B,:C)
DECLARE
A NUMBER:=206;
B VARCHAR2(50);
C VARCHAR2(100);
D NUMBER;
BEGIN
AR_PRO4(A,B,C,D);
END;
IN SQL * PLUS
VAR N NUMBER
VAR A VARCHAR2(50)
VAR B VARCHAR2(100)
VAR C NUMBER
BEGIN
:N:=205;
END;
/
EXEC AR_PRO3(:N,:A,:B,:C)
BEGIN
INSERT INTO departments (department_id, department_name, location_id)
VALUES (departments_seq.NEXTVAL, p_name, p_loc);
END add_dept;
EXECUTE add_dept
EXECUTE add_dept ('ADVERTISING', p_loc => 1200)
EXECUTE add_dept (p_loc => 1200)
exec dbms_output.put_line(ar_fun(2633,33,'/'))
var n number
exec :n:=ar_fun(4646,474,'-')
print n
declare
a number:=366;
b number:=3636;
c varchar2(1):='+';
d number;
begin
ar_fun(a,b,c,d);
dbms_output.put_line(d);
end;
declare
a number:=9;
b number;
begin
b:=ar_fun1(a);
dbms_output.put_line(b);
end;
declare
a hr.ar_pack1.emp_typ;
begin
select * bulk collect into a from employees;
for i in a.first..a.last loop
dbms_output.put_line(a(i).last_name);
end loop;
end;
declare
a number;
cursor c1 is select table_name from user_tables;
begin
for i in c1 loop
execute immediate ' select count(*) from ' ||i.table_name into a;
dbms_output.put_line(i.table_name|| chr(9) || a);
end loop;
end;
END;
create or replace trigger ar_trig instead of insert on ar_vu for each row
begin
insert into departments(department_id,department_name,location_id) values
(:new.dno,:new.department_name,:new.location_id);
insert into employees(employee_id,last_name,job_id,hire_date,email,department_id)
values
(:new.employee_id,:new.last_name,:new.job_id,:new.hire_date,:new.email,:new.edno);
end;