What is the operator "=>" we can often see in the UTL_TCP usage examples ?
As in 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);
I dont understand what is the purpore of "p_conn => l_conn", since we never use p_conn anywhere. Even closing the connection is done with ftp.logout(l_conn), not using p_conn. All the variables used before this operator "=>" arent even defined anywhere.
Maybe it's an operator specific to the UTL_TCP package, because I never saw it being used anywhere else, and cant find it in any PL/SQL documentation, Oracle or otherwise.
It's a method to pass parameters to a PL/SQL subroutine called named notation.
For more information see the official Oracle documentation:
http://docs.oracle.com/cd/B12037_01/appdev.101/b10807/08_subs.htm#sthref1013
It's mostly used when you don't know how much parameters a procedure does expect or in which order they are expected. So you just name every parameter you want to pass with it's according value.
Excerpt from the documentation:
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.
Excerpt from documentation:
Positional Versus Named Notation for Subprogram Parameters
When calling a subprogram, you can write the actual parameters using either positional or named notation. That is, you can indicate the association between an actual and formal parameter by position or name. So, given the declarations
DECLARE
acct INTEGER;
amt REAL;
PROCEDURE credit_acct (acct_no INTEGER, amount REAL) IS ...
you can call the procedure credit_acct in four logically equivalent ways:
BEGIN
credit_acct(acct, amt); -- positional notation
credit_acct(amount => amt, acct_no => acct); -- named notation
credit_acct(acct_no => acct, amount => amt); -- named notation
credit_acct(acct, amount => amt); -- mixed notation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With