Update using the PL/SQL variables : Update « Object Oriented Database « Oracle PL / SQL

Home
Oracle PL / SQL
1.Aggregate Functions
2.Analytical Functions
3.Char Functions
4.Constraints
5.Conversion Functions
6.Cursor
7.Data Type
8.Date Timezone
9.Hierarchical Query
10.Index
11.Insert Delete Update
12.Large Objects
13.Numeric Math Functions
14.Object Oriented Database
15.PL SQL
16.Regular Expressions
17.Report Column Page
18.Result Set
19.Select Query
20.Sequence
21.SQL Plus
22.Stored Procedure Function
23.Subquery
24.System Packages
25.System Tables Views
26.Table
27.Table Joins
28.Trigger
29.User Previliege
30.View
31.XML
Oracle PL / SQL » Object Oriented Database » Update 




Update using the PL/SQL variables
  
SQL>
SQL> CREATE OR REPLACE TYPE StudentList AS TABLE OF NUMBER(5);
  2  /

Type created.

SQL>
SQL>
SQL> CREATE TABLE library_catalog (
  2    catalog_number NUMBER(4),
  3    num_copies     NUMBER,
  4    num_out        NUMBER,
  5    checked_out    StudentList)
  6    NESTED TABLE checked_out STORE AS co_tab;

Table created.

SQL>
SQL>
SQL> DECLARE
  2    v_StudentList1 StudentList := StudentList(100001000210003);
  3    v_StudentList2 StudentList := StudentList(100001000210003);
  4    v_StudentList3 StudentList := StudentList(100001000210003);
  5  BEGIN
  6    -- First insert rows with NULL nested tables.
  7    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
  8      VALUES (1000203);
  9    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
 10      VALUES (1001203);
 11    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
 12      VALUES (1002103);
 13    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
 14      VALUES (2001500);
 15    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
 16      VALUES (300150);
 17    INSERT INTO library_catalog (catalog_number, num_copies, num_out)
 18      VALUES (300251);
 19
 20    UPDATE library_catalog
 21      SET checked_out = v_StudentList1
 22      WHERE catalog_number = 1000;
 23    UPDATE library_catalog
 24      SET checked_out = v_StudentList2
 25      WHERE catalog_number = 1001;
 26    UPDATE library_catalog
 27      SET checked_out = v_StudentList3
 28      WHERE catalog_number = 1002;
 29
 30    -- And update the last row using new variable.
 31    UPDATE library_catalog
 32      SET checked_out = StudentList(10009)
 33      WHERE catalog_number = 3002;
 34  END;
 35  /

PL/SQL procedure successfully completed.

SQL>
SQL> DELETE FROM library_catalog
  2    WHERE catalog_number = 3001;

row deleted.

SQL>
SQL>
SQL>
SQL> select from library_catalog;

CATALOG_NUMBER NUM_COPIES    NUM_OUT
-------------- ---------- ----------
CHECKED_OUT
--------------------------------------------------------------------------------
          1000         20          3
STUDENTLIST(100001000210003)

          1001         20          3
STUDENTLIST(100001000210003)

          1002         10          3
STUDENTLIST(100001000210003)


CATALOG_NUMBER NUM_COPIES    NUM_OUT
-------------- ---------- ----------
CHECKED_OUT
--------------------------------------------------------------------------------
          2001         50          0


          3002          5          1
STUDENTLIST(10009)


SQL>
SQL> drop table library_catalog;

Table dropped.

SQL>
SQL>

   
  














Related examples in the same category
1.Use type constructor in update statement
2.update calls the constructor in the SET clause
3.Using UPDATE with Columns
4.UPDATE Data in a Table of Row Objects
5.UPDATE a Table that Contains Row Objects (TCRO)
6.Update user-defined type column
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.