Oracle

如何在替換變數中轉義點(。)

  • October 5, 2021

我有一個名為的變數ERROR_DETAIL,在我的文件中file.sql我有這一行:

SELECT 'error detail : &ERROR_DETAIL ' FROM DUAL;

ERROR_DETAIL一旦執行 sqlplus 在變數包含例如以下錯誤時抱怨'the field x.y is mandatory'

ORA-00923: FROM keyword not found where expected

我知道x.y(視為table.column)的問題。

我嘗試使用雙引號,但出現無效標識符錯誤

我也不能set define off

這是我收到的腳本錯誤:

腳本中的錯誤消息

SELECT q'{error detail : &ERROR_DETAIL }' FROM DUAL;
SQL> SELECT 'error detail : ' || &ERROR_DETAIL from dual;
Enter value for error_detail: 'the field x.y is mandatory'
old   1: SELECT 'error detail : ' || &ERROR_DETAIL from dual
new   1: SELECT 'error detail : ' || 'the field x.y is mandatory'  from dual

'ERRORDETAIL:'||'THEFIELDX.YISMANDATORY'
-----------------------------------------
error detail : the field x.y is mandatory

SQL>

引用自:https://dba.stackexchange.com/questions/300589