使用`SELECT`来调用一个函数 [英] Using `SELECT` to call a function

查看:268
本文介绍了使用`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.

任何见解都会受到赞赏.

Any insights appreciated.

推荐答案

此实践可追溯到PLSQL和Oracle 7之前.

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 ...从double转换为var;

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菜单中的上下文切换通常是通过 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`来调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆