Using Object Types in Database Tables
A constructor is a built-in method for the object type and we use it to insert data to the table.
SQL> CREATE TYPE t_emp AS OBJECT (
2 id INTEGER,
3 name VARCHAR2(10),
4 sal NUMBER(5, 2),
5 hiredate DATE,
6 MEMBER FUNCTION get_hire_date RETURN DATE
7 );
8 /
Type created.
SQL>
SQL> CREATE TYPE BODY t_emp AS
2 MEMBER FUNCTION get_hire_date RETURN DATE IS
3 v_date DATE;
4 BEGIN
5 SELECT hiredate INTO v_date FROM dual;
6 RETURN v_date;
7 END;
8 END;
9 /
Type body created.
SQL>
SQL> CREATE TABLE emp(
2 emp t_emp,
3 dept INTEGER
4 );
Table created.
SQL>
SQL>
SQL> INSERT INTO emp (emp,dept) VALUES (t_emp(1, 'Peter', 20, '17-DEC-1980'),50);
1 row created.
SQL>
SQL> SELECT * FROM emp;
EMP(ID, NAME, SAL, HIREDATE) DEPT
--------------------------------------
T_EMP(1, 'Peter', 20, '17-DEC-80') 50
SQL>
Home »
Oracle »
PL/SQL »
Oracle »
PL/SQL »
Object Types:
- Creating Object Types
- A type with member function:
- Using DESCRIBE to Get Information on Object Types
- Using Object Types in Database Tables
- Retrieve an individual column object from a table
- Call method from type
- UPDATE/DELETE row based on custom data type
- Object Tables
- VALUE() selects a row from an object table.
- UPDATE Object Table
- DELETE rows from Object Table
- Object table abased on nested types
- Object Identifiers and Object References
- REF type for an object reference
- Retrieve the actual objects stored in an object reference using the DEREF() function,
- Comparing Object Values
Related: