invalid character error while executing immediate(立即执行时出现无效字符错误)
问题描述
BEGIN
exception
when others then
sqltext2:='insert into ERROR_TABLE_SHREE select '||str||' from dual;';
EXECUTE IMMEDIATE sqltext2;
end;
COMMIT;
我在异常块中收到以下错误
I am getting the below error within Exception block
ORA-00911: invalid character
推荐答案
那里没有字符串(我假设 str 被声明为某种描述的字符).如果你想插入一个字符串,你需要额外的引号,否则在这种情况下它会被解释为一列.类似的东西:
You don't have a string there (I assume str is declared as a character of some description). If you wanted to insert a string you need extra quotes otherwise it'll be interpreted as a column in this instance. Something like:
begin
...
exception
when others then
sqltext2 := 'insert into error_table_shree select '''||str||''' from dual';
execute immediate sqltext2;
end;
commit;
请注意,我已经删除了字符串末尾的分号;这不是必需的(并且可能是您错误的实际原因).
Please note that I've removed the semi-colon from the end of your string; this is not required (and is probably the actual cause of your error).
还有一点值得注意的是,这有点SQL-injectiony... 你应该使用 绑定变量而不是串联;这在文档中有全部描述:
It's also worth noting that this is a bit SQL-injectiony... you should be using bind variables rather than concatenation; this is all described in the documentation:
begin
...
exception
when others then
execute immediate 'insert into error_table_shree select :1 from dual'
using str;
end;
commit;
然而,在这种情况下没有必要使用动态 SQL;你可以简单地插入变量值:
However, there's no need to use dynamic SQL in this context; you could simply insert the variable value:
begin
...
exception
when others then
insert into error_table_shree values (str);
end;
commit;
最后,我有点担心你的COMMIT;以这种方式处理错误后提交是不寻常的.没有更多上下文就不可能确定,但在 自主交易
Lastly, I am slightly concerned about your COMMIT; it's unusual to commit after handling an error in this manner. Without more context it's impossible to be certain but it would be more normal for error logging to be performed in an autonomous transaction
这篇关于立即执行时出现无效字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:立即执行时出现无效字符错误
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
