Advertisement
abrar1

Untitled

Dec 11th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. -- function
  2. create or replace function employee_profit(emp_id in NUMBER)
  3. return number is
  4. profit number(10);
  5.  
  6. begin
  7. --if emp_id does not exist in sl.EMPLOYEE_ID , profit := 0 ; return profit ;
  8. --else
  9. select sum(sp.PRICE - nvl(sp."BUYING PRICE",0)) into profit
  10. from SALES sl, STOCK stk, PRODUCT_SPECIFICATION sp
  11. where sl.PRODUCT_IMEI_NO = stk.STOCK_IMEI and stk.STOCK_PRODUCT_ID = sp.PRODUCT_ID
  12. group by sl.EMPLOYEE_ID
  13. having sl.EMPLOYEE_ID = emp_id ;
  14. return profit ;
  15.  
  16. exception
  17. when no_data_found then
  18. profit := 0 ;
  19. return profit;
  20. end;
  21.  
  22.  
  23. select EMPLOYEE_ID, employee_profit(EMPLOYEE_ID)
  24. from EMPLOYEES
  25. where username like '%sales%' ;
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement