surya760

bank.oracle

Oct 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. CREATION OF TABLES:
  2.  
  3. SQL> create table customer
  4. (
  5. customer_id number(10) primary key,
  6. customername varchar2(20),
  7. contactno number(10),
  8. address varchar2(20),
  9. aadharnumber number(20),
  10. emailid varchar2(30),
  11. );
  12. Table created.
  13.  
  14. SQL> create table account
  15. (
  16. account_id number(10) primary key,
  17. type varchar2(10),
  18. opendate date,
  19. closedate date,
  20. interest number(10),
  21. balance number(10));
  22. foreign key(customer_id) references customer(customer_id)
  23. );
  24.  
  25. Table created.
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. INSERTING VALUES:
  28.  
  29.  
  30. SQL> insert into Account values(101,'saving',TO_DATE('01-01-2018','dd-mm-yyyy'),TO_DATE('01-01-2030','dd-mm-yyyy'),10,54321,201);
  31.  
  32. 1 row created.
  33.  
  34. SQL> insert into Account values(102,'current',TO_DATE('02-01-2018','dd-mm-yyyy'),TO_DATE('02-01-2030','dd-mm-yyyy'),5,45321,203);
  35.  
  36. 1 row created.
  37.  
  38. SQL>
  39.  
  40. SQL> insert into Account values(103,'salary',TO_DATE('03-01-2018','dd-mm-yyyy'),TO_DATE('03-01-2030','dd-mm-yyyy'),10,32451,201);
  41.  
  42. 1 row created.
  43.  
  44. SQL> insert into customer values(201,'raja',9688161234,'erode',330953639542,'kiruthiik15@gmail.com');
  45.  
  46. 1 row created.
  47.  
  48. SQL> insert into customer values(202,'kiruthiik',8667495530,'coimbatore',330965458789,'kiruthiik750@gmail.com');
  49.  
  50. 1 row created.
  51.  
  52. SQL> insert into customer values(203,'hari',8074456458,'kerala',354852526454,'hariguru@gmail.com');
  53.  
  54. 1 row created.
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. TO DISPLAY TABLES:
  57.  
  58. SQL> select * from account;
  59.  
  60. ACCOUNT_ID TYPE OPENDATE CLOSEDATE INTEREST BALANCE CUSTOMER_ID
  61. ---------- ---------- --------- --------- ---------- -------------------------
  62. 101 saving 01-JAN-18 01-JAN-30 10 54321 201
  63. 102 current 02-JAN-18 02-JAN-30 5 45321 203
  64. 103 salary 03-JAN-18 03-JAN-30 10 32451 201
  65.  
  66.  
  67. SQL> select * from customer;
  68.  
  69. CUSTOMER_ID CUSTOMERNAME CONTACTNO ADDRESS AADHARNUMBER EMAILID
  70. ----------- -------------------- ---------- -------------------- ---------------------------------------
  71.  
  72. 201 raja 9688161234 erode 3.3095E+11 kiruthiik15@gmail.com
  73.  
  74.  
  75. 202 kiruthiik 8667495530 coimbatore 3.3097E+11 kiruthiik750@gmail.com
  76.  
  77.  
  78. 203 hari 8074456458 kerala 3.5485E+11 hariguru@gmail.com
  79.  
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. 3) Query 1:
  82.  
  83. Write an SQL query to display the account details alongwith balance for all the customers.
  84.  
  85.  
  86. SQL> select account.*,customer.customer_id,customer.customername from account,customer where customer.customer_id=account.customer_id;
  87.  
  88. ACCOUNT_ID TYPE OPENDATE CLOSEDATE INTEREST BALANCE CUSTOMER_ID
  89. ---------- ---------- --------- --------- ---------- ---------- -----------
  90. CUSTOMERNAME
  91. --------------------
  92. 101 saving 01-JAN-18 01-JAN-30 10 54321 201
  93. raja
  94.  
  95. 102 current 02-JAN-18 02-JAN-30 5 45321 202
  96. kiruthiik
  97.  
  98. 103 salary 03-JAN-18 03-JAN-30 10 32451 203
  99. hari
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101.  
  102. 4) Query 2:
  103.  
  104. Write an SQL query to display the details of the accounts opened for the given date range.
  105.  
  106.  
  107. SQL> select * from account where opendate between TO_DATE('31-12-2017','dd-mm-yyyy') and TO_DATE('04-01-2018','dd-mm-yyyy');
  108.  
  109. ACCOUNT_ID TYPE OPENDATE CLOSEDATE INTEREST BALANCE
  110. ---------- ---------- --------- --------- ---------- ----------
  111. 101 saving 01-JAN-18 01-JAN-30 10 54321
  112. 102 current 02-JAN-18 02-JAN-30 5 45321
  113. 103 salary 03-JAN-18 03-JAN-30 10 32451
  114.  
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116. 5) Write a procedure to display the account details of the accounts having maximum and minimum balance.
  117.  
  118. SQL> !vi displaydetails.sql
  119.  
  120. create or replace procedure displaydetails
  121. is
  122. cursor c is select * from account where balance=(select min(balance) from account);
  123. cursor d is select * from account where balance=(select max(balance) from account);
  124. a c% rowtype;
  125. b d% rowtype;
  126. BEGIN
  127. open c;
  128. fetch c into a;
  129. dbms_output.put_line('***************************************');
  130. dbms_output.put_line('Account datails for Maximum balance');
  131. dbms_output.put_line('accountid: '||a.account_id);
  132. dbms_output.put_line('accountType: '||a.type);
  133. dbms_output.put_line('Opendate: '||a.opendate);
  134. dbms_output.put_line('closedate: '||a.closedate);
  135. dbms_output.put_line('interest is: '||a.interest);
  136. dbms_output.put_line('balance: '||a.balance);
  137. close c;
  138. open d;
  139. fetch d into b;
  140. dbms_output.put_line('***************************************');
  141. dbms_output.put_line('Account datails for Minimum balance');
  142. dbms_output.put_line('accountid: '||b.account_id);
  143. dbms_output.put_line('accountType: '||b.type);
  144. dbms_output.put_line('Opendate: '||b.opendate);
  145. dbms_output.put_line('closedate: '||b.closedate);
  146. dbms_output.put_line('interest is: '||b.interest);
  147. dbms_output.put_line('balance: '||b.balance);
  148. dbms_output.put_line('***************************************');
  149. close d;
  150. end;
  151. /
  152. show errors;
  153.  
  154. SQL> @displaydetails.sql
  155.  
  156. Procedure created.
  157.  
  158. No errors.
  159. SQL> exec displaydetails
  160. ***************************************
  161. Account datails for Maximum balance
  162. accountid: 103
  163. accountType: salary
  164. Opendate: 03-JAN-18
  165. closedate: 03-JAN-30
  166. interest is: 10
  167. balance: 32451
  168. ***************************************
  169. Account datails for Minimum balance
  170. accountid: 101
  171. accountType: saving
  172. Opendate: 01-JAN-18
  173. closedate: 01-JAN-30
  174. interest is: 10
  175. balance: 54321
  176. ***************************************
  177.  
  178. PL/SQL procedure successfully completed.
Add Comment
Please, Sign In to add comment