views:

221

answers:

1

What is the difference between these two statements?

dbms_output.new_line(); // with no parameters.
dbms_output.new_line;    // with no parameters,no round brackets

If there is function overloading,even for that close and open brackets are required after function name.

+1  A: 

Well the difference is that the first formulation fails and the second one succeeds:

SQL> begin
  2      dbms_output.put_line('some text');
  3      dbms_output.put('about to new_line with no parameters');
  4      dbms_output.new_line;
  5  end;
  6  /
some text
about to new_line with no parameters

PL/SQL procedure successfully completed.

SQL> begin
  2      dbms_output.put_line('some text');
  3      dbms_output.put('about to new_line with a parameter');
  4      dbms_output.new_line('');
  5  end;
  6  /
    dbms_output.new_line('');
    *
ERROR at line 4:
ORA-06550: line 4, column 5:
PLS-00306: wrong number or types of arguments in call to 'NEW_LINE'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored


SQL>

edit

What does work is the empty brackets...

SQL> begin
  2      dbms_output.put_line('some text');
  3      dbms_output.put('about to new_line with a parameter');
  4      dbms_output.new_line();
  5  end;
  6  /
some text
about to new_line with a parameter

PL/SQL procedure successfully completed.

SQL>

I don't know when Oracle actually started supprting this convention but I only became aware of it when they introduced the OO stuff. Some member functions (i.e. methods) on Types won't work unless we include the empty brackets e.g. XMLType's getClobVal(). But the brackets are strictly optional for the standard procedural calls.

APC
Your answer is right in context of this question what aboutdbms_output.new_line();//it works same as dbms_ouput.new_line;whats the differnce between them?
Vineet
@Vineet: There is no difference between them, the brackets are optional when no parameter is provided.
Peter Lang
Peter ,you mean to say in pl/sql it is not necessary to give brackets after functions or procedures?
Vineet
@Vineet: It is not necessary as long as they do not take any parameters. I prefer to always write the brackets anyway to improve readability. When defining functions or procedures without parameters, you cant' even use brackets: `CREATE PROCEDURE test() AS ...` won't compile.
Peter Lang
Thnx Peter,I got it now!
Vineet