Why is SET DEFINE OFF not working for the colon (:) character?

穿精又带淫゛_ 提交于 2019-12-12 05:14:10

问题


I have a script I'm trying to run via sqlplus. At the top of the script, I have "SET DEFINE OFF" set. However, when I run it, I'm receiving this error:

SP2-0552: Bind variable "CHANDAWALA" not declared.

I believe this is happening because I have a couple update statements that include colons within a string like this:

UPDATE ADDRESS SET ADDRESS_STREET_LINE1 = 'Moh: Chandawala'...
UPDATE ADDRESS SET ADDRESS_STREET_LINE1 = 'Moh:chandawala'...

So it's treating them like bind variables. I was under the impression that SET DEFINE OFF would make it treat anything within a quoted string as characters and not interpret anything within, including perceived bind variables.

This obviously isn't the case - So in this situation, what am I supposed to do? Do I have to escape these manually?

Thanks.

EDIT - The posted question at When or Why to use a "SET DEFINE OFF" in Oracle Database doesn't help me since that person is trying to escape ampersands for variable substitution, and not colons as bind variables. I'm looking for a way to tell the client to ignore anything (including colons) in quoted strings.

EDIT - Okay, so it sounds like Oracle shouldn't be interpreting that as a bind variable within quotes. So now the question is, why is it doing that?


回答1:


Set Define Off is a SQLPlus command and it prevents SQLPlus from treating & as a special character. & is also specific to SQLPlus and have no meaning outside it.

When define is on, the SQLPlus replaces the substitution variables with actual values and then pass it to the Oracle SQL engine.

On the other hand, : are real bind variable that only Oracle SQL engine recognises and look for a to-be-bound value. The : are not recognized as bind meta character by SQLPlus and is passed as such to the SQL engine.




回答2:


I cannot duplicate your issue. I created a table called dually with a column of a single character. When I attempt to run the update statement, no substitution is permitted.

SQL> UPDATE brianl.dually
  2         SET dummy   = ':x';
       SET dummy   = ':x'
                     *
ERROR at line 2:
ORA-12899: value too large for column "BRIANL"."DUALLY"."DUMMY" (actual: 2,
maximum: 1)

Have you tried using concatenation?

UPDATE ADDRESS SET ADDRESS_STREET_LINE1 = 'Moh' || ':' || Chandawala'


来源:https://stackoverflow.com/questions/43876365/why-is-set-define-off-not-working-for-the-colon-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!