Usage and exceptions of optical mark in Oracle

Source: Internet
Author: User

Usage and exceptions of optical mark in Oracle

  1. 1. Use of cursor without Parameters
  2. SQL>Declare
  3. 2CursorClIs Select*FromEmp;
  4. 3 emp_row emp % rowtype;
  5. 4Begin
  6. 5OpenCl;
  7. 6 loop
  8. 7FetchClIntoEmp_row;
  9. 8 exitWhenCl % notfound;
  10. 9 dbms_output.put_line ('Employee name'| Emp_row.ename |'Employee Department'| Emp_row.deptno );
  11. 10EndLoop;
  12. 11CloseCl;
  13. 12End;
  14. 13/
  15. Employee name SMITH employee's department 20
  16. Employee name ALLEN employee Department 30
  17. Employee name WARD employee Department 30
  18. Employee name JONES employee's department 20
  19. Employee name MARTIN employee Department 30
  20. Employee name: employee's Department 30
  21. Employee name CLARK employee's Department 10
  22. Employee name SCOTT employee's department 20
  23. Employee name KING employee's Department 10
  24. Employee name TURNER employee Department 30
  25. Employee name ADAMS employee's department 20
  26. Employee name JAMES employee Department 30
  27. Employee name FORD employee's department 20
  28. Employee name MILLER employee Department 10
  29. PL/SQLProcedureSuccessfully completed
  30. SQL>Declare
  31. 2CursorCl (emp_name varchar2)Is Select*FromEmpWhereEname = emp_name;
  32. 3 emp_row emp % rowtype;
  33. 4Begin
  34. 5OpenCl ('Smith');
  35. 6FetchClIntoEmp_row;
  36. 7 dbms_output.put_line ('Employee name'| Emp_row.ename |'Employee's work'| Emp_row.job );
  37. 8CloseCl;
  38. 9End;
  39. 10/
  40. Employee name SMITH employee's work CLERK
  41. Employees numbered 10
  42. SQL>Declare
  43. 2CursorCl (emp_deptno number)Is Select*FromEmpWhereDeptno = emp_deptno;
  44. 3 emp_row emp % rowtype;
  45. 4Begin
  46. 5OpenCl (10 );
  47. 6 loop
  48. 7FetchClIntoEmp_row;
  49. 8 exitWhenCl % notfound;
  50. 9 dbms_output.put_line ('Employee name :'| Emp_row.ename );
  51. 10EndLoop;
  52. 11CloseCl;
  53. 12End;
  54. 13/
  55. Employee name: CLARK
  56. Employee name: KING
  57. Employee name: MILLER
  58. PL/SQLProcedureSuccessfully completed
  59. Exception except 0
  60. SQL>Declare
  61. 2 pnum number: = 10;
  62. 3Begin
  63. 4 pnum: = pnum/0;
  64. 5 exception
  65. 6WhenZero_divideThen
  66. 7 dbms_output.put_line ('Division cannot be 0');
  67. 8End;
  68. 9/
  69. The divisor cannot be 0.
  70. PL/SQLProcedureSuccessfully completed
  71. Custom exceptions
  72. SQL>Declare
  73. 2CursorCl (emp_no number)Is Select*FromEmpWhereEmpno = emp_no;
  74. 3 emprow emp % rowtype;
  75. 4 no_found exception;
  76. 5Begin
  77. 6OpenCl (1000 );
  78. 7FetchClIntoEmprow;
  79. 8 if cl % notfoundThenRaise no_found;
  80. 9EndIf;
  81. 10CloseCl;
  82. 11 exception
  83. 12WhenNo_foundThen
  84. 13 dbms_output.put_line ('Custom accidents');
  85. 14End;
  86. 15/
  87. Accidents defined by yourself
  88. PL/SQLProcedureSuccessfully completed

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.