UPDATE/DELETE row based on custom data type
CREATE TABLE emp(
emp t_emp,
dept INTEGER
);
CREATE TYPE t_emp AS OBJECT (
id INTEGER,
name VARCHAR2(10),
sal NUMBER(5, 2),
hiredate DATE,
MEMBER FUNCTION get_hire_date RETURN DATE
);
/
CREATE TYPE BODY t_emp AS
MEMBER FUNCTION get_hire_date RETURN DATE IS
v_date DATE;
BEGIN
SELECT hiredate INTO v_date FROM dual;
RETURN v_date;
END;
END;
/
INSERT INTO emp (emp,dept) VALUES (t_emp(1, 'Peter', 20, '17-DEC-1980'),50);
SQL> UPDATE emp p
2 SET p.emp.name = 'Tom'
3 WHERE p.emp.id = 1;
1 row updated.
SQL>
SQL> select * from emp;
EMP(ID, NAME, SAL, HIREDATE) DEPT
------------------------------------------------
T_EMP(1, 'Tom', 20, '17-DEC-80') 50
SQL>
SQL> DELETE FROM emp p WHERE p.emp.id = 1;
1 row deleted.
SQL>
SQL> select * from emp;
no rows selected
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: