Advertisement
Aniket_Goku

assi8

Nov 20th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.74 KB | None | 0 0
  1. CREATE TABLE customer
  2. (
  3.     customerid VARCHAR(4) primary key,
  4.     customername VARCHAR(20)
  5. );
  6. CREATE TABLE account
  7. (
  8.     accountid VARCHAR(4) primary key,
  9.     customerid VARCHAR(4),
  10.     accounttype VARCHAR(20),
  11.     balance NUMBER,
  12.     constraints fk_cid foreign key (customerid) references customer(customerid) ON DELETE cascade
  13. );
  14.  
  15. --insert on customer;
  16. INSERT INTO customer VALUES('c01','Aniket');
  17. INSERT INTO customer VALUES('c02','Sahil');
  18. INSERT INTO customer VALUES('c03','Dev');
  19. INSERT INTO customer VALUES('c04','Brijal');
  20. INSERT INTO customer VALUES('c05','Devanshi');
  21. INSERT INTO customer VALUES('c06','Shivangi');
  22. INSERT INTO customer VALUES('c07','Aditi');
  23. INSERT INTO customer VALUES('c08','Aadesh');
  24.  
  25. --insert in account
  26. INSERT INTO account VALUES('A01','c01','Currant',46000);
  27. INSERT INTO account VALUES('A02','c02','Saving',20000);
  28. INSERT INTO account VALUES('A03','c03','Saving',1000);
  29. INSERT INTO account VALUES('A04','c04','Saving',12500);
  30. INSERT INTO account VALUES('A05','c05','Currant',22000);
  31. INSERT INTO account VALUES('A06','c06','Currant',11000);
  32. INSERT INTO account VALUES('A07','c07','Saving',10200);
  33. INSERT INTO account VALUES('A08','c08','Saving',21500);
  34. INSERT INTO account VALUES('A09','c01','Saving',12000);
  35. INSERT INTO account VALUES('A10','c02','Currant',2000);
  36. INSERT INTO account VALUES('A11','c03','Currant',2750);
  37. INSERT INTO account VALUES('A12','c07','Currant',12000);
  38. INSERT INTO account VALUES('A13','c08','Currant',22000);
  39.  
  40.  
  41.  
  42. --Q1
  43. DECLARE
  44. ano VARCHAR(4):='&ano';
  45. aid VARCHAR(4);
  46. cid VARCHAR(4);
  47. aty VARCHAR(20);
  48. bal NUMBER;
  49. T NUMBER:=0;
  50. exp4 EXCEPTION;
  51. CURSOR c1
  52. IS
  53. SELECT * INTO aid,cid,aty,bal
  54.     FROM account
  55.     WHERE accountid=ano;
  56.  
  57. BEGIN
  58.         OPEN c1;
  59.         LOOP
  60.             FETCH c1 INTO aid,cid,aty,bal;
  61.             EXIT WHEN c1%notfound;
  62.             IF (bal-5000)<1000  THEN
  63.                 DBMS_OUTPUT.put_line(aid ||' => ' || cid||' => ' ||aty||' => ' ||bal);
  64.                 raise_application_error(-20008,'Account has minimum amount 1000 after debit  5000 rs so it will not debited');
  65.                 T:=1;
  66.             ELSE
  67.                 DBMS_OUTPUT.put_line(' 5000 RS Debited From A\c no: '|| aid);
  68.                 UPDATE account
  69.                 SET balance=balance-5000
  70.                 WHERE accountid=aid;
  71.                 DBMS_OUTPUT.put_line(aid ||' => ' || cid||' => ' ||aty||' => ' ||bal);
  72.                 T:=1;
  73.             END IF;
  74.         END LOOP;
  75.         CLOSE c1;
  76.         IF T=0 THEN
  77.             RAISE exp4;
  78.         END IF;
  79.        
  80.         EXCEPTION
  81.             WHEN exp4 THEN
  82.                 raise_application_error(-20001,'THe Account no is INVALID');
  83. END;
  84. /
  85.  
  86. --Q2
  87.  
  88. CREATE OR REPLACE TRIGGER trg_day
  89. before UPDATE ON account
  90. FOR each ROW
  91. BEGIN
  92.     IF  TO_CHAR(SYSDATE,'Dy') IN ('Sun','Sat') THEN
  93.         raise_application_error(-20012,'This is Weekend Boss no entry');
  94.     END IF;
  95. END trg_day;
  96. /
  97.  
  98. UPDATE account
  99. SET balance=30000
  100. WHERE accountid='A02';
  101. --select to_char(sysdate,'Dy') from dual;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement