如何从 pl/sql 匿名块调用 pl/sql 匿名块 [英] How to call a pl/sql anonymous block from an pl/sql anonymous block

查看:76
本文介绍了如何从 pl/sql 匿名块调用 pl/sql 匿名块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 PL/SQL 块,它运行良好.我想从另一个 PL/SQL 块调用这个函数 (TimeToFrame).

I have the following PL/SQL block and it's working fine. I would like to call this function (TimeToFrame) but from another PL/SQL block.

我无法在存储在数据库中的过程或包中声明此函数.换句话说,我如何从另一个 pl/sql 调用 pl/sql,其中 pl/sql 都是匿名块??

I cannot declare this function in a procedure or package that is stored in the DB. In other words how can I call a pl/sql from another pl/sql where both pl/sql are anonymous blocks??

如果我将该函数放在单独的 .sql 文件中会怎样.我不能从我的匿名块调用那个 .sql 文件并向它传递一些 IN 参数并让 fct 返回 OUT 参数吗?

What if I put that function in a separate .sql file. Can't I call that .sql file from my anonymous block and pass it some IN parameters and have that fct return OUT params?

Declare
nTime Number;

FUNCTION TimeToFrame(pTime IN Varchar2)
return NUMBER IS
nTime NUMBER;
BEGIN
select (SUBSTR(pTime, 1, 2) * 108000)+(SUBSTR(pTime, 4, 2) * 1800)+(SUBSTR(pTime, 7, 2)     * 30)+SUBSTR(pTime, 10, 2)
 into nTime
 from dual;
 return nTime;
END TimeToFrame;

Begin
nTime:=TimeToFrame('47:59:59:29');
DBMS_OUTPUT.PUT_LINE(nTime);
End;

推荐答案

不幸的是,没有办法做到这一点.在匿名块中声明的嵌套子程序在匿名块被处理后甚至不会持久化,所以即使我们忽略范围限制,当另一个匿名块被处理时它不存在.

Unfortunately, there is no way to achieve that. A nested subprogram declared in an anonymous block isn't even persisted after the anonymous block has been processed, so even when we ignore the scope limits, it doesn't exist when the other anonymous block is processed.

如果由于邪恶的 DBA 不允许而无法将其设置为存储函数,则必须复制粘贴该函数.

If you can't make it a stored function because the evil DBA doesn't allow that, you will have to copy-paste the function.

这篇关于如何从 pl/sql 匿名块调用 pl/sql 匿名块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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