How to delete procedure or function from Package - oracle

Suppose you create a package in Oracle 10g and has defined a procedure and a function inside the package.
Now, How to delete a particular procedure or function in the package created, without physically DROPPING the package?? i.e. without using DROP PACKAGE package_name
I was wondering if i could actually perform the above action. Thank you in advance for any suggestions and solutions.

Since all objects in a package are stored as a unit, Oracle won't allow you to modify, drop or add packages or functions without replacing the whole package body.
You can find some discussion on the subject at the Oracle forums.

Related

Import and replace package & procedure in oracle

I wanted to import packages and procedures to DB x from another DB y. I used expdp command with include=procedure, package in DB y to export the package and procedure.
In DB x some packages and procedure are already there, so those packages which exist, is showing "already exists", but I need to replace it with this dump as it has some modifications too. Is there any possible way where I can import and replace packages and procedures? It will be a hideous task to manually compile each package.
See this thread for a similar question and a suggestion:
https://dba.stackexchange.com/questions/204968/how-to-replace-and-overwrite-all-existing-objects-in-oracle-with-impdp-for-full
One other option I can think of is to: take export of the source schema and then drop only all the procedures and functions and packages (since you want to replace them anyway) and then run the import which will create them with target code.

Does a procedure declared in package requires separate creation outside it?

I am new to creating packages, I have to include a procedure and a function in a package,
I will create a package by declaring its head and body, Body will contains details about procedure and function.
My query is, after package is created, do I need to create that procedure and function again outside? i.e Create and Replace procedure ...and all?
No. You just define the procedure in the package body.
A procedure can either be a stand-alone procedure or it can be part of a package. In real systems, you almost never want to have stand-alone procedures. It virtually always makes sense to put related procedures together into packages to better organize them.

Oracle,Spring: Using package name when calling stored procedure

What are the benefits of calling a stored procedure via its package name E.g. package.mystoredproc versus a direct call E.g. mystoredproc?
Does this give extra information to the calling code or is it just a good convention to use?
I've created a stored procedure which doesn't live in a package. I can execute the call without any problems however when the procedure was moved into a replicated environment where synonyms are used i ran into a problem whereby i had to include the schema name when calling the procedure.

How to rename an Oracle procedure

Is there a way to rename an oracle procedure, without having to drop and recreate the procedure?
UNfortunately there is no equivalent of ALTER TABLE ... RENAME TO for PL/SQL objects. So I'm afraid you will have to drop the procedure and create it afresh with the new name....
... unless using a SYNONYM will resolve your bind. Without knowing why you want to change the procedure name it's a bit difficult to give advice.
A way around this would be using a procedure inside a package. Then you might use CREATE OR REPLACE PACKAGE ... and CREATE OR REPLACE PACKAGE BODY ... to achieve your goal.
There is no way to rename a procedure unless you drop and create it again. Anyway:
If you have a lot of procedures you'd have to use PACKAGEs instead of PROCEDUREs. In this way you'd only need to change the PACKAGE BODY.
If your problem is to recreate the grants you can create easily an script to do it querying DBA_TAB_PRIVS (yes, also contains privileges for procedures).
You can effectively rename a Procedure by simply creating another procedure - with the new name - that simply calls the old procedure
create or replace procedure new_procedure_name
as
begin
old_procedure_name;
end;

PL/SQL Package Table

I need to maintain state in a PL/SQL application. It needs to hold a small table during the session.
As I understand it, this is accomplished via a package variable, but I don't know how to create a table as a package variable.
Anyone explain how to do this or alternatives?
Expansion of Problem:
I have a WHERE IN condition that I must populate in a cursor at run time. Since to my knowledge I can only populate it with a hard-coded literal or a SELECT I need to hold all the IN's that are selected by the user during the session.
You define a variable with a table type in the package. If you want the state accessible from outside the package it is defined in the header - if you want it private then you define it in the body.
If you want to initialise the variable the first time the package is accessed then you use an initialisation block at the bottom of the package.
Some tips:
Be careful with exception handling when using initialisation blocks. If an exception is raised you need to ensure you use clear error messages or log messages. A maintenance programmer troubleshooting an issue may jump straight to the called method to troubleshoot rather than examining the implicit initialisation block.
Oracle can shuffle packages in and out of memory under various conditions at which point the package level variable is cleared. Ensure your state is required just for that session and that the session is fairly short lived (i.e not around for days). If you need more reliable persistence then use a physical table, not a package variable.
I often find a problem that starts out as being suitable for a package-level table usually grows more complex over time. It might be better to use a real table from an extensibility point of view. It depends on whether you are looking for a short-term solution for a simple problem or a long-term solution for a mission-ritical problem or a problem that will evolve over time.
Example using a simple "name-value" mapping table:
create or replace package bob as
procedure do_stuff;
end bob;
create or replace package body bob as
type my_table is table of varchar2(100) index by varchar2(100);
my_variable my_table;
procedure do_stuff
begin
--do stuff to my_variable
end;
begin
--initialise my_variable
end bob;
If you need to maintain state in your application, you can do this in a global table just as easily as a package-level table. The difference would be that the package table will not be accessible outside of the package.
From O'Reilly, we see that a table defined in the PACKAGE specification is considered global, but a table declared in the PACKAGE BODY specification is a package-level var.
A GLOBAL TEMP TABLE set to on Commit Preserve Rows that is setup as Key/Value can help in using the values throughtout the session not just within the package. SQL queries can then be built around IN or EXIST clauses with the table using access by the key.
Here is the Oracle Doc on Global Temp Tables

Resources