01-06-2014
01-06-2014
01-06-2014
----------------------declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
dbms_output.put_line('n1 is' || n1 );
dbms_output.put_line('v1 is' || v1 );
end;
-------------------------------set serveroutput on
declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
select ename,sal into v1,n1 from
dbms_output.put_line('n1 is ' ||
dbms_output.put_line('v1 is ' ||
end;
/
-----------------------set serveroutput on
declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
select ename,sal into v1,n1 from
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
end;
/
-- it will ask to user or operator to input the value
----------------------set serveroutput on
declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
select ename,sal into v1,n1 from emp where empno=&empno;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
when no_data_found then
dbms_output.put_line('invalid emp no');
end;
/
-- error handing
----------------------set serveroutput on
declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
--select ename,sal into v1,n1 from emp where empno=&empno;
select ename,sal into v1,n1 from emp where deptno=10;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
when no_data_found then
dbms_output.put_line('invalid emp no');
when too_many_rows then
dbms_output.put_line('multipal rows');
end;
/
-- multipal row error handing
----------------------set serveroutput on
declare
n1 number (6);
v1 varchar(30);
begin
n1:=10;
v1:='Excuting Pl Sql Block';
select ename,sal into n1,v1 from emp where empno=&empno;
--select ename,sal into v1,n1 from emp where deptno=10;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
end;
/
-----------------------set serveroutput on
declare
n1 number (6):=5;
v1 varchar(30);
n2 number(6):=0;
begin
--v1:='Excuting Pl Sql Block';
--n1:=n1/n2;
begin
insert into dept values (10, 'IT','MUM');
--exception
--when dup_val_on_index then
--dbms_output.put_line('-- inner department already exists');
end;
select ename,sal into v1,n1 from emp where empno='&empno';
--select ename,sal into v1,n1 from emp where deptno=10;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
when no_data_found then
dbms_output.put_line('invalid emp no');
when too_many_rows then
dbms_output.put_line('multipal rows');
when value_error or invalid_number then
dbms_output.put_line('Truncation or conversion error');
when zero_divide then
dbms_output.put_line('denominator ca nit be zero');
when dup_val_on_index then
dbms_output.put_line('--outer ');
end;
/
--for the duplicat data
-----------------------------------set serveroutput on
declare
n1 number (6):=5;
v1 varchar(30);
n2 number(6):=0;
begin
--v1:='Excuting Pl Sql Block';
--n1:=n1/n2;
begin
insert into dept values (10, 'IT','MUM');
--exception
--when dup_val_on_index then
--dbms_output.put_line('-- inner department already exists');
end;
select ename,sal into v1,n1 from emp where empno='&empno';
--select ename,sal into v1,n1 from emp where deptno=10;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
when no_data_found then
dbms_output.put_line('invalid emp no');
when too_many_rows then
dbms_output.put_line('multipal rows');
when value_error or invalid_number then
dbms_output.put_line('Truncation or conversion error');
when zero_divide then
dbms_output.put_line('denominator ca nit be zero');
--when dup_val_on_index then
--dbms_output.put_line('--outer ');
when others then
dbms_output.put_line(sqlcode || '---' || sqlerrm);
end;
/
-- it handle all error other then predefine
---------------------------create table error_log
(
uname varchar2(30),
errcode number(10),
errmesg varchar2(1000),
errdate timestamp
);
----------------------------set serveroutput on
declare
n1 number (6):=5;
v1 varchar(1000);
n2 number(6):=0;
begin
--v1:='Excuting Pl Sql Block';
--n1:=n1/n2;
begin
insert into dept values (10, 'IT','MUM');
--exception
--when dup_val_on_index then
--dbms_output.put_line('-- inner department already exists');
end;
select ename,sal into v1,n1 from emp where empno='&empno';
--select ename,sal into v1,n1 from emp where deptno=10;
dbms_output.put_line('n1 is ' || n1 );
dbms_output.put_line('v1 is ' || v1 );
exception
when no_data_found then
dbms_output.put_line('invalid emp no');
when too_many_rows then
dbms_output.put_line('multipal rows');
when value_error or invalid_number then
dbms_output.put_line('Truncation or conversion error');
when zero_divide then
dbms_output.put_line('denominator ca nit be zero');
--when dup_val_on_index then
--dbms_output.put_line('--outer ');
n1:=sqlcode;
v1:=sqlerrm;
when others then
insert into error_log values(user,n1,v1,localtimestamp);
--dbms_output.put_line(sqlcode || '---' || sqlerrm);
end;
/
-- insert the error into table
-------------------------------------(locking)
DECLARE
qty_on_hand NUMBER(5);
BEGIN
SELECT quantity INTO qty_on_hand FROM inventory
WHERE product = 'TENNIS RACKET'
FOR UPDATE OF quantity nowait;
IF qty_on_hand > 0 THEN -- check quantity
UPDATE inventory SET quantity = quantity - 1
WHERE product = 'TENNIS RACKET';
INSERT INTO purchase_record
VALUES ('Tennis racket purchased', SYSDATE);
ELSE
INSERT INTO purchase_record
VALUES ('Out of tennis rackets', SYSDATE);
END IF;
-- COMMIT;
END;
/
--------------------------------------------DECLARE
qty_on_hand NUMBER(5);
BEGIN
SELECT quantity INTO qty_on_hand FROM inventory
WHERE product = 'TENNIS RACKET'
FOR UPDATE OF quantity nowait;
IF qty_on_hand > 0 THEN -- check quantity
UPDATE inventory SET quantity = quantity - 1
WHERE product = 'TENNIS RACKET';
INSERT INTO purchase_record
VALUES ('Tennis racket purchased', SYSDATE);
ELSE
INSERT INTO purchase_record
VALUES ('Out of tennis rackets', SYSDATE);
END IF;
-- COMMIT;
END;
/
-- for no waiting for the user bt no transaction us done
--------------------------------------------set serveroutput on
DECLARE
qty_on_hand NUMBER(5);
row_lock exception;
pragma exception_init (row_lock,-54);
BEGIN
SELECT quantity INTO qty_on_hand FROM inventory
WHERE product = 'TENNIS RACKET'
FOR UPDATE OF quantity nowait;
IF qty_on_hand > 0 THEN -- check quantity
UPDATE inventory SET quantity = quantity - 1
WHERE product = 'TENNIS RACKET';
INSERT INTO purchase_record
VALUES ('Tennis racket purchased', SYSDATE);
ELSE
INSERT INTO purchase_record
VALUES ('Out of tennis rackets', SYSDATE);
END IF;
exception
when row_lock then
dbms_output.put_line('please try after some time');
-- COMMIT;
END;
/
-- for no waiting for the user bt no transaction us done
--------------------------------------------set serveroutput on
DECLARE
qty_on_hand NUMBER(5);
row_lock exception;
pragma exception_init (row_lock,-54);
BEGIN
SELECT quantity INTO qty_on_hand FROM inventory
WHERE product = 'TENNIS RACKET'
FOR UPDATE OF quantity wait 5;
IF qty_on_hand > 0 THEN -- check quantity
UPDATE inventory SET quantity = quantity - 1
WHERE product = 'TENNIS RACKET';
INSERT INTO purchase_record
VALUES ('Tennis racket purchased', SYSDATE);
ELSE
INSERT INTO purchase_record
VALUES ('Out of tennis rackets', SYSDATE);
END IF;
exception
when row_lock then
dbms_output.put_line('please try after some time');
-- COMMIT;
END;
/
-- for no waiting for the user for 5 sec.
--------------------------------------------==========================================
to run the plsql
set serveroutput on
------