I am new to oracle database, I have about 100 tables which starts with prefix like PRE:
CREATE TABLE PRE1 ( name VARCHAR2(15), value VARCHAR2(15)) CREATE TABLE PRE2 ( name VARCHAR2(15), value VARCHAR2(15)) CREATE TABLE PRE3 ( name VARCHAR2(15), value VARCHAR2(15)) ... .....etc
I need in java to select name and values from all tables which start with prefix PRE; something like this:
select name, value from all tables which start with **PRE**
is this possible?
Now I would like to create select statement in java to get name and value from all tables which starts with PRE
Advertisement
Answer
If you really need this, the following can be a way:
SQL> CREATE TABLE PRE1 ( 2 name VARCHAR2(15), 3 value VARCHAR2(15)) 4 / Table created. SQL> CREATE TABLE PRE2 ( 2 name VARCHAR2(15), 3 value VARCHAR2(15)) 4 / Table created. SQL> CREATE TABLE PRE3 ( 2 name VARCHAR2(15), 3 value VARCHAR2(15)) 4 / Table created. SQL> select table_name from user_tables where table_name like 'PRE%'; TABLE_NAME ------------------------------ PRE1 PRE2 PRE3 SQL>
Here I user USER_TABLES
, while you may need ALL_TABLES
or DBA_TABLES
, depending on your needs and/or permissions.
However, at first sight, this does not seem the best possible design, so maybe you would re-consider it.