Apache Derby # 符号上出现词法错误?

发布于 2024-11-29 15:32:46 字数 629 浏览 5 评论 0原文

我正在以编程方式在 DB2 服务器和 Apache Derby (JavaDB) 服务器之间传输数据。

DB2 服务器有许多表,其列名称中包含井号 (#) 字符。但是,当尝试在 Derby 中创建表时:

CREATE TABLE LIBNAME.TABNAME  
(COL# decimal(3,0),  
REC# decimal(5,0),  
DESC char(30,0),  
SDSC char(10,0));

我收到以下错误:

错误 42X02:第 1 行第 38 列出现词法错误。遇到:“#”(35),之后:“”

Derby 参考手册 没有帮助;错误代码 42X02 的给出的解释很简单

从 Derby 的列名称中删除井号然后将其添加回 DB2 是一个简单的任务,但我想避免如果可以的话。

有谁知道 Derby 是否根本不允许使用 # 字符(为什么?)或者我是否做错了什么......

I'm programmatically transferring data between a DB2 server and an Apache Derby (JavaDB) server.

The DB2 server has a number of tables with column names that include the pound sign (#) character. However, when trying to create tables in Derby:

CREATE TABLE LIBNAME.TABNAME  
(COL# decimal(3,0),  
REC# decimal(5,0),  
DESC char(30,0),  
SDSC char(10,0));

I get the following error:

ERROR 42X02: Lexical error at line 1, column 38. Encountered: "#" (35), after : ""

The Derby Reference Manual is no help; the given explanation for error code 42X02 is simply <value>

It's a simple task to remove the pound sign from the column names for Derby and then add it back for DB2, but I'd like to avoid it if I can.

Does anyone happen to know if Derby simply doesn't allow the # character (and why?) or if I'm doing something wrong...

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

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

发布评论

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

评论(1

南渊 2024-12-06 15:32:46

根据Derby参考手册(规则对于 SQL92 标识符):

普通标识符是没有用双引号括起来的标识符。定界标识符是用双引号括起来的标识符。

普通标识符必须以字母开头,并且只能包含字母、下划线字符 (_) 和数字。允许的字母和数字包括所有 Unicode 字母和数字,但 Derby 不会尝试确保标识符中的字符在数据库的区域设置中有效。

分隔标识符可以包含双引号内的任何字符。括起来的双引号不是标识符的一部分;它们仅用于标记其开始和结束。分隔标识符末尾的空格无关紧要(被截断)。 Derby 将定界标识符中的两个连续双引号翻译为一个双引号,即“翻译后的”双引号成为定界标识符中的一个字符。

因此,由于 #COL# 作为普通标识符似乎无效。 "COL#" 作为分隔标识符可能是有效的,但我还没有对此进行测试。

According to the Derby reference manual (Rules for SQL92 Identifiers):

Ordinary identifiers are identifiers not surrounded by double quotation marks. Delimited identifiers are identifiers surrounded by double quotation marks.

An ordinary identifier must begin with a letter and contain only letters, underscore characters (_), and digits. The permitted letters and digits include all Unicode letters and digits, but Derby does not attempt to ensure that the characters in identifiers are valid in the database's locale.

A delimited identifier can contain any characters within the double quotation marks. The enclosing double quotation marks are not part of the identifier; they serve only to mark its beginning and end. Spaces at the end of a delimited identifier are insignificant (truncated). Derby translates two consecutive double quotation marks within a delimited identifier as one double quotation mark-that is, the "translated" double quotation mark becomes a character in the delimited identifier.

So, COL# appears to be invalid as an ordinary identifier because of the #. "COL#" would probably be valid as a delimited identifier, but I haven't tested this.

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