fork download
  1. GROUP BY==========
  2. SELECT EMPLOYEE_CITY,
  3. AVG(SALARY) AS AVG_SAL
  4. FROM EMPLOYEE
  5. GROUP BY EMPLOYEE_CITY;
  6.  
  7. GROUP BY MULTIPLE==========
  8. SELECT CUST_CITY, TYPE,
  9. SUM(BALANCE) AS TOTAL_BALANCE
  10. FROM CUSTOMER
  11. NATURAL JOIN DEPOSITOR
  12. NATURAL JOIN ACCOUNT
  13. GROUP BY CUST_CITY, TYPE;
  14.  
  15. HAVING========
  16. SELECT employee_city, AVG(salary) AS avg_salary
  17. FROM employee
  18. GROUP BY employee_city
  19. HAVING AVG(salary) > 50000;
  20.  
  21. HAVING MULTIPLE========
  22. SELECT CUST_CITY, TYPE, AVG(BALANCE) AS AVG_BAL
  23. FROM CUSTOMER
  24. NATURAL JOIN DEPOSITOR
  25. NATURAL JOIN ACCOUNT
  26. GROUP BY CUST_CITY, TYPE
  27. HAVING AVG(BALANCE) > 5000;
  28.  
  29. WHERE GROUP BY HAVING ORDER BY together=========
  30. SELECT employee_city, AVG(salary) AS avg_salary
  31. FROM employee
  32. WHERE employee_startdate > '01-JAN-80'
  33. GROUP BY employee_city
  34. HAVING AVG(salary) > 1000
  35. ORDER BY AVG(salary) DESC;
  36.  
  37. Nested group quick========
  38. SELECT MAX(AVG(salary))
  39. FROM employee
  40. GROUP BY employee_city;
  41.  
  42. SELECT INTO condition=======
  43. DECLARE
  44. v_salary employee.salary%TYPE;
  45. BEGIN
  46. SELECT salary INTO v_salary
  47. FROM employee
  48. WHERE employee_id = 'E001';
  49. IF v_salary > 50000 THEN
  50. DBMS_OUTPUT.PUT_LINE('High Salary');
  51. ELSIF v_salary >= 30000 THEN
  52. DBMS_OUTPUT.PUT_LINE('Medium Salary');
  53. ELSE
  54. DBMS_OUTPUT.PUT_LINE('Low Salary');
  55. END IF;
  56. END;
  57.  
  58. CURSOR===============
  59. DECLARE
  60. CURSOR emp_cursor IS
  61. SELECT employee_name, employee_id
  62. FROM employee
  63. WHERE employee_id LIKE 'E%';
  64. emp_val emp_cursor%ROWTYPE;
  65. BEGIN
  66. OPEN emp_cursor;
  67. LOOP
  68. FETCH emp_cursor INTO emp_val;
  69. EXIT WHEN emp_cursor%NOTFOUND;
  70. DBMS_OUTPUT.PUT_LINE(emp_val.employee_name);
  71. END LOOP;
  72. CLOSE emp_cursor;
  73. END;
  74.  
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "GROUP": syntax error
Error: near line 7: near "GROUP": syntax error
Error: near line 15: near "HAVING": syntax error
Error: near line 21: near "HAVING": syntax error
Error: near line 29: near "WHERE": syntax error
Error: near line 37: near "Nested": syntax error
Error: near line 42: near "INTO": syntax error
Error: near line 45: near "SELECT": syntax error
Error: near line 49: near "IF": syntax error
Error: near line 51: near "ELSIF": syntax error
Error: near line 53: near "ELSE": syntax error
Error: near line 55: near "IF": syntax error
Error: near line 56: cannot commit - no transaction is active
Error: near line 58: near "CURSOR": syntax error
Error: near line 64: near "emp_val": syntax error
Error: near line 65: near "OPEN": syntax error
Error: near line 67: near "LOOP": syntax error
Error: near line 69: near "EXIT": syntax error
Error: near line 70: near "DBMS_OUTPUT": syntax error
Error: near line 71: near "LOOP": syntax error
Error: near line 72: near "CLOSE": syntax error
Error: near line 73: cannot commit - no transaction is active