ORA-01747:无效的user.table.column,table.column或列规范 [英] ORA-01747: invalid user.table.column, table.column, or column specification
问题描述
在循环中调用立即执行时得到上述错误
Get the above error when the execute immediate is called in a loop
Update CustomersPriceGroups set 1AO00=:disc Where cuno=:cuno
Parameters: disc=66 cuno=000974
Update CustomersPriceGroups set 1AP00=:disc Where cuno=:cuno
Parameters: disc=70.5 cuno=000974
Update CustomersPriceGroups set 1AQ00=:disc Where cuno=:cuno
Parameters: disc=66 cuno=000974
Update CustomersPriceGroups set 1ZA00=:disc Where cuno=:cuno
Parameters: disc=60 cuno=000974
这是什么意思?
这是代码片段
c:=PriceWorx.frcPriceListCustomers('020','221');
LOOP
fetch c into comno,cuno,nama,cpls;
exit when c%notfound;
dbms_output.put_Line(cuno);
g:=priceWorx.frcPriceListItemGroups('020','221');
d:=priceworx.frcCustomerDiscounts('020','221',cuno);
loop
fetch g into comno,cpgs,n;
fetch d into comno,cpls,cuno,cpgs,stdt,tdat,qanp,disc,src;
--dbms_output.put(chr(9)||cpgs);
sQ:='Update saap.CustomersPriceGroups set "'|| trim(cpgs)||'"=:disc '
|| ' Where cuno=:cuno';
execute immediate sQ using disc,cuno;
commit;
dbms_output.put_line( sQ );
dbms_output.put_line( chr(9)||'Parameters: disc='|| disc||' cuno='||cuno);
exit when g%notfound;
end loop;
close g;
close d;
end loop;
推荐答案
Unquoted identifiers must begin with an alphabetic character (see rule 6 here). You're trying to assign a value to a column with a name starting with a number 1AO00
, 1AP00
etc.
在没有看到CustomersPriceGroups
的表定义的情况下,我们不知道它是否具有带有这些名称的列.如果是这样,则必须已将它们创建为带引号的标识符.如果是这样,您将不得不在所有地方都用引号引用它们,这是不理想的-使代码更难阅读,使这样的错误更容易出现,并且很难发现错误所在.甚至Oracle在同一页面上也说过:
Without seeing the table definition for CustomersPriceGroups
we don't know if it has columns with those names. If it does then they must have been created as quoted identifiers. If so you'll have to refer to them (everywhere) with quotes, which is not ideal - makes the code a bit harder to read, makes it easy to make a mistake like this, and can be hard to spot what's wrong. Even Oracle say, on the same page:
注意:Oracle不建议对数据库使用带引号的标识符 对象名称.这些带引号的标识符被SQL * Plus接受,但是 当使用其他管理数据库的工具时,它们可能无效 对象.
Note: Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be valid when using other tools that manage database objects.
在您的代码中,分配sQ
时似乎使用了引号,但显示的输出却没有.但它也没有saap.
模式标识符.那可能是因为您没有运行您认为的代码版本,但可能只是
如果重新输入数据而不是粘贴数据,则会丢失-您也不会显示c.cuno
的早期输出.但是,也有可能列名称的大小写有误.
In you code you appear to be using quotes when you assign sQ
, but the output you show doesn't; but it doesn't have the saap.
schema identifier either. That may be because you're not running the version of the code you think, but might just have been
lost if you retyped the data instead of pasting it - you're not showing the earlier output of c.cuno
either. But it's also possible you have, say, the case of the column name wrong.
如果execute
引发错误,那么您不会在循环中看到该命令正在执行的时间,因为调试是在此之后进行的-您看到的是成功的值,而不是被破坏的值.您需要检查函数返回的所有值.我怀疑g
返回的cpgs
值实际上不是有效的列名.
If the execute
is throwing the error, you won't see the command being executed that time around the loop because the debug comes after it - you're seeing the successful values, not the one that's breaking. You need to check all the values being returned by the functions; I suspect that g
is returning a value for cpgs
that actually isn't a valid column name.
如@nineside所说,显示更多信息,尤其是完整的异常消息,将有助于发现问题所在.
As @ninesided says, showing more information, particularly the full exception message, will help identify what's wrong.
这篇关于ORA-01747:无效的user.table.column,table.column或列规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!