Skip to Main Content
Oracle PL/SQL Programming: A Developer's Workbook
book

Oracle PL/SQL Programming: A Developer's Workbook

by Steven Feuerstein, Andrew Odewahn
May 2000
Intermediate to advanced content levelIntermediate to advanced
594 pages
11h 32m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL Programming: A Developer's Workbook

Intermediate

Q:

6-14.

The only complication comes into play when you assign a value to a field in a record:

Table Name

Syntax

Number_table

number_table(100) := 100;

Empno_table

empno_table(100) := 100;

Employee_table

employee_table(100).empno := 100;

Employee_record_table

employee_record_table(100).empno := 100;

Q:

6-15.

Here are the methods:

  1. EXISTS

  2. COUNT

  3. FIRST

  4. LAST

  5. PRIOR

  6. NEXT

  7. DELETE

Prior to Oracle 7.3, these methods were not available, and you had to write code yourself to keep track of FIRST, LAST, etc. To see an example of the kind of code you had to write to do this, see the lclmthd.sql file on the book’s web page.

Q:

6-16.

You can specify NOT NULL for the collection type:

SQL> DECLARE
  2    TYPE a_table_type IS TABLE OF NUMBER(10) NOT NULL
  3    INDEX BY BINARY_INTEGER;
  4    a_table a_table_type;
  5  BEGIN
  6    a_table(-100) := -9876;
  7    a_table(-100) := NULL;  -- will fail!
  8  END;
  9  /
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error

Tip

You can also use IS NULL to check values before assigning them to rows. This approach involves writing more code, but Oracle claims that it is more efficient than the declarative constraint NOT NULL.

Q:

6-17.

First, declare a cursor to fetch the employee numbers:

DECLARE
   CURSOR curs_get_empnos IS
   SELECT employee_id
     FROM employee;

Then define a table TYPE and index-by table based on the employee ID number:

TYPE v_employee_table_type IS TABLE OF employee.employee_id%TYPE INDEX ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle Database 12c PL/SQL Programming

Oracle Database 12c PL/SQL Programming

Michael McLaughlin
Oracle PL/SQL for DBAs

Oracle PL/SQL for DBAs

Arup Nanda, Steven Feuerstein
Oracle PL/SQL For Dummies

Oracle PL/SQL For Dummies

Michael Rosenblum, Paul Dorsey

Publisher Resources

ISBN: 9781449324070Supplemental ContentErrata Page