Where and how are procedure and packages store or saved in oracle database? Do oracle store compiled version separately? - oracle

in plsql when I create and compile a procedure, whether inside a package or standalone, how specification and body of procedure is saved in database?

Like all the other data about objects etc, the text of the code is stored in the dictionary tables. You can see the package contents by querying user_source, all_source or dba_source, depending on which level you're viewing the data at.
The actual compiled version of the code that Oracle keeps is, as far as I know, an internal thing that isn't available to be queried in the dictionary tables.

Related

I want to bash a file from server side containing a list to a table in database

I've been stuck on how to do this task, python is unavailable, all I can do is pl/sql which I only did once. Basically what I'm trying to do is query a file that contains a list to a table in database, this is the format it contains 123-43763-2748, Please help on how to approach/solve this task. Thank you so much
If I understood you correctly, you have a file that contains data (many rows, I presume?) like the one you posted. Now you'd want to store data from file into a table within an Oracle database. Is that correct?
If so, PL/SQL is not the only option you have. If you want to use it, then you'd first have to acquire access to Oracle directory (that's an object that points to a filesystem directory, usually located on a database server). To do so, you'll have to talk to DBA, they'll grant privileges to your user. Then you'd write a PL/SQL procedure which uses UTL_FILE package, reads the file and inserts values into the database.
Another option - which also includes previously mentioned directory - is to create a external table; it just points to the filesystem file which then acts as if it were an ordinary table, so you can easily query it and use it as a source for a simple INSERT INTO statement (to store data into the target table).
Then, there's my favourite option - SQL Loader, utility that is capable of reading files stored on your own computer (as opposed to previous options), and is really, really fast. You'd create a control file (it says what data to read and where to store those values) and use it with the sqlldr executable.
That's theory. It is useless to write some dummy code because you didn't explain any details - for example, how does the target table look like (its description), whether you have access to database server or not, were you granted certain privileges (e.g. execute on utl_file) etc.

Data Migration in PL/SQL with Toad

I am beginner on PL/SQL, and I have to use it for data migration.
We are setting up a new Human Resources Management system. So, we want to:
Extract all data of the old system
Edit it with PL/SQL
Export it in XML files (another team gonna load the XML files to the new system after that)
We have to edit column names, column types, employees IDs, etc.. in a way that all data can be suitable for the new system.
Can anyone explain me steps to do this, show me links or similar examples.
This answer is keeping in mind that you are using a oracle data base to extract data and create xml files
For extracting data from database tables to xml you have several options
Using Sql
Example:-
SELECT XMLElement( "DEPARTMENT"
, department_name
)
FROM departments
WHERE department_id IN (10, 20);
output
<DEPARTMENT>Administration</DEPARTMENT> <DEPARTMENT>Marketing</DEPARTMENT>
2.Using PLSQL
using plsql XMLTYPE constructor
using DBMS_XMLGEN package
using dbms_xmldom package
With the XMLTYPE constructor and DBMS_XMLGEN package, you can create simple XML documents, fast and easy. When you need to create more advanced XML documents or want to have more control on how your XML document looks like, DBMS_XMLDOM can be used. The DBMS_XMLDOM package is a bit more complicated as you’ll have to create the entire document by calling functions and procedures of the package.
Refer following 2 articles
Generating XML from SQL and PL/SQL – Part 1
Generating XML from SQL and PL/SQL – Part 2
To Wite the xml in to a file you can use
Oracle Spool if you are using sql to generate
xml UTL_FILE package if you are using plsql to generate xml

Generate DDL for Oracle Stored Procedure Dependency Graph

With TOAD I know I can view the dependency (uses) graph of a stored procedure using the schema browser. And, the Oracle utility procedure deptree_fill can do something similar. What I want to do is script out all of the stored procedures, functions and table definition DLLs into a file that I can use to recreate those objects in another database. Is there a tool or an existing script for this purpose? My own searching has not found a solution. In my particular case the stored procedure uses a dozen other procedures, a few functions and twenty tables.
Edit 1
Maybe my original question was not clear. What I am looking for is something that will take the stored procedure I am interested in and script it and all of its dependency graph into one or more files.
The schema I am dealing with has hundreds of objects in it and the dependency graph has ~50 objects in it. So I'd rather not dig through large lists in TOAD or write an Oracle script myself if I can avoid it.
All sources can be extracted using the dbms_metadata package.
To get the source of a table:
select dbms_metadata.get_ddl('TABLE', 'SOME_TABLE')
from dual;
To get the source of a stored procedure:
select dbms_metadata.get_ddl('PROCEDURE', 'SOME_PROC')
from dual;
Using that you can create a SQL script that extracts everything and then spool the result to a file.
More details about the various functions in dbms_metadata can be found in the manual:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_metada.htm#i1015856
Hmm, it is quite easy to find in google.
Get table DDL: How to get Oracle create table statement in SQL*Plus
Code of stored procedures can be found in table USER_SOURCE.
Also, for exporting schema to another DB you can use oracle utilities: http://docs.oracle.com/cd/B28359_01/server.111/b28319/exp_imp.htm#g1070082
In Toad see the Generate Schema Script window. You can get to it from the Database|Export menu. There are many options there to include/exclude what you want.

Attempting to use SQL-Developer to analyze a system table dump created with 'exp'

I'm attempting to recover the data from a specific table that exists in a system table dump I performed earlier. I would like to append the rows existing in the dump to any rows that may exist in the active table. The problem is, it's likely that the name of the table in the dump is not the same as what exists in the database currently (They're dynamically created with a prefix of ARC_TREND_). In addition, I don't know the name of the table as it exists in the dump, I was hoping to use SQL Developer to analyze the dump file as I can recognize the correct table by it's columns and it's existing rows.
While i'm going on blind faith that SQL Developer can work with my dump file, when attempting to open it, i'm getting a Java Heap OutOfMemory exception raised. I've adjusted the maximum heap size from 640m to 1024m in both sqldeveloper.bat and in sqldeveloper.conf, but to no avail.
Can someone recommend a course of action for me to take to recover the data from a table which exists in a exp created dump file? A graphical tool would be nice, but I'm no stranger to the command line. I need to analyze the tables that exist in the dump in order to pick the correct one out. Then I assume I can use imp TABLE= to bring it back into the active instance. It likely won't match the existing table name, so I will use SQL Developer to copy the rows from the imported table to the table where I need them to be.
The dump was taken from a Linux server running 10g, and will be imported to (the same server & database instance, upgraded) an 11g instance of the same database.
Thanks
Since you're referring to imp rather than impdp, I assume this wasn't exported with data pump. Either way, I doubt you'll get anything useful through SQL Developer.
Fortunately most of what you're trying to do is quite easy from the command line; just run imp with the INDEXFILE parameter, which will give you a text file containing all the table (commented out with REM) and index creation commands. From that you should be able to spot the table from its column names.
You can't really see any row data though, so if there's more than one possible match you might need to import several tables and inspect the data in them in the database to see which one you really want.

Oracle: Finding the stored procedure that modifies record on a table

I've got a C# code that calls stored procedures and UPDATES a table. Can I monitor each operation made on this table by a SID.
Yes, you can do this at the database level using Oracle auditing. See here for good writeup and examples of its use.

Resources