PL-SQL
PL-SQL
=========>>>> 1)
declare
a number(4);
b number(4);
begin
a:=4;
b:=6;
DBMS_OUTPUT.PUT_LINE(a+b);
DBMS_OUTPUT.PUT_LINE('Bhavin' || ' ' || 'Jariwala'); /*concatination of string
using pipe operator*/
end;
=========>>>> 2)
declare
a number(4);
b number(4);
begin
b:=6;
DBMS_OUTPUT.PUT_LINE(a+b);
/*If any one value is NULL than output will be NULL. Default value of variable is
NULL*/
end;
2)
// LOOP
/*
--->SYNTAX
LOOP
#code
EXIT WHEN exit_condition
END LOOP;
// 'END LOOP' passes control to the 'LOOP'
*/
DECLARE
I NUMBER(6) := 0;
AC_NO ACCOUNT.ACCOUNTNO%TYPE;
BEGIN
AC_NO := 105;
LOOP
AC_NO := AC_NO + 1;
INSERT INTO ACCOUNT VALUES(AC_NO,12000);
I := I + 1;
EXIT WHEN I>5;
END LOOP;
END;
/*
--->SYNTAX:
CREATE SEQUENCE sequence_name
STARTS WITH initial_value
INCREMENTED BY incrementation_value
MAXVALUE value till squence will be increment value
MINVALUE minimum value(uses if you decrement value or increment by -1)
CYCLE|NOCYCLE
CYCLE : if sequence reaches it's maximum value it will again starts from initial
value
NOCYCLE: if sequence exceeds its maximum value an exception will be thrown
*/
create sequence bankid
start with 1
increment by 1;
delete from account; //delete all the records from table
begin
insert into account values(bankid.nextval,4500);
insert into account values(bankid.nextval,2500);
insert into account values(bankid.nextval,20000);
insert into account values(bankid.nextval,45000);
insert into account values(bankid.nextval,13000);
insert into account values(bankid.nextval,15000);
insert into account values(bankid.nextval,25000);
end;
select * from account