Backup of procedures in toad oracle 12.1? - oracle

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.

Related

How to create schema in oracle database using PL/SQL code block?

I want to create schema dynamically i.e. it should prompt for the input. Or how to use collections, nested table to create users from PL/SQL code blocks i.e. procedures, functions etc?
I give you a small example for that:
create or replace procedure p(p_user varchar2) is
begin
execute immediate 'create user '||p_user||' identified by x';
end;
/
begin
p('&user');
end;
/
Here the procedure gets a parameter which can be used to put together your DDL commands. The procedure must be called somehow. You can call it from sqlplus, or execute it via web server, or from a desktop app, etc. I wrote the last 4 lines as example how to call it from sqlplus. Sqlplus can prompt and read input from user.

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.

What is the difference between stored procedure and standalone procedure in Oracle?

standlone procedure
create procedure proc1
(
begin
end;
)
stored procedure
create package pkg1
(
procedure proc2
begin
end;
)
These are both stored procedures, as they are both stored in the database and can be called later.
Putting procedures in a package is just a neat way to organize them. It helps remembering to update all the relevant procedures together, keep your creation scripts tidy, etc. The main functional difference is the ability to grant and revoke privileges on an entire package, instead of having to manage a dozen "stand-alone" procedures independently.
From the oracle documentation for CREATE PROCEDURE
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 not "stored" procedures.
This 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;
/
There is not a huge difference between nested procedures in packages and standalone procedures:
A standalone procedure is defined using CREATE PROCEDURE ... whereas a nested procedure is defined within the PL/SQL block using PROCEDURE ....
A standalone procedure always requires a procedure definition (the AS BEGIN ... END; part) but a (public) nested procedure in a package only declares the procedure heading (the PROCEDURE NAME(...) part) and then in the package body will restate the heading and define the procedure definition.
Nesting a procedure in a package allows it to be grouped with similar functionality and allows it to access functions, procedures and data which is private to the package (i.e. defined in the package body but not in the public package specification).

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.

Why is static ddl not allowed in PL/SQL?

In an Oracle PL/SQL block, why is dynamic sql allowed
begin
execute immediate 'drop table table_name';
end;
but static is not?
begin
drop table table_name;
end;
I hope the answer is more insightful than "because that's how the language works".
The answer is PL/SQL does not support dynamic polymorphism. it only supports static polymorphism because
All PL/SQL generats a "DIANA" -> Descriptive Intermediate Attributed Notation for Ada , a tree-structured intermediate language. DIANA is used internally by compilers.
At compile time, PL/SQL source code is translated into system code and generates corresponding DIANA. Now think if there were a DDL statement like create table statement which at the compile time does not exists it will be created after running the program. how would your PL/SQL engine generate a DIANA then ????
The DIANA is plays an important role in PL/SQL to check/validate that the sub program. this is required because as we know that a sub-program can use database objects such as Tables,Views,Synonyms or other stored procs. it could be possible that the the objects may have changed/removed/droped when next time you run the program. For ex : some one might have droped the table, the stored proc or function singnature may have changed.
Thats why generally PL/SQL is used to manipulate the data within database structure, but not to manipulate those structures.
but there are ways to manipulate using dynamic SQL and DBMS_SQL package but theses methodlogy are again should be used cautiously. For example if you are creating a Table you should check first if this table is already exists or not using data dictionary views.
Probably because otherwise some code would be like:
begin
create table tmp (n number);
insert into tmp values (1);
end;
And we would expect the compiler to know that at time of the insert, the table exists. The compilation of the block would me much more difficult. Here it is a very simple case, but we can easily imagine some conditional branching, and complex blabla.
But, since we need to put the DDL in an execute immediate block, the limitation maybe somehow easier to understand.
Just an idea...
Before execution/compilation, oracle checks all access permissions,validity and dependencies of all schema objects like tables,views,stored procs etc referenced inside a pl/sql block. But problem with DDL statement is that it
can create, alter or drop schema object and as a result, it can change the object dependencies.So it is possible that we are referring one object which has been dropped using DDL. To prevent such situation I guess plsql block does not allow direct DDL statement.
But we can still include DDL in PL/SQL block using Dynamic query. As in this case the actual query is not known until run-time, basically we can hide the DDL statement in the form of Dynamic SQL and include DDL inside PL/SQL block.
You can refer my blog to understand the concept with example:
Why oracle does not allow direct DDL statements inside the procedure (PLSQL BLOCK)

Resources