UL4ON is a lightweight text-based cross-platform object serialization format.
This Oracle package makes it possible to output UL4ON encoded data that can then be parsed by any of the UL4ON implementations in Python, Java and Javascript.
Define the following Oracle function:
create or replace function ul4on_test return clob as c_out clob; begin ul4on_pkg.begindict(c_out); ul4on_pkg.keystr(c_out, 'firstname', 'John'); ul4on_pkg.keystr(c_out, 'lastname', 'Doe'); ul4on_pkg.keydate(c_out, 'birthday', to_date('2000-02-29', 'YYYY-MM-DD')); ul4on_pkg.key(c_out, 'emails'); ul4on_pkg.beginlist(c_out); ul4on_pkg.str(c_out, '[email protected]'); ul4on_pkg.str(c_out, '[email protected]'); ul4on_pkg.endlist(c_out); ul4on_pkg.enddict(c_out); return c_out; end;
Then you can call this function and parse the result with the following Python code:
import cx_Oracle from ll import ul4on db = cx_Oracle.connect(...) c = db.cursor() c.execute("select ul4on_test from dual") dump = c.fetchone()[0].read() data = ul4on.loads(dump) print(data)
This will print the parsed data:
{ 'firstname': 'John', 'lastname': 'Doe', 'birthday': datetime.date(2000, 2, 29), 'emails': ['[email protected]', '[email protected]'] }
The Python documentation contains more info about UL4ON.
- Walter Dörwald