Select the object type from the table, rather than the columns. : Select « Object Oriented Database « Oracle PL / SQL






Select the object type from the table, rather than the columns.

 
SQL>

SQL>
SQL> CREATE TABLE rel_tab (
  2    f1 NUMBER,
  3    f2 VARCHAR2(50)
  4  );

Table created.

SQL>
SQL> CREATE or replace TYPE objType AS OBJECT (
  2    f1 NUMBER,
  3    f2 VARCHAR2(50)
  4  );
  5  /

Type created.

SQL> show errors
No errors.
SQL>
SQL> CREATE TABLE obj_tab OF objType;

Table created.

SQL>
SQL>
SQL> DECLARE
  2    v_Row obj_tab%ROWTYPE;
  3    CURSOR c_AllRows IS
  4      SELECT VALUE(o) FROM obj_tab o;
  5  BEGIN
  6    OPEN c_AllRows;
  7    LOOP
  8      FETCH c_AllRows INTO v_Row;
  9      EXIT WHEN c_AllRows%NOTFOUND;
 10      DBMS_OUTPUT.PUT_LINE(v_Row.f1 || ' ' || v_Row.f2);
 11    END LOOP;
 12    CLOSE c_AllRows;
 13  END;
 14  /

PL/SQL procedure successfully completed.

SQL>
SQL> drop table rel_tab;

Table dropped.

SQL> drop table obj_tab;

Table dropped.

 








Related examples in the same category

1.Display the New Table (SELECT * and SELECT by Column Name)
2.Query object table
3.Use type member function in select statement
4.SELECT Only One Column in the Composite
5.SELECT with a WHERE Clause
6.Query data from table based on object
7.SELECTing Individual Columns in TCROs
8.Use the function we created: use the table alias in our SELECT as well as the qualifier
9.Use * to reference column with user-defined type
10.demonstrates SQL operations on object types.
11.Use %ROWTYPE to select from the relational table.