sql - How to select a table dynamically with HSQLDB and Hibernate? -
i have table references other tables. stored table name , entity id.
like this:
ref_table id | table_name | refid -------+------------+------- 1 | test | 6 2 | test | 9 3 | other | 5
now try formulate sql/function returns correct entities correct tables. like:
select * resolveid(3)
i expect entity id "5" table "other". possible? guess can stored procedure (create function). function have inspect "ref_table" , return name of table use in sql statement ... how exactly?
if want use resuling entities in select statements or joins, should use create function returns table ( .. )
there limitation in hsqldb routines disallows dynamically creating sql. therefore body of create function may include case or if else block switches pre-defined select statement based on input value (1, 2, 3, ..).
the details of create function documented here: http://hsqldb.org/doc/2.0/guide/sqlroutines-chapt.html#n12cc4 there 1 example sql function returns table.
Comments
Post a Comment