SQL/JDBC:对变量表名进行选择查询
我正在使用 Oracle DB,我想编写一个 SQL 查询,然后可以使用 JDBC 调用该查询。我对 SQL 不太熟悉,所以如果有人可以帮助我,那就太好了!问题就在这里。我有一个表 MY_TABLE ,其中包含其他表的列表,我想仅保留非空表和名称以特定字符串开头的表。 我编写的查询如下:
select TABLE_NAME
from MY_TABLE
where TABLE_NAME like '%myString%'
and (select count(*) from TABLE_NAME where rownum=1)<>0
order by TABLE_NAME;`
问题来自第二个 SELECT,但我不知道如何使用 TABLE_NAME 值。
有人有主意吗?
谢谢。
[从评论添加]
实际上,我需要测试 ALL_CATALOG 表中包含的 V$ 视图。但是,如果我能找到另一个表,其中也包含所有这些视图并且也包含 NUM_ROWS 列,那就太完美了!
I'm using Oracle DB and I would like to write a SQL query that I could then call with JDBC. I'm not very familiar with SQL so if someone can help me, that could be great ! Here is the problem. I have a table MY_TABLE wich contains a list of another tables, and I would like to keep only the nonempty tables and those that their names start by a particular string.
The query I wrote is the following :
select TABLE_NAME
from MY_TABLE
where TABLE_NAME like '%myString%'
and (select count(*) from TABLE_NAME where rownum=1)<>0
order by TABLE_NAME;`
The problem comes from the second SELECT, but I don't know how can I do to use the TABLE_NAME value.
Does someone have an idea ?
Thanks.
[Added from comments]
Actually, I need to test the V$ views contained in the ALL_CATALOG table. But if I can find another table where all these views are contained too and with a NUM_ROWS column too, it would be perfect !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准版本的 SQL 不允许您用变量值或占位符替换查询的“结构元素”,例如表名或列名。
有几种方法可以解决这个问题。
Standard versions of SQL do not allow you to replace 'structural elements' of the query, such as table name or column name, with variable values or place-holders.
There are a few ways to approach this.
可以使用oracle视图USER_TABLES吗?那么查询就会容易得多
Can you use oracle view USER_TABLES? then query will be much easier