google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Monday, February 11, 2019

Assignment in SQL for Using trigger


Assignment:-               
Assign. Name:-Using Trigger
CLASS:-T.Y.B.Sc(Computer)     



     *************************************************************

Triggers:-

 SQL> select * from purchase

 PO_NO   PO_DATE     ITEM_NO    QTY
 --------  ---------            ----------    ---------
 11          12-MAY-03      101        100
 12          17-JUN-03       102        75
 13          21-APR-03       103        150
 14          14-JAN-04       104        100

 SQL> select * from stock;

 ITEM_NO       QTY
-----------  -----------
  101            100
  102             75
  103            150
  104            100

      <1>                       

     create or replace trigger ptr1 before insert on purchase for each row
     declare
     v1 integer;
     begin
    select count(*) into v1 from stock
    where Itrmno=:new.Item_no;
    if v1=0 then
    insert into stock values(:new.Itemno,:new.qty)
    else
    update stock set qty=qty+:new.qty
    where Itemno=:new.Itemno;
    end if;
    end;
    /
SQL> select * from purchase;

Assignment in SQL for use of set operator


Assignment:-               

Assign. Name:- In SQL Use of SET Operator.

CLASS:-T.Y.B.Sc(Computer)          

*************************************************************

Use of SET Operator:
- UNION
- INTERSECT
- IN
- NOT IN

SQL>select * from borrower;

 CUST_NAME                 LOAN_NO
---------------------    -------------
Samir                            1
Mahesh                         2
Smita                            3
Vrushali                         4
Devendra                       5
Vaibhav                         6

UNION:-
SQL> (select cust_name from borrower) UNION
     (select cust_name from depositer);
 CUST_NAME
-----------------------
 Devendra
 Mahesh
 Samir
 Smita
 Vaibhav
 Vrushali
  6 rows selected.
SQL> (Select cust_name from borrower) UNION ALL
     (Select cust_name from depositer);

    CUST_NAME
---------------------------------
    Samir
    Mahesh
    Smita
    Vrushali
    Devendra
    Vaibhav
    Samir
    Mahesh
    Samita
    Vrushali
    Devendra   

    

11 row selected.

INTERSECT:-

SQL> (Select cust_name from borrower) INTERSECT
     (Select cust_name from depositer);

    CUST_NAME
  ----------------------------
    Devendra
    Mahesh
    Samir
    Smita
    Vrushali

 IN:-

SQL> Select DISTINCT cust_name from borrower WHERE
     cust_name IN (Select cust_name from depositer);

    CUST_NAME
       ------------------------
    Devendra
    Mahesh
    Samir
    Smita
    Vrushali

 NOT IN:-

SQL> Select DISTINCT cust_name from borrower WHERE
     cust_name NOT IN (Select cust_name from depositer);

    CUST_NAME
    ----------------------
    Vaibhav
   

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...