Home » SQL & PL/SQL » SQL & PL/SQL » packages......
packages...... [message #278293] Fri, 02 November 2007 13:19 Go to next message
sunilcse1
Messages: 23
Registered: June 2007
Location: Bangalore
Junior Member
Can we create package specification without package body? If yes then where to use?
Re: packages...... [message #278294 is a reply to message #278293] Fri, 02 November 2007 13:24 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
A package specification is necessary, but not sufficient to do something useful all by itself.
Re: packages...... [message #278298 is a reply to message #278294] Fri, 02 November 2007 13:36 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Package specification *might* be useful when you want to declare types or constants which are used in other program units; for example
CREATE PACKAGE pkg_const IS
   TYPE integer_tab IS TABLE OF INTEGER;

   c_true    BOOLEAN   := TRUE;
   c_false   BOOLEAN   := FALSE;

   c_sign_rd VARCHAR2(2) := 'RD';
   c_sign_se VARCHAR2(2) := 'SE';
END;
Re: packages...... [message #278314 is a reply to message #278294] Fri, 02 November 2007 20:38 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
anacedent wrote on Fri, 02 November 2007 18:24

A package specification is necessary, but not sufficient to do something useful all by itself.

Not often I disagree with you ana, but this is one time. I've certainly seen a bodiless package used for example, to create a standard set of exceptions
Re: packages...... [message #278316 is a reply to message #278293] Fri, 02 November 2007 20:55 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
> I've certainly seen a bodiless package used for example, to create a standard set of exceptions
Live & Learn. Now this old dog just learned a new trick.
I don't know, what I don't know.
Re: packages...... [message #278317 is a reply to message #278316] Fri, 02 November 2007 20:59 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
>I don't know, what I don't know

I like that, I may use it in the future Smile
Re: packages...... [message #278439 is a reply to message #278298] Sun, 04 November 2007 03:45 Go to previous messageGo to next message
William Robertson
Messages: 1640
Registered: August 2003
Location: London, UK
Senior Member
If they are constants, then perhaps that should be

CREATE PACKAGE pkg_const IS
   TYPE integer_tab IS TABLE OF INTEGER;

   c_true    CONSTANT BOOLEAN   := TRUE;
   c_false   CONSTANT BOOLEAN   := FALSE;

   c_sign_rd CONSTANT VARCHAR2(2) := 'RD';
   c_sign_se CONSTANT VARCHAR2(2) := 'SE';
END;

What prefix do you use for cursors anyway? I use k_ for constants.
Re: packages...... [message #278472 is a reply to message #278439] Sun, 04 November 2007 10:09 Go to previous messageGo to next message
Littlefoot
Messages: 20900
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Thank you for correcting my mistake, William; obviously CONSTANT is what I *forgot* to specify. Being too sloppy lately, I'm afraid.

I use 'cur_' for cursors.
Re: packages...... [message #279088 is a reply to message #278472] Tue, 06 November 2007 20:43 Go to previous message
rleishman
Messages: 3724
Registered: October 2005
Location: Melbourne, Australia
Senior Member
You can also declare a standard set of CURSORs that you want to use in two or more other packages (unlikely, I grant you, but possible).

It's also good for declaring collections whose contents you want to be persistent for a session. Sort of like SYS_CONTEXT. This is the type of thing you might use to retain state information between different trigger types.

Ross Leishman
Previous Topic: CREATE SYNONYM
Next Topic: using analytic function to solve my query
Goto Forum:
  


Current Time: Wed Dec 07 22:29:06 CST 2016

Total time taken to generate the page: 0.12281 seconds