如何使用 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
How to check for valid oracle table name using sql/plsql
提问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 表名找到的标准如下:
- The table name must begin with a letter.
- The table name can not be longer than 30 characters.
- The table name must be made up of alphanumeric characters or the following special characters: $, _, and #.
- The table name can not be a reserved word.
- 表名必须以字母开头。
- 表名不能超过 30 个字符。
- 表名必须由字母数字字符或以下特殊字符组成:$、_ 和#。
- 表名不能是保留字。
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
回答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 帖子中桌子的同义词)