使用 `SELECT` 调用函数

Using `SELECT` to call a function(使用 `SELECT` 调用函数)
本文介绍了使用 `SELECT` 调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔会遇到使用 SELECT...INTO...FROM DUAL 调用函数的例子 - 例如:

I occasionally encounter examples where SELECT...INTO...FROM DUAL is used to call a function - e.g.:

SELECT some_function INTO a_variable FROM DUAL;

使用

代替

a_variable := some_function;

我对此的看法是,这不是一个好的做法,因为 A) 它不清楚正在调用一个函数,B) 它的效率低下,因为它强制从 PL/SQL 引擎转换到 SQL 引擎(也许今天问题不大).

My take on this is that it's not good practice because A) it makes it unclear that a function is being invoked, and B) it's inefficient in that it forces a transition from the PL/SQL engine to the SQL engine (perhaps less of an issue today).

谁能解释为什么会这样做,例如这在早期的 PL/SQL 编码中是否有必要以调用函数?我正在查看的代码可能最早可以追溯到 Oracle 8.

Can anyone explain why this might have been done, e.g. was this necessary in early PL/SQL coding in order to invoke a function? The code I'm looking at may date from as early as Oracle 8.

感谢任何见解.

推荐答案

这种做法可以追溯到 之前 PLSQL 和 Oracle 7.如前所述,在 Oracle7 中可以进行赋值(当然还有最佳实践).

This practice dates from before PLSQL and Oracle 7. As already mentioned assignment was possible (and of course Best Practice) in Oracle7.

在 Oracle 7 之前,有两个广泛使用的工具需要使用 Select ... into var from dual;

Before Oracle 7 there were two widely used Tools that needed the use of Select ... into var from dual;

一方面,曾经有一个名为 RPT 的 Oracle 工具,它是某种报告生成器.RPT 可用于创建批处理.它有两种宏,可以组合起来实现我们今天使用 PLSQL 的功能.我的第一个 Oracle 工作涉及调试由一个程序生成的 PLSQL,该程序采用 RPT 批处理并将它们自动转换为 PLSQL.2000 年之后不久,我扔掉了我唯一的 RPT 手册.

On the one hand there used to be an Oracle Tool called RPT, some kind of report generator. RPT could be used to create batch processes. It had two kinds of macros, that could be combined to achieve what we use PLSQL for today. My first Oracle job involved debugging PLSQL that was generated by a program that took RPT batches and converted them automatically to PLSQL. I threw away my only RPT handbook sometime shortly after 2000.

另一方面,有 Oracle Forms 2.x 及其菜单组件.Oracle Menu 中的上下文切换通常是通过 Select ... from dual; 我还记得当我发现一个难以处理的 Bug 是由总共 6 引起的时,我是多么自豪strong> 表 Dual 中的记录.

On the other hand there was Oracle Forms 2.x and its Menu component. Context switching in Oracle Menu was often done with a Select ... from dual; I still remember how proud I was when I discovered that an untractable Bug was caused by a total of 6 records in table Dual.

很抱歉,我无法证明其中的任何一个,但现在是回想过去的时候,知道答案真的很有趣.

I am sorry to say that I can not proof any of this, but it is the time of year to think back to the old times and really fun to have the answer.

这篇关于使用 `SELECT` 调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)