首页 > 解决方案 > oracle apex 更新语句(使用选择列表和 text_field 的返回值)

问题描述

update student set :P9_COLUMNNAME = :P9_VALUE

这是我的尝试,但它返回

ORA06550 错误 user.table 列、table.column 或列规范无效。

通常,当我从用户输入设置值时,它运行良好,但这次 oracle 不允许我以这种方式传递列值。有没有人遇到过同样的问题?提前致谢

psP9_columnname是一个选择列表,p9_value是一个文本字段

在此处输入图像描述

标签: oracleoracle-apex

解决方案


UPDATE应该用于更新表格列,而不是 Apex 应用程序中的项目。

所以,要么

update student set 
  some_column = :P9_VALUE
  where ...   --> don't forget the WHERE clause, otherwise you'll update the whole table

或者

:P9_COLUMNNAME := :P9_VALUE;

如果选择列表项包含列名,则必须使用动态 SQL。例如:

declare
  l_str varchar2(200);
begin
  l_str := 'update student set ' || :P9_COLUMNNAME || ' = ' || :P9_VALUE;
  execute immediate l_str;
end;

不要忘记where条款!


推荐阅读