oracle 从查询设置表单字段的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5186415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:07:21  来源:igfitidea点击:

Setting the value of a form field from a Query

oracleoracle-apex

提问by Roy

I have a form field where one of the values has a default value defined in a an application settings table. The user would see the default value upon display of the create form, but could change it to another value if they wanted prior to saving the new row.

我有一个表单字段,其中一个值具有在应用程序设置表中定义的默认值。用户将在显示创建表单时看到默认值,但如果他们想在保存新行之前将其更改为另一个值。

I don't see any way in the field defaults to specify that the default value is the result of an SQL query (e.g. select default_rate from app_defaults where row_key = 1).

我在字段 defaults 中没有看到任何方式来指定默认值是 SQL 查询的结果(例如,从 app_defaults 中选择 default_rate,其中 row_key = 1)。

Surely this has to be possible, but how?

当然这必须是可能的,但是如何呢?

回答by Roy

As posted to Jeffrey above, final solution can be done completely within APEX but using the Default Value Type = PL/SQL Function Body on the page item.

正如上面发布给 Jeffrey 的,最终解决方案可以完全在 APEX 内完成,但在页面项上使用默认值类型 = PL/SQL 函数体。

DECLARE default_value number(9,2); 
BEGIN 
SELECT deflt_rate INTO default_value FROM app_defaults WHERE row_key = 1; 
RETURN default_value; 
END;

回答by Jeffrey Kemp

You can use the SQL query in a PL/SQL block to assign it directly, e.g.

您可以在 PL/SQL 块中使用 SQL 查询来直接分配它,例如

SELECT default_rate
INTO :myblock.rate
FROM app_defaults
WHERE row_key = 1;