Intermediate
Checkpoint 4 — employee profiles
You should now be able to work with every Oracle data type the library exposes:
strings/charsets, dates, timestamps, intervals, exact numbers, RAW, vectors, LOBs,
BFILEs, XMLType, JSON — PL/SQL-only types (BOOLEAN, RECORD) and
schema-level user-defined types (OCI_Object/Object). Collections and REFs
get their own deep dive in Part 6.
The exercise — profile service
Extend the employee schema (tutorial-schema.sql plus):
alter table employees add (profile json, photo blob, resume bfile);
create table dept_docs (deptno number, doc xmltype, note varchar2(4000));
create directory docs_dir as '/tmp/docs';
Write a program that:
- JSON profile — for each employee, build a mutable
OCI_Jsonwith{"name":…,"hiredate":…,"skills":[…]},LoadText/node ops to fill it, thenOCI_StatementBindJsonintoprofile. - Photo — stream a small PNG into
photoviaOCI_LobCreate/LobWritein 32 KB chunks; read it back withLobReadand compare checksums. - Resume BFILE —
OCI_FileSetName(DOCS_DIR, 'smith.txt'), verifyFileExists,FileOpen+FileReadit, bind intoresume. - XML doc —
xmltype(:x)insert intodept_docsvia string bind, fetch withOCI_ResultsetGetXmlTypeand printGetContent. - Tenure report —
OCI_DateDaysBetween(sysdate, hiredate)per employee; format hiredate withOCI_DateToText.
Stretch goals
- Validate
profileagainst a JSON schema (OCI_JsonValidate, 23ai). - Store a 3-dim "skills vector" per employee (
OCI_Vector) and rank similarity. - Extract
profile.skillsper row viaOCI_JsonNodeGetByPathand index them in anOCI_HashTablename→empno map (bridge to page 825).
What it exercises
| Skill | Pages |
|---|---|
| Charset-safe strings & formats | 510 |
| Dates / timestamps / intervals | 515–525 |
| Exact numbers, RAW | 530/535 |
| Vectors (23ai) | 540 |
| LOB chunked I/O | 550/555 |
| BFILE | 560 |
| XMLType | 565 |
| JSON doc + DOM | 570/575 |
Part 2 done — you can now move any Oracle value in and out. Next: the object-relational API (types, objects, collections, REFs).