2011-08-16 42 views
1

我正在以編程方式在DB2服務器和Apache Derby(JavaDB)服務器之間傳輸數據。Apache Derby Lexical Error on#-sign?

DB2服務器有許多列名稱包含井號(#)字符的表。然而,當試圖在德比創建表:

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

我得到以下錯誤:

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

Derby Reference Manual沒有幫助;對於錯誤代碼42X02給出的解釋僅僅是<value>

這是一個簡單的任務,從Derby的列名稱中除去井號,然後將其添加回DB2,但是如果可以的話,我想避免它。

有誰碰巧知道德比根本不容許#字符(爲什麼?),或者如果我做錯了什麼......

回答

2

根據德比參考手冊(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.

所以,COL#看來是無效的,因爲由於#的一個普通的標識符。 "COL#"可能會作爲分隔標識符有效,但我沒有測試過。

+0

很酷,這回答我的問題。謝謝! – BenCole

+0

@Luke Woodward鏈接已損壞。有沒有其他的信息鏈接? – verystrongjoe

+0

@verystrongjoe:奇怪的是,當我幾分鐘前嘗試使用它,但它重定向到另一個URL。我更新了指向我重定向到的URL的鏈接,所以希望它現在能夠正常工作。 –