在 Oracle 查询中设置 FMTONLY ON

发布于 2024-10-01 04:13:24 字数 594 浏览 9 评论 0原文

我想知道 SET FMTONLY ON 是否可以在 Oracle 查询中使用。当我这样使用时:

SET FMTONLY ON select * from department

我收到这样的消息:

第 1 行:跳过 SQLPLUS 命令:SET FMTONLY ON select * from Department

我正在 Oracle 中寻找一条语句,

该语句仅将元数据返回给客户端以测试响应的格式,而无需实际运行查询。

编辑

谢谢....我想要所有类型的查询通用的东西,如果查询包含任何“排序依据”,那么我们无法添加它。如果它是一个插入查询,它应该只验证查询,现在我正在做回滚以验证查询(然后在运行时执行它)SET FMTONLY 帮助我在 SQL 中实现它,在 Oracle 中类似? ??。

并“CREATE TABLE FormatTest AS (SELECT ...) 然后执行 DESCRIBE FormatTest。”我没有得到这个:(

任何帮助表示赞赏。

I'd like to know if SET FMTONLY ON can be used within Oracle queries. When I'm using like this:

SET FMTONLY ON select * from department

I'm getting a message as such:

Line 1: SQLPLUS Command Skipped: SET FMTONLY ON select * from department

I'm looking for a statement in Oracle that

that returns only metadata to the client to test the format of the response without actually running the query.

EDIT

Thanks.... I want something generic for all types of queries, if the query contains any 'order by' then we cannot add this. If it is an insert query it should just validate the query, now I'm doing a roll back to just validate the query (and then execute it at run time) SET FMTONLY helps me achieve it in SQL, something similar in Oracle????.

And "CREATE TABLE FormatTest AS (SELECT ...) and then do a DESCRIBE FormatTest." I didn't get this one :(

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不如归去 2024-10-08 04:13:24

根据设置 FMTONLY ON

仅将元数据返回给客户端。
可以用来测试格式
响应而不实际运行
查询。

没有行被处理或发送到
客户端因为SET时的请求
FMTONLY 已打开。

因此,我猜测结果是:(a) 语句成功,但什么也没有发生; (b) 语句失败,并引发异常。

因此,您可以通过运行EXPLAIN PLAN FOR xxx在Oracle中达到类似的效果,例如:

SQL> EXPLAIN PLAN FOR insert into baddml values (1);
explain plan for INSERT INTO baddml VALUES (1)
                             *
ERROR at line 1:
ORA-00942: table or view does not exist

如果语句成功,则可以假定该语句在语法上是有效的。

According to this, SET FMTONLY ON:

Returns only metadata to the client.
Can be used to test the format of the
response without actually running the
query.

No rows are processed or sent to the
client because of the request when SET
FMTONLY is turned ON.

Therefore, I'm guessing the outcome is that either (a) the statement succeeds, and nothing happens; or (b) the statement fails, and an exception is raised.

Therefore, you could achieve a similar effect in Oracle by running EXPLAIN PLAN FOR xxx, e.g.:

SQL> EXPLAIN PLAN FOR insert into baddml values (1);
explain plan for INSERT INTO baddml VALUES (1)
                             *
ERROR at line 1:
ORA-00942: table or view does not exist

If the statement succeeds, then the statement can be assumed to be syntactically valid.

盗梦空间 2024-10-08 04:13:24

它并不完全相同,但您可以将 WHERE rownum<=1 添加到查询中。它允许您根据一行评估格式。

这有点矫枉过正,但您可以执行CREATE TABLE FormatTest AS (SELECT ...),然后执行DESCRIBE FormatTest

编辑:

根据您最近的编辑,听起来您正在寻找语句验证而不是布局,在这种情况下,Janek Bogucki 或 Jeffrey Kemp 有更好的答案。

It is not quite the same, but you could add WHERE rownum<=1 to your query. It would allow you to assess the format based on one row.

Its a little overkill, but you could do CREATE TABLE FormatTest AS (SELECT ...) and then do a DESCRIBE FormatTest.

EDIT:

Based on your more recent edits it sounds like you are looking for statement validation rather than layout, in which case Janek Bogucki or Jeffrey Kemp have better answers.

×纯※雪 2024-10-08 04:13:24

查看DBMS_SQL.DESCRIBE_COLUMNS。这是将为每列返回的数据,

alt text

这将适用于任何选择语句,例如我通过修改 示例 8:描述列并且它起作用了,

DBMS_SQL.PARSE(c, 'SELECT sysdate, b.* FROM scott.bonus b', DBMS_SQL.NATIVE);

col_type = 12
col_maxlen = 7
col_name = SYSDATE
col_name_len = 7
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 1
col_maxlen = 10
col_name = ENAME
col_name_len = 5
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 1
col_maxlen = 9
col_name = JOB
col_name_len = 3
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 2
col_maxlen = 22
col_name = SAL
col_name_len = 3
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = -127
col_null_ok = true
col_type = 2
col_maxlen = 22
col_name = COMM
col_name_len = 4
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = -127
col_null_ok = true

PL/SQL procedure successfully completed.

Have a look at DBMS_SQL.DESCRIBE_COLUMNS. This is the data that will be returned for each column,

alt text

This will work with any select statement afaik, for example I tried this query by modifying Example 8: Describe Columns and it worked,

DBMS_SQL.PARSE(c, 'SELECT sysdate, b.* FROM scott.bonus b', DBMS_SQL.NATIVE);

col_type = 12
col_maxlen = 7
col_name = SYSDATE
col_name_len = 7
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 1
col_maxlen = 10
col_name = ENAME
col_name_len = 5
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 1
col_maxlen = 9
col_name = JOB
col_name_len = 3
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = 0
col_null_ok = true
col_type = 2
col_maxlen = 22
col_name = SAL
col_name_len = 3
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = -127
col_null_ok = true
col_type = 2
col_maxlen = 22
col_name = COMM
col_name_len = 4
col_schema_name =
col_schema_name_len = 0
col_precision = 0
col_scale = -127
col_null_ok = true

PL/SQL procedure successfully completed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文