Oracle 绑定参数占位符中允许使用哪些字符?

发布于 2024-12-09 12:18:21 字数 201 浏览 0 评论 0原文

谁能指出我在哪里列出了绑定变量名称允许的字符?我花了几个小时研究 Oracle SQL 文档,但毫无结果。

我的意思是以下内容中的“:id”:

SELECT * FROM mytable WHERE id = :id

例如,可以在那里使用点,例如“:some.id”吗?它的功能与没有点的版本完全相同吗?

Could anyone please point me to where the characters allowed for a bind variable name are listed? I've spent several hours digging through Oracle SQL docs to no avail.

I mean ":id" in the following:

SELECT * FROM mytable WHERE id = :id

E.g. can a dot be used there like ":some.id"? Will it function exactly like the version without the dot?

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

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

发布评论

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

评论(2

缱绻入梦 2024-12-16 12:18:21

这些页面都声明绑定变量必须是“合法的 Oracle 标识符”
我发现的文档并没有具体说明点可以
成为合法标识符的一部分。我可以在两者中使用点
表名和绑定变量名,但看起来是这样
不推荐。

具有绑定变量命名约定的页面
(这些页面规定绑定变量必须是合法标识符):

http://www. utoug.org/i/doc/concept_bind_var.htm

http://docs.oracle.com/cd/E23903_01/ doc.41/e21674/concept_ses_val.htm#BEIEGCCC

页面描述法律标识符:
http://docs.oracle.com/cd/B19306_01/ server.102/b14200/sql_elements008.htm

我找不到任何关于此的内容页面显示点是合法的
标识符(EG 表或绑定变量名称)的一部分,DB 链接中除外。
尽管 $ 和 # 是合法的,但我们甚至不推荐使用它们,所以“.”
可能有效,但显然不推荐(甚至没有提到合法
本页)

绑定变量名称必须与项目名称相对应。
绑定变量名称不区分大小写。
绑定变量名称不能超过 30 个字符(即它们必须是有效的 Oracle 标识符)。

我知道一个有效的 ORACLE 标识符(基于 ORACLE 的定义
合法标识符)不能以数字开头,
并且可以有一些特殊字符,例如 $ 和 .但如果有
特殊字符标识符必须用双引号引起来。

我能够获得一个带有点的标识符来在绑定中工作
变量,但我必须在绑定周围加上双引号
当绑定变量中有一个点时。

create or replace function F0416B
RETURN VARCHAR2
is
    V_STMT    VARCHAR2(1999);
    V_RESULT  VARCHAR2(1999);
BEGIN 
    V_STMT := 'INSERT INTO TEST0411(FIELD1, FIELD2) VALUES ( :"A.1" , :"A.2")';
    EXECUTE IMMEDIATE V_STMT USING  'AS201', 'AS202';
    RETURN 'INSERT-OK';
    COMMIT;
EXCEPTION
WHEN OTHERS THEN RETURN SQLERRM;
END;    

#这可能有效,但根据上述文档,句点/点
在绑定变量或其他对象名称中不合法/推荐...

#这是ORACLE模式对象命名页面上的句子,即
告诉我这一点:

不带引号的标识符只能包含数据库字符集中的字母数字字符以及下划线 (_)、美元符号 ($) 和井号 (#)。数据库链接还可以包含句点 (.) 和“at”符号 (@)。 Oracle 强烈建议您不要在不带引号的标识符中使用 $ 和 #。

These pages both state bind variables must be "legal Oracle identifiers"
The documentation I found doesn't specifically say that a dot can
be part of a legal identifer. I was able to use a dot in both
a table name and as a bind variable name, but it looks like it is
not recommended.

PAGES THAT HAVE BIND VARIABLE NAMING CONVENTIONS
(These pages state a bind variable must be a legal identifier):

http://www.utoug.org/i/doc/concept_bind_var.htm

http://docs.oracle.com/cd/E23903_01/doc.41/e21674/concept_ses_val.htm#BEIEGCCC

PAGE THAT DESCRIBES LEGAL IDENTIFIERS:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm

I could not find anything on this page that says that a dot is a legal
part of an identifier (E.G. table or bind variable name) except in a DB link.
Even though $ and # are legal, they are not even recommended, so "."
may work but is obviously not recommended (not even mentioned as legal on
this page)

Bind variable names must correspond to an item name.
Bind variable names are not case-sensitive.
Bind variable names cannot be longer than 30 characters (that is, they must be a valid Oracle identifier).

I know that a valid ORACLE identifer (based on ORACLE's definition
of a legal identifier) cannot start with a number,
and can have SOME special characters like $ and . but if there are
special characters the identifier MUST be in double quotes.

I was able to get an identifier with a dot to work in a bind
variable, but I had to put double quotes around the bind
variable when the bind variable had a dot in it.

create or replace function F0416B
RETURN VARCHAR2
is
    V_STMT    VARCHAR2(1999);
    V_RESULT  VARCHAR2(1999);
BEGIN 
    V_STMT := 'INSERT INTO TEST0411(FIELD1, FIELD2) VALUES ( :"A.1" , :"A.2")';
    EXECUTE IMMEDIATE V_STMT USING  'AS201', 'AS202';
    RETURN 'INSERT-OK';
    COMMIT;
EXCEPTION
WHEN OTHERS THEN RETURN SQLERRM;
END;    

#This may work but according to the above documentation a period/dot
in a bind variable or other object name is not legal/recommended...

#This is the sentence on the ORACLE schema object naming page that is
telling me this:

Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Database links can also contain periods (.) and "at" signs (@). Oracle strongly discourages you from using $ and # in nonquoted identifiers.

够钟 2024-12-16 12:18:21

我也很难找到官方的 Oracle 文档: http://docs.oracle.com/cd/E14072_01/appdev.112/e10646/oci04sql.htm#i420655

最重要的是,您可以引用占位符(: “_normallyinvalid”),然后前面链接中列出的大多数规则就不再相关。我找不到任何 Oracle 文档提供此建议;只是互联网上的提示。

I also had trouble finding the official Oracle doc for this: http://docs.oracle.com/cd/E14072_01/appdev.112/e10646/oci04sql.htm#i420655

On top of that, it turns out that you can quote placeholders (:"_normallyinvalid") and then most of the rules listed in the preceding link stop being relevant. I couldn't find any Oracle doc offering this suggestion; just hints around the internet.

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