gpt4 book ai didi

sql - PL/SQL 神秘箭头运算符

转载 作者:行者123 更新时间:2023-12-04 16:46:30 27 4
gpt4 key购买 nike

我们经常在 UTL_TCP 使用示例中看到的运算符“=>”是什么?

http://www.oracle-base.com/articles/misc/ftp-from-plsql.php

  l_conn := ftp.login('ftp.company.com', '21', 'ftpuser', 'ftppassword');
ftp.ascii(p_conn => l_conn);
ftp.get(p_conn => l_conn,
p_from_file => '/u01/app/oracle/test.txt',
p_to_dir => 'MY_DOCS',
p_to_file => 'test_get.txt');
ftp.logout(l_conn);

我不明白“p_conn => l_conn”的目的是什么,因为我们从来没有在任何地方使用过 p_conn。
即使关闭连接也是使用 ftp.logout(l_conn) 完成的,而不是使用 p_conn。
在此运算符“=>”之前使用的所有变量甚至都没有在任何地方定义。

也许它是特定于 UTL_TCP 包的运算符,因为我从未见过它在其他任何地方使用过,并且在任何 PL/SQL 文档、Oracle 或其他文档中都找不到它。

最佳答案

这是一种将参数传递给名为命名符号的 PL/SQL 子例程的方法。
有关更多信息,请参阅 Oracle 官方文档:
http://docs.oracle.com/cd/B12037_01/appdev.101/b10807/08_subs.htm#sthref1013
它主要用于当您不知道过程确实期望多少参数或期望它们的顺序时。因此,您只需根据值命名要传递的每个参数。
文档摘录:

Positional notation. You specify the same parameters in the same order as they are declared in the procedure.

This notation is compact, but if you specify the parameters (especially literals) in the wrong order, the bug can be hard to detect. You must change your code if the procedure's parameter list changes.

Named notation. You specify the name of each parameter along with its value. An arrow (=>) serves as the association operator. The order of the parameters is not significant.

This notation is more verbose, but makes your code easier to read and maintain. You can sometimes avoid changing your code if the procedure's parameter list changes, for example if the parameters are reordered or a new optional parameter is added. Named notation is a good practice to use for any code that calls someone else's API, or defines an API for someone else to use.

Mixed notation. You specify the first parameters with positional notation, then switch to named notation for the last parameters.

You can use this notation to call procedures that have some required parameters, followed by some optional parameters.

关于sql - PL/SQL 神秘箭头运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20422072/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com