PL/SQL mysterious arrow operator

operators, oracle, sql

Solution

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.

Problem

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.

Original source