Advanced
Checkpoint 5 — org chart as objects
You should now be able to describe schema objects, create and fill object types, work collections and iterate them, and link objects with REFs.
The exercise — object-relational org chart
Step 1 — schema. Model the running project with types:
create type emp_t as object (empno number, ename varchar2(30),
sal number, mgr ref emp_t);
create type emp_list_t as varray(50) of emp_t;
create type dept_t as object (deptno number, dname varchar2(30),
members emp_list_t);
create table emp_obj of emp_t;
create table dept_obj of dept_t;
Step 2 — the program.
- Describe
dept_objviaOCI_TypeInfoGet+TypeInfoGetColumn— print the attribute tree (members → varray → emp_t attrs). - Build one
dept_tprogrammatically:Deptno=20,Members= aemp_list_tcollection with twoemp_telements; bind it intodept_obj. - Fetch it back and walk
MEMBERSwithOCI_Iterator, printing eachENAME/SAL. - For one member, set
mgr = OCI_ObjectGetSelfReference(other_emp_obj)and update. - Dump everything once with
OCI_ObjectToTextfor comparison.
Acceptance checks
select * from dept_objshows the row;select value(m) from dept_obj d, table(d.members) mlists member attrs.- Your program prints the same tree it inserted.
- No handle leaks: every
Get*that yields a handle is freed.
What it exercises
| Skill | Pages |
|---|---|
| TypeInfo describe | 610 |
| Object create/get/set, NULLs | 615–620 |
| Assign/inheritance/self-ref | 625/640 |
Collections + OCI_Iterator |
630/635 |
| End-to-end nested graph | 645 |
Part 6 done — the whole object-relational API is yours. Next: messaging — AQ and change notification.