如何使用 sql/plsql 检查有效的 oracle 表名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1311996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:50:32  来源:igfitidea点击:

How to check for valid oracle table name using sql/plsql

oracle

提问by Rene

I need to check if a string contains a valid Oracle table name using sql/plsql. The criteria I found for a Oracle table name are these:

我需要使用 sql/plsql 检查字符串是否包含有效的 Oracle 表名。我为 Oracle 表名找到的标准如下:

  1. The table name must begin with a letter.
  2. The table name can not be longer than 30 characters.
  3. The table name must be made up of alphanumeric characters or the following special characters: $, _, and #.
  4. The table name can not be a reserved word.
  1. 表名必须以字母开头。
  2. 表名不能超过 30 个字符。
  3. 表名必须由字母数字字符或以下特殊字符组成:$、_ 和#。
  4. 表名不能是保留字。

Criteria 1,2,3 don't seem so hard to tackle. But what about point 4? What are my options without trying to actually create a table with the given name and then see if it succeeds or fails.

标准 1、2、3 似乎并不难解决。但是第 4 点呢?如果不尝试实际创建具有给定名称的表,然后查看它是成功还是失败,我的选择是什么。

回答by Jim Hudson

Oracle has a built-in that's useful for checking whether a SQL Name is valid. That's especially useful when building dynamic queries where you need to prevent SQL Injection.

Oracle 有一个内置函数,可用于检查 SQL 名称是否有效。这在构建需要防止 SQL 注入的动态查询时特别有用。

Check out the dbms_assert.simple_sql_namebuilt-in, and see the Oracle white paper at How to Write Injection Proof PL/SQLfor more details.

查看内置的dbms_assert.simple_sql_name,并查看 Oracle 白皮书How to Write Injection Proof PL/SQL了解更多详细信息。

v$reserved_words is also useful, as others have noted.

正如其他人所指出的, v$reserved_words 也很有用。

回答by Ian Carpenter

For SQL reserved words you can check v$reserved_words. Here the link from the documentation

对于 SQL 保留字,您可以检查 v$reserved_words。这里是文档中的链接

回答by cagcowboy

I have a SQL_RESERVED_WORDS table that I check against.

我有一个用于检查的 SQL_RESERVED_WORDS 表。

EDIT:

编辑:

(I lied... it was just a SYNONYMN for the table in carpenteri's post)

(我撒谎了……这只是 carpenteri 帖子中桌子的同义词)

回答by Gren

It is a fairly large listto check. Can you simply add a default prefix to the tables and avoid these problems all together? user_xxx

这是一个相当大的清单,需要检查。您能否简单地向表中添加一个默认前缀并同时避免这些问题?用户_xxx