存储PL/SQL块的地方

发布于 2024-12-03 22:41:27 字数 429 浏览 0 评论 0原文

对于 PL/SQL 应该存储在哪里,以下问题的解决方案是否正确?

您想要创建一个计算客户订单折扣的 PL/SQL 代码块。 - 此代码将从多个位置调用,但仅在程序单元 ORDERTOTAL 内调用。 存储计算折扣的代码最合适的位置是什么?

A. A stored procedure on the server.
B. A block of code in PL/SQL library.
C. A standalone procedure on the client machine.
D. A block of code in the body of the program unit ORDERTOTAL.
E. A local subprogram defined within the program unit ORDERTOTAL.

ANSWER: E

Is the Below question solution correct for where should the PL/SQL be stored.

You want to create a PL/SQL block cof code that calculates discounts on customer orders. - This code will be invoked from several places,but only within the program unit ORDERTOTAL.
What is the most appropriate location to store the code that calculates the discounts?

A. A stored procedure on the server.
B. A block of code in PL/SQL library.
C. A standalone procedure on the client machine.
D. A block of code in the body of the program unit ORDERTOTAL.
E. A local subprogram defined within the program unit ORDERTOTAL.

ANSWER: E

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疾风者 2024-12-10 22:41:27

正如 Ranzo 指出,其他几个答案也是合理的。那么,为什么E是正确答案呢?因为问题要求提供代码最合适的位置

让我们来分解一下。

该逻辑需要从多个地方调用。因此有必要将其定义为自己的函数(因为我们不想重复相同的代码)。

同时,客户折扣逻辑仅从 ORDERTOTAL 程序单元调用。因此,我们不想将其公开为独立过程或打包函数,因为它们可以被其他程序调用。这就排除了AB

因此,最好的放置位置是 E,即 ORDERTOTAL 程序的声明部分。类似于:

 create procedure ordertotal
     (custid in pls_integer
      , orderid in pls_integer)
 is
     ln_running_total number;
     ....
     function calc_discount 
        (custid in pls_integer)
        return number
     is
  ....

现在,如果 ORDERTOTAL 是一个打包过程,我们可以选择将 CALC_DISCOUNT() 设为私有函数(在正文中定义,但未在规范中声明)。但一般来说,最好保持范围尽可能严格,除非该函数将来有可能被其他过程使用。

根据记录,C 是错误的,因为在客户端声明的内容无法被服务器访问,D 是错误的,因为它无法编译。


在搜索这个问题的文本版本时,我发现了一个PDF版本 here 给出的正确答案为 A。 8-) 另一个提供盗版考试的网站说正确答案是B。所以好消息是,那些认为通过简单地学习答案就可以破解测试的人将会失败。

As Ranzo notes several of the other answers are are also plausible. So, why is E the correct answer? Because the question asks for the most appropriate location for the code.

Let's break it down.

The logic needs to be called from several places. It is therefore necessary to define it as its own function (because we don't want to repeat the same code).

At the same time, the customer discount logic is only called from the ORDERTOTAL program unit. Hence we don't want to expose it as a standalone procedure or a packaged function, which could be called by other programs. That rules out A and B.

So the best place to put it is E, the declaration section of the ORDERTOTAL program. Something like:

 create procedure ordertotal
     (custid in pls_integer
      , orderid in pls_integer)
 is
     ln_running_total number;
     ....
     function calc_discount 
        (custid in pls_integer)
        return number
     is
  ....

Now if ORDERTOTAL were a packaged procedure, we would have the choice to make CALC_DISCOUNT() a private function (defined in the body but not declared in the spec). But generally speaking its better to keep the scope as tight as possible, unless there is a reasonable chance the function will be used by other procedures in the future.

For the record, C is wrong because stuff declared on the client side is not accessible to the server, and D is wrong because it would not compile.


While searching for a text version of this question, I found a PDF version here which gives the correct answer as A. 8-) And another site offering pirated exams says the correct answer is B. So the good news is, people who think they can hack the tests by simply learning the answers are going to FAIL.

江湖彼岸 2024-12-10 22:41:27

除了“C”之外的所有内容都是合理的。这些 Oracle 测试已简化为细节,以使其变得更加困难。我认识一些优秀的 Oracle DBA,但他们无法通过这些考试,因为它们不是关于概念的,而是关于行话和技巧的。

E是最好的答案,它在调用程序中本地化子程序。关键词是本地化。

当然,它也存储在数据库服务器上(A),它实际上是一个代码块(B--虽然“库”不是 PL/SQL 所说的),而且它实际上是内部的一个代码块订单总计 (D)。

祝你考试顺利,并确保专注于概念。

Everything except "C" is plausible. These Oracle tests have descended into minutia, in an effort to make them harder. I know several good Oracle DBAs who can't pass them, because they are not about concepts but about jargon and trickiness.

E is the best answer, it localizes the subroutine in the calling program. The key word is local.

Of course, it is also stored on the DB server (A), it is in fact a block of code (B--although "library" isn't PL/SQL speak), and it is in fact a block of code within ORDERTOTAL (D).

Good luck on your tests, and make sure to focus on the concepts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文