ORA-00911錯誤 解決執行個體

來源:互聯網
上載者:User

ORA-00911錯誤 解決執行個體

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錯誤:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.