Oracle: PLSQL Commands

11,028 views
10,797 views

Published on

Oracle: PLSQL Commands

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
  • http://dbmanagement.info/Tutorials/PLSQL.htm
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
11,028
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
0
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Oracle: PLSQL Commands

  1. 1. 1<br />Using ORACLE®<br />MANIPULATING DATA using PL/SQL <br />
  2. 2. 2<br />COMMENTING CODE<br />We can add comments to the PL/SQL .There are two types of comments:<br />EXAMPLE:<br /> DECLARE<br />eage NUMBER ; --This is a single line comment . number variable defined.<br /> BEGIN<br /> SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’; /* A multiline command .Here the select command is defined */<br /> END<br />
  3. 3. 3<br />FUNCTIONS<br />The 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:<br />DECODE function.<br />All GROUP functions except the LEAST and GREATEST.<br />EXAMPLE1:<br />ename VARCHAR2(20) := INITCAP(‘bill’); --stores Bill in the variable ename.<br />We can use data type conversion function in PL/SQL statements.<br />EXAMPLE 2:<br />mainphone NUMBER(10) := 9000000000;<br />ename VARCHAR2(20);<br />BEGIN<br />SELECT name INTO ename FROM InfoTable WHERE phone = TO_NUMBER(mainphone);<br />END<br />
  4. 4. 4<br />Operators in PL/SQL<br />
  5. 5. 5<br />Operators<br />EXAMPLES:<br />profit BOOL; sp NUMBER; cp NUMBER;<br />BEGIN<br />cp:= 1000;<br />sp:= 1200;<br />profit := ((sp – cp) > 100); -- finding if profit was above 100 or not<br />END<br />
  6. 6. 6<br />RETRIEVING DATA <br />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.<br />SYNTAX:<br />SELECT column, […column] <br />INTO variable_name,[…variable_name]<br />FROM table_name<br />WHERE { expression….};<br />EXAMPLE:<br />DECLARE<br />eage NUMBER;<br /> BEGIN<br /> SELECT age INTO eage FROM InfoTable WHERE name = ‘bill’;<br /> DBMS_OUTPUT.PUT_LINE(‘ Age of bill is : ‘ || eage);<br /> END<br />
  7. 7. 7<br />INSERT command<br />We can insert data into tables using the PL/SQL INSERT command.<br />SYNTAX:<br />INSERT INTO table_name<br />(column , (…..column))<br />VALUES<br />(value , (…..value));<br />EXAMPLE:<br />BEGIN<br /> INSERT INTO InfoTable<br /> (name,age,phone)<br /> VALUES<br /> (‘micheal’,45,9666002203);<br /> END<br />
  8. 8. 8<br />UPDATE command<br />We can update data in tables using the PL/SQL UPDATE comand.<br />SYNTAX:<br />UPDATE table_name<br />SET column = value,<br /> (…column = value);<br />WHERE {expression };<br />EXAMPLE: DECLARE<br />eage NUMBER(5):=40;<br /> BEGIN<br /> UPDATE InfoTable SET age = eage<br /> WHERE name = ‘micheal’;<br /> END<br />
  9. 9. 9<br />DELETE command<br />We can delete data from tables using the PL/SQL DELETE comand.<br />SYNTAX:<br />DELETE FROM table_name<br />WHERE { expression };<br />EXAMPLE:<br />BEGIN<br /> DELETE FROM InfoTable<br /> WHERE age = 45 ;<br /> END<br />
  10. 10. 10<br />MERGE COMMAND<br />The 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.<br />DECLARE<br />ename INFOTABLE.NAME%TYPE := ‘bill';<br />BEGIN<br /> MERGE INTO addtable a<br /> USING infotable I Infotable<br /> ON (i.name =ename) <br /> WHEN MATCHED THEN<br /> UPDATE SET<br />a.phone = i.phoneADDtable<br /> WHEN NOT MATCHED THEN<br /> INSERT VALUES(i.name,NULL,i.phone); <br />END;<br />ADDtable after MERGE<br />
  11. 11. THANK YOU<br />11<br />THANK YOU FOR VIEWING THIS PRESENTATION<br />FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,<br />please visit: <br />www.dataminingtools.net<br />

×