Home » SQL & PL/SQL » SQL & PL/SQL » how to drop a spec named body
how to drop a spec named body [message #42195] Thu, 06 March 2003 04:51 Go to next message
Olaf
Messages: 7
Registered: February 1999
Junior Member
Accidentaly I created a spec named body.
Does anybody know how to get rid of it?
DROP PACKAGE BODY; does not work!
Re: how to drop a spec named body [message #42196 is a reply to message #42195] Thu, 06 March 2003 05:04 Go to previous messageGo to next message
Remi Visser
Messages: 44
Registered: December 2002
Member
What's the source code?

you should issue
sql> drop package body name

remi

http://askremi.ora-0000.com
Re: how to drop a spec named body [message #42198 is a reply to message #42195] Thu, 06 March 2003 05:49 Go to previous messageGo to next message
Olaf
Messages: 7
Registered: February 1999
Junior Member
its a little bit more complicated:
I created a spec with the name 'body' what
was possible even though 'body' is a reserved word
but while trying to drop the spec (wich has no body)
oracle throws ORA 04050 because the name of the package
is invalid
Re: how to drop a spec named body [message #42202 is a reply to message #42195] Thu, 06 March 2003 07:13 Go to previous message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
quote:
----------------------------------------------------------------------
Accidentaly I created a spec named body.
Does anybody know how to get rid of it?
DROP PACKAGE BODY; does not work! 

----------------------------------------------------------------------
Olaf,

What I don't understand is how you created a package with the name of body in the first place.
It's pretty hard to do, even when you try, as you'll soon see.

What do you get when you run the following query, Olaf? (Note, you'll need to substitute your own schema for SCOTT):

SQL> SELECT object_name
  2  FROM   all_objects
  3  WHERE  owner = 'SCOTT'
  4  AND    object_type = 'PACKAGE'
  5  AND    UPPER(object_name) LIKE '%BODY%'
  6  /
  
no rows selected
This tells me that we're staring out "fresh".

Now, I'm going to try to create a package spec with the name body:
SQL> CREATE OR REPLACE PACKAGE body AS
  2      FUNCTION f1 RETURN NUMBER;
  3  END body;
  4  /
CREATE OR REPLACE PACKAGE body AS
                               *
ERROR at line 1:
ORA-04050: invalid or missing procedure, function, or package name
Notice, it doesn't let me create a package named body, because body is a reserved word that ordinarily comes right after the text CREATE OR REPLACE PACKAGE.

Since PL/SQL wouldn't let me create a package with the name body outright, this time, I'm going to try creating a package with the name of body by surrounding the word body with quotes, and it works:
SQL> CREATE OR REPLACE PACKAGE "body" AS
  2      FUNCTION f1 RETURN NUMBER;
  3  END "body";
  4  /
  
Package created.
  
SQL> CREATE OR REPLACE PACKAGE BODY "body" AS
  2      FUNCTION f1 RETURN NUMBER
  3      IS
  4      BEGIN
  5          RETURN (TO_NUMBER(TO_CHAR(SYSDATE,'YYYYMMDD')));
  6      END f1;
  7  END "body";
  8  /
  
Package body created.
Here we see, when I query all_objects, the package with the name body exists, and apparently without quotes:
SQL> SELECT object_name
  2  FROM   all_objects
  3  WHERE  owner = 'SCOTT'
  4  AND    object_type = 'PACKAGE'
  5  AND    UPPER(object_name) LIKE '%BODY%'
  6  /
  
OBJECT_NAME
------------------------------
body
But when I try to invoke my package's function, it doesn't work (I'm not sure why....?):
SQL> SELECT body.f1 FROM DUAL;
SELECT body.f1 FROM DUAL
            *
ERROR at line 1:
ORA-00904: invalid column name
When I surround my package body's name with quotes, however, the above call works:
SQL> SELECT "body".f1 FROM DUAL;
  
        F1
----------
  20030306
So that proves that the package really exists. Now I try to drop the package, like you're trying to do, Olaf:
SQL> DROP PACKAGE body;
DROP PACKAGE body
                *
ERROR at line 1:
ORA-04050: invalid or missing procedure, function, or package name
Since that doesn't work, I surround body with quotes:
SQL> <font color=red>DROP PACKAGE "body";</font>
  
Package dropped.
And just to make sure the package is really gone, I once again query all_objects:
SQL> SELECT object_name
  2  FROM   all_objects
  3  WHERE  owner = 'SCOTT'
  4  AND    object_type = 'PACKAGE'
  5  AND    UPPER(object_name) LIKE '%BODY%'
  6  /
  
no rows selected
  
SQL> 
....and it's gone.

I hope this helps, Olaf.

Art
Previous Topic: How to store blob's in a table?
Next Topic: Want a PPS file for oracle forms presentation..
Goto Forum:
  


Current Time: Sat Jan 24 16:57:16 CST 2026