Wednesday, September 29, 2010

Simple PL Sql Query Example , Select query, Insert query, Delete Query, update query

SQL> select * from salesman;

     SNUM SNAME      CITY       COMMIS
--------- ---------- ---------- ------
     1001 PIYUSH     LONDON     12%
     1002 NIRAJ      SURAT      13%
     1003 MITI       LONDON     11%
     1004 RAJESH     BARODA     15%
     1005 ANAND      NEW DELHI  10%
     1006 RAM        PATAN      10%
     1007 LAXMAN     BOMBAY     09%

7 rows selected.
--------------------------------------------------------------------------------------------
SQL> select * from customer;

     CNUM CNAME      CITY          RATING      SNUM
--------- ---------- ---------- --------- ---------
     2001 hardik     london           100      1001
     2002 gita       rome             200      1003
     2003 laxit      surat            200      1002
     2004 govind     bombay           300      1002
     2005 chandu     london           100      1001
     2006 champak    surat            300      1007
     2007 pratik     rome             100      1004

7 rows selected.
----------------------------------------------------------------------------------------------
SQL> select * from aorder;

     ONUM    AMOUNT ODATE          CNUM      SNUM
--------- --------- --------- --------- ---------
     3001     18.69 10-MAR-99      2007      1007
     3002    767.19 10-MAR-99      2001      1001
     3003    1900.1 10-MAR-99      2007      1004
     3004   5160.45 10-MAR-99      2003      1002
     3005   1098.25 10-APR-99      2007      1007
     3006   1713.12 10-APR-99      2002      1003
     3007     75.75 10-MAY-99      2004      1002
     3008      4723 10-MAY-99      2006      1001
     3009   1309.95 10-MAY-99      2004      1002
     3010   9898.87 10-JUN-99      2006      1001

---------------------------------------------------------------------------------------------

 (1)

sQL> select onum, amount,odate from aorder;

     ONUM    AMOUNT ODATE
--------- --------- ---------
     3001     18.69 10-MAR-99
     3002    767.19 10-MAR-99
     3003    1900.1 10-MAR-99
     3004   5160.45 10-MAR-99
     3005   1098.25 10-APR-99
     3006   1713.12 10-APR-99
     3007     75.75 10-MAY-99
     3008      4723 10-MAY-99
     3009   1309.95 10-MAY-99
     3010   9898.87 10-JUN-99

10 rows selected.
--------------------------------------------------------------------------------------------
(2)

SQL> select * from customer where snum=1001;

     CNUM CNAME      CITY          RATING      SNUM
--------- ---------- ---------- --------- ---------
     2001 hardik     london           100      1001
     2005 chandu     london           100      1001
--------------------------------------------------------------------------------------------

(3)

SQL> select city,sname,snum ,commission from salesman;

CITY       SNAME           SNUM COMMIS
---------- ---------- --------- ------
LONDON     PIYUSH          1001 12%
SURAT      NIRAJ           1002 13%
LONDON     MITI            1003 11%
BARODA     RAJESH          1004 15%
NEW DELHI  ANAND           1005 10%
PATAN      RAM             1006 10%
BOMBAY     LAXMAN          1007 09%

7 rows selected.
--------------------------------------------------------------------------------------------
(4)

SQL> SELECT RATING,CNAME FROM customer where city='surat';

   RATING CNAME
--------- ----------
      200 laxit
      300 champak
--------------------------------------------------------------------------------------------
(5)

SQL> select distinct snum from aorder;

     SNUM
---------
     1001
     1002
     1003
     1004
     1007
---------------------------------------------------------------------------------------------
(6)

SQL> select *from aorder where amount>1000;

     ONUM    AMOUNT ODATE          CNUM      SNUM
     --------- --------- --------- --------- ---------
     3003    1900.1 10-MAR-99      2007      1004
     3004   5160.45 10-MAR-99      2003      1002
     3005   1098.25 10-APR-99      2007      1007
     3006   1713.12 10-APR-99      2002      1003
     3008      4723 10-MAY-99      2006      1001
     3009   1309.95 10-MAY-99      2004      1002
     3010   9898.87 10-JUN-99      2006      1001

7 rows selected.