Home » SQL & PL/SQL » SQL & PL/SQL » Functions within a Package (Oracle Database 11g, Win 7)
icon5.gif  Functions within a Package [message #582287] Tue, 16 April 2013 11:24 Go to next message
SQLer
Messages: 3
Registered: April 2013
Location: Dublin
Junior Member
Hi guys,

I'm new to PL/SQL and I'm trying to create multiple functions, add them then minus 1 in a package. I'm at my wits end as to what I'm not doing correctly as the package gets created fine but the package body is giving me compilation errors.

I've attached my code and it would be appreciated if someone could point out the errors of my ways!

Thanks!

create or replace package addfunction as
function q1 (num1 IN NUMBER, num2 IN NUMBER) return number;
function q1 (num1 IN NUMBER, num2 IN NUMBER, num3 IN NUMBER) return number;
END;
/

package created


create or replace package body addfunction as
function q1 (num1 IN NUMBER, num2 IN NUMBER) return number
IS
BEGIN
dbms_output.put_line(num1+num2-1);
RETURN 1;
END;
function q1 (num1 IN NUMBER, num2 IN NUMBER, num3 IN NUMBER) return number
IS
BEGIN
dbms_output.put_line(num1+num2+num3-1);
RETURN 1;
END;
END;
/

Warning: Package body created with compilation errors
Re: Functions within a Package [message #582288 is a reply to message #582287] Tue, 16 April 2013 11:50 Go to previous messageGo to next message
Michel Cadot
Messages: 57612
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please INDENT the code.
If you don't know how to do it, learn it using SQL Formatter.

I have no problem with your code:
SQL> create or replace package addfunction as
  2  function q1 (num1 IN NUMBER, num2 IN NUMBER) return number;
  3  function q1 (num1 IN NUMBER, num2 IN NUMBER, num3 IN NUMBER) return number;
  4  END;
  5  /

Package created.

SQL> create or replace package body addfunction as
  2  function q1 (num1 IN NUMBER, num2 IN NUMBER) return number
  3  IS
  4  BEGIN
  5  dbms_output.put_line(num1+num2-1);
  6  RETURN 1;
  7  END;
  8  function q1 (num1 IN NUMBER, num2 IN NUMBER, num3 IN NUMBER) return number
  9  IS
 10  BEGIN
 11  dbms_output.put_line(num1+num2+num3-1);
 12  RETURN 1;
 13  END;
 14  END;
 15  /

Package body created.

To know your errors you can use "show error".

Regards
Michel
Re: Functions within a Package [message #582290 is a reply to message #582288] Tue, 16 April 2013 12:25 Go to previous messageGo to next message
SQLer
Messages: 3
Registered: April 2013
Location: Dublin
Junior Member
Thanks Michel,

Sorry I didn't indent - I was typing on my phone! I do indent in the TUI however!

Strange you got no errors - but ill run everything again and make sure it's imputed correctly!

Thanks for the tip on show errors & next time ill indent!

P
Re: Functions within a Package [message #582291 is a reply to message #582287] Tue, 16 April 2013 12:43 Go to previous messageGo to next message
joy_division
Messages: 4454
Registered: February 2005
Location: East Coast USA
Senior Member
SQLer wrote on Tue, 16 April 2013 12:24
Hi guys,

I'm new to PL/SQL and I'm trying to create multiple functions, add them then minus 1 in a package.


Look at your classmates thread:

http://www.orafaq.com/forum/t/187145/66800/
Re: Functions within a Package [message #582341 is a reply to message #582291] Wed, 17 April 2013 05:41 Go to previous message
SQLer
Messages: 3
Registered: April 2013
Location: Dublin
Junior Member
Thanks guys... I got it working with the same code that I originally posted! Strange that & apologies for wasting anyone's time!
Previous Topic: how to update column value with out using sequences
Next Topic: Anonymous PLSQL - need output with 0.
Goto Forum:
  


Current Time: Sat Apr 19 05:35:10 CDT 2014

Total time taken to generate the page: 0.14733 seconds