Windows 編寫的 SQL 文件放到 Linux 執行,明明編碼都是 UTF-8,卻拋出 SP2-0734: unknown command beginning "?--create ..."。罪魁禍首是 UTF-8 with BOM。本文完整記錄排查過程、原理分析與兩種修復方案。
--create tablespace declare v_tbs_name varchar2(200):='hytpdtsmsshistorydb'; begin ...
錯誤:
SP2-0734: unknown command beginning "?--create ..." - rest of line ignored. PL/SQL procedure successfully completed.
文件頭幾行明明是註釋或 declare,卻被識別為未知命令「?--create」。
EF BB BF,用於標識字節序。?(或亂碼),解析器以為是非法命令開頭。file 命令可鑒別:
$ file *.sql crt_tab_xxx.sql: UTF-8 Unicode (with BOM) text normal.sql: UTF-8 Unicode text
vim crt_tab_xxx.sql :set fileencoding=utf-8 :set nobomb :wq
:set fileencoding=utf-8 確保目標編碼。:set nobomb 移除 BOM 標記。:wq 保存退出。$ file crt_tab_xxx.sql crt_tab_xxx.sql: UTF-8 Unicode text # 不再顯示 with BOM $ sqlplus user/pass @crt_tab_xxx.sql -- 正常執行,無 SP2-0734
.editorconfig 設置 insert_final_newline = true、charset = utf-8、bom = false。file 或 grep -r $'\xEF\xBB\xBF' 檢查,發現 BOM 直接失敗。一個隱形的 BOM,能讓整條部署鏈路卡住半天。養成「無 BOM UTF-8」習慣,是跨平台開發的基本功。