1Using ORACLE®MANIPULATING DATA using PL/SQL
2COMMENTING CODEWe can add comments to the PL/SQL .There are two types of comments:EXAMPLE:	DECLAREeage NUMBER ; --This is a single line comment . number variable defined.	BEGIN	SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’;	/* A multiline	command .Here the select command is defined */	END
3FUNCTIONSThe functions available in SQL can be used in PL/SQL code. Not all SQL function can be used in PL/SQL statements .The SQL functions unavailable in Pl/SQL statements are:DECODE function.All GROUP functions except the LEAST and GREATEST.EXAMPLE1:ename VARCHAR2(20) := INITCAP(‘bill’);	--stores Bill in the variable ename.We can use data type conversion function in PL/SQL statements.EXAMPLE 2:mainphone NUMBER(10) := 9000000000;ename VARCHAR2(20);BEGINSELECT name INTO ename FROM InfoTable WHERE phone = TO_NUMBER(mainphone);END
4Operators in PL/SQL
5OperatorsEXAMPLES:profit BOOL;	sp NUMBER;	cp NUMBER;BEGINcp:= 1000;sp:= 1200;profit := ((sp – cp) > 100); -- finding if profit was above 100 or notEND
6RETRIEVING DATA We can retrieve data using the SELECT command. Variables are used to store the values returned from the SELECT statement and hence have to be of the same datatype and be declared before use.SYNTAX:SELECT column, […column] INTO variable_name,[…variable_name]FROM table_nameWHERE { expression….};EXAMPLE:DECLAREeage NUMBER;	BEGIN	SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’;	DBMS_OUTPUT.PUT_LINE(‘ Age of bill is : ‘ || eage);	END
7INSERT commandWe can insert data into tables using the PL/SQL INSERT command.SYNTAX:INSERT INTO table_name(column , (…..column))VALUES(value , (…..value));EXAMPLE:BEGIN	INSERT INTO InfoTable	(name,age,phone)	VALUES	(‘micheal’,45,9666002203);	END
8UPDATE commandWe can update data in tables using the PL/SQL UPDATE comand.SYNTAX:UPDATE table_nameSET	column = value,	(…column = value);WHERE	{expression };EXAMPLE:	DECLAREeage NUMBER(5):=40;	BEGIN	UPDATE InfoTable SET age = eage	WHERE name = ‘micheal’;	END
9DELETE commandWe can delete data from tables using the PL/SQL DELETE comand.SYNTAX:DELETE FROM table_nameWHERE { expression };EXAMPLE:BEGIN	DELETE FROM InfoTable	WHERE age = 45 ;	END
10MERGE COMMANDThe MERGE comand is use to merge the data of one table into the data of another table.The merge command updates or inserts rows in order to make data in both rows similar.DECLAREename INFOTABLE.NAME%TYPE := ‘bill';BEGIN	MERGE INTO addtable a	USING infotable I	Infotable	ON (i.name =ename)	WHEN MATCHED THEN	UPDATE SETa.phone = i.phoneADDtable	WHEN NOT MATCHED THEN	INSERT VALUES(i.name,NULL,i.phone);	END;ADDtable after MERGE
THANK YOU11THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit: www.dataminingtools.net

Oracle: PLSQL Commands

  • 1.
  • 2.
    2COMMENTING CODEWe canadd comments to the PL/SQL .There are two types of comments:EXAMPLE: DECLAREeage NUMBER ; --This is a single line comment . number variable defined. BEGIN SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’; /* A multiline command .Here the select command is defined */ END
  • 3.
    3FUNCTIONSThe functions availablein SQL can be used in PL/SQL code. Not all SQL function can be used in PL/SQL statements .The SQL functions unavailable in Pl/SQL statements are:DECODE function.All GROUP functions except the LEAST and GREATEST.EXAMPLE1:ename VARCHAR2(20) := INITCAP(‘bill’); --stores Bill in the variable ename.We can use data type conversion function in PL/SQL statements.EXAMPLE 2:mainphone NUMBER(10) := 9000000000;ename VARCHAR2(20);BEGINSELECT name INTO ename FROM InfoTable WHERE phone = TO_NUMBER(mainphone);END
  • 4.
  • 5.
    5OperatorsEXAMPLES:profit BOOL; sp NUMBER; cpNUMBER;BEGINcp:= 1000;sp:= 1200;profit := ((sp – cp) > 100); -- finding if profit was above 100 or notEND
  • 6.
    6RETRIEVING DATA Wecan retrieve data using the SELECT command. Variables are used to store the values returned from the SELECT statement and hence have to be of the same datatype and be declared before use.SYNTAX:SELECT column, […column] INTO variable_name,[…variable_name]FROM table_nameWHERE { expression….};EXAMPLE:DECLAREeage NUMBER; BEGIN SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’; DBMS_OUTPUT.PUT_LINE(‘ Age of bill is : ‘ || eage); END
  • 7.
    7INSERT commandWe caninsert data into tables using the PL/SQL INSERT command.SYNTAX:INSERT INTO table_name(column , (…..column))VALUES(value , (…..value));EXAMPLE:BEGIN INSERT INTO InfoTable (name,age,phone) VALUES (‘micheal’,45,9666002203); END
  • 8.
    8UPDATE commandWe canupdate data in tables using the PL/SQL UPDATE comand.SYNTAX:UPDATE table_nameSET column = value, (…column = value);WHERE {expression };EXAMPLE: DECLAREeage NUMBER(5):=40; BEGIN UPDATE InfoTable SET age = eage WHERE name = ‘micheal’; END
  • 9.
    9DELETE commandWe candelete data from tables using the PL/SQL DELETE comand.SYNTAX:DELETE FROM table_nameWHERE { expression };EXAMPLE:BEGIN DELETE FROM InfoTable WHERE age = 45 ; END
  • 10.
    10MERGE COMMANDThe MERGEcomand is use to merge the data of one table into the data of another table.The merge command updates or inserts rows in order to make data in both rows similar.DECLAREename INFOTABLE.NAME%TYPE := ‘bill';BEGIN MERGE INTO addtable a USING infotable I Infotable ON (i.name =ename) WHEN MATCHED THEN UPDATE SETa.phone = i.phoneADDtable WHEN NOT MATCHED THEN INSERT VALUES(i.name,NULL,i.phone); END;ADDtable after MERGE
  • 11.
    THANK YOU11THANK YOUFOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit: www.dataminingtools.net