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

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.

Related

Backup of procedures in toad oracle 12.1?

Procedure for taking backup of procedures in toad oracle 12.1? I would also like to ask the difference between procedures and stored procedures
I would also like to ask the difference between procedures and stored procedures
A procedure is a subprogram that performs a specific action.
Oracle's documentation for CREATE PROCEDURE uses the term "standalone procedure" rather than "stored procedure" (but does state that it is stored in the db):
A standalone procedure is a procedure (a subprogram that performs a specific action) that is stored in the database.
A nested procedure is a procedure that is in a PL/SQL block or a package.
From the CREATE PACKAGE documentation:
The CREATE PACKAGE statement creates or replaces the specification for a stored package, which is an encapsulated collection of related procedures, functions, and other program objects stored as a unit in the database. The package specification declares these objects. The package body, specified subsequently, defines these objects.
Standalone procedures and procedures nested in a package are both stored (compiled) within the database - so are "stored" procedures. Procedures defined in an anonymous PL/SQL block are "nested" procedures but are not "stored" procedures.
This anonymous block defines a procedure which is not a stored procedure:
DECLARE
n NUMBER := 1;
PROCEDURE incr( a IN OUT NUMBER ) IS
BEGIN
a := a + 1;
END;
BEGIN
incr(n);
DBMS_OUTPUT.PUT_LINE(n);
END;
/
Toad has many ways to export that can be used to make backups of your objects. See the Database menu, Export sub-menu. Export DDL allows you to retrieve DDL for specific objects. Generate Schema Script will generate a complete script necessary to recreate an entire schema. You can also create actions for these tasks in the Automation Designer, available from the Utilities menu. Those actions can be scheduled. You can also add actions to zip the results, move them to another location (folder, ftp, email, etc.) You can create an "app" that will export the objects, zip the results, move them to another location, and email you when complete. There are many possibilities.

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 delete procedure or function from Package

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.

Passing an associative array as a parameter between packages

I've got two separate Oracle (v9.2) PL/SQL packages and I'm trying to pass an associative array (ie, index-by table) from a procedure in package1, as a parameter to a procedure in package2. Is this possible? I keep getting PLS-00306: wrong number or types of arguments in call to 'ROLLUP_TO_15' when I compile package1.
The array is defined as:
type list_tab is table of number(10)
index by binary_integer;
in both package's spec. In the procedure in package1, I'm calling the second package as package2.rollup_to_15(chanList); That's the line I get the compile error on (chanList is a variable of type list_tab).
In package2, the procedure is defined as:
procedure rollup_to_15(channels in list_tab) is
I'm guessing that my problem is that the type is defined separately in each package, because I can pass the `chanList' variable to other procedures within the first package without any problems.
So, is it possible to pass an associative array between packages? And if so, how?
Dave
Yes, it's possible for sure.
It's hard to explain why do you receive error without package specs samples, but in general to pass a user-defined type as a parameter you should either with define type DDL, or defining the type in package spec.
I suppose you want the latter variant :)
So here're an example:
create or replace package TestPackage_1
as
type TTestType is table of varchar2(1) index by varchar2(1);
end TestPackage_1;
/
create or replace package TestPackage_2
as
procedure Dummy(aParam TestPackage_1.TTestType);
end TestPackage_2;
/
You can use TTestType type in any PL/SQL block, but not in SQL.
"The array is defined as: ... in both
package's spec."
This is the source of your problem. PL/SQL regards two separate declarations as two different objects, even though both types have an identical signature. Consequently the engine hurls when you call this:
package2.rollup_to_15(chanList)
Your code has defined the chanList variable as package1.list_tab but the procedure is expecting a variable of type package2.list_tab.
The simplest solution is to declare LIST_TAB just in PACKAGE2, and chnage PACKAGE1 so that chanList is declared appropriately.

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;

Resources