ORA-00911錯誤,ora00911

來源:互聯網
上載者:User

ORA-00911錯誤,ora00911

ORA-00911,"911"看著很霸氣的錯誤號碼,雖然我還是Oracle的初學者,但每次碰到一個未見過的ORA錯誤號碼後,都有一種查案的趕腳,根據錯誤號碼、OERR、相關錯誤資訊,判斷錯誤原因以及找到解決方案或替代方案,雖然大部分可能還是參考前輩或官方,但碰到一次後,至少是似曾相識了,再次碰到時即使不記得,大概也能有個方向。


話說回來,這個ORA-00911的錯誤,是在一段用JAVA寫的測試案例中碰到的,

...

private static final String SQL_INSERT_TBL = "insert into tbl (id, ...) "
            + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, SYSDATE);";

報的是這段SQL有這個錯誤。


看看錯誤描述:

ORA-00911 invalid character
Cause: Special characters are valid only in certain places. If special characters other than $, _, and # are used in a name and the name is not enclosed in double quotation marks ("), this message will be issued. One exception to this rule is for database names; in this case, double quotes are stripped out and ignored.
Action: Remove the invalid character from the statement or enclose the object name in double quotation marks.

很明顯,這個錯誤主要是因為SQL中包含了非法字元,解析的時候出現報錯。


但這個SQL很簡單啊,就是一條INSERT語句,將他拷貝到plsql developer中好像是可以的啊,奇怪了。

調試很多次後,忽然發現,定義中結尾有個“;”,難道是這個的問題?

於是首先在plsql developer中執行INSERT語句,結尾帶了兩個“;”,果然報了這個ORA-00911錯誤。

修改代碼中的語句:

private static final String SQL_INSERT_TBL = "insert into tbl (id, ...) "
            + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, SYSDATE)";

果然,正常回顯了。


一個看似簡單,但挑錯較麻煩的錯誤,值得自己的總結。

1. OERR錯誤描述是基準,要順著這個方向排查,基本方向可以明確

2. 代碼中出現的SQL錯誤,可以在plsql developer等工具中重新執行來類比錯誤,但一定要和代碼中的SQL語句一樣,這裡我可能拷貝的時候就沒有帶結尾的;,以至於第一次沒有發現這個錯誤,總之一句話,除了需要判斷大方向,最重要的一點就是細心,不要放過任何一個小的細節


可以參考楊長老曾經一樣遇到的這個ORA-00911錯誤:http://blog.itpub.net/4227/viewspace-68615/

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.