Is there any way to get the DDL for a function in a package under a different user in Oracle? I can see the package in SQL Developer under one of the users listed under 'Other users'. I've tried using the dbms_metadata.get_ddl function:
SELECT dbms_metadata.get_ddl('PACKAGE', 'MY_PACKAGE', 'OTHER_USER') FROM DUAL
But I get the following error:
ORA-31603: object "MY_PACKAGE" of type PACKAGE not found in schema "OTHER_USER"
For the first parameter of the get_ddl function I tried PACKAGE_SPEC, and PACKAGE_BODY but this didn't seem to help.
Not sure if this will help anyone, this is an old question, but I use this query (from Java) to rip all the procedures and functions off our server so we can put them in GIT. I'm using 12C.
with x as
(
SELECT owner, object_name, object_type
FROM dba_objects
WHERE owner LIKE 'OWNER_NAME_HERE'
AND object_type IN ('PROCEDURE', 'FUNCTION')
)
SELECT DBMS_METADATA.get_ddl (x.object_type, x.object_name, x.owner) as ddlcode FROM x;
You can extract code from package using get_dll, but you should instead provide the correct type of object (for example PACKAGE_BODY to get everything but the head/description)
Since you're in SQL Developer, you can use the DDL command as well
clear screen
show user
ddl ords_demo.demo_pkg -- schema.package, gets the package and package body code
This is also available at the command line in SQLcl
Related
I am auditing an Oracle BD and I need to know the password policy assigned to this Database.
One way I thought to do it is retrieving the body of verify_function that is assigned to the profiles.
How can I list the body of these "verify_function"? Such as the body of utlpwdmg.sql and ora12c_strong_verify_function etc.
Thx!
As I see the problem from the comments you can't find the function "ORA_COMPLEXITY_CHECK" which is an oracle standart function. The code might be obtained under
{ORACLE_HOME}/rdbms/admin/catpvf.sql
And it could be that the catpvf.sql script wasn't executed against the instance you're on.
In general, here is the script to get the ddl of an object withour specifying it's type(might take longer time to execute).
select owner, object_name, object_type, dbms_metadata.get_ddl(object_type, object_name)
from dba_objects
where object_name = 'CFL_BITAND';
The same way you'd get the DDL for any object in the database -- dbms_metadata.get_ddl. There's nothing magic about the particular function you are after. It's just another function defined in the database.
I need to debug an Oracle procedure code but I am new to Oracle. In the procedure I see a line of code like the following, but I cannot locate its implementation in order figure out what it's doing.
select SOME_OBJECT_OR_PACKAGE.NEXTVAL into some_var from dual;
It looks like it's calling a function from a package to me but I don't see a package with that name in the Packages folder from SQL Developer. I have tried the following command but got nothing in return.
select * from all_source where UPPER(name) like UPPER('%SOME_OBJECT_OR_PACKAGE%')
Please help.
NEXTVAL is way to retrieve the next value in a SEQUENCE in Oracle.
see here for more details:
http://www.techonthenet.com/oracle/sequences.php
or here:
Create Table With Sequence
It's a database object called a sequence. It auto-increments when you select it.
In simplicity, PL/SQL generally follow the following:
DECLARE
Variable declaration
BEGIN
Program Execution
EXCEPTION
Exception handling
END;
I am quite new to PL/SQL and i am looking at the variable declaration section where i would like to find out more information on SALES_PRODUCT_TY_LIST.
Is there a table i may look up to check on information on SALES_PRODUCT_TY_LIST, such as checking out table column information from all_tab_cols view?
CREATE OR REPLACE PROCEDURE GET_DISCOUNTS
(
v_have_list SALES_PRODUCT_TY_LIST
)
IS
QUERY VARCHAR(5000);
...
Thanks.
The Oracle database has an extensive data dictionary (what some other DBMS products call the INFORMATION SCHEMA). You can find all the views here. Alas, the revised ToC structure makes it harder to find something in the 11g documentation unless you already know what you're looking for, so use the index instead. 8-)
Anyway, the views you need to query are ALL_TYPES and ALL_TYPE_ATTRS.
This seems to be user defined collection type. You can find some information about it querying all_types/user_types view:
select * from user_types where type_name = 'SALES_PRODUCT_TY_LIST'
The definition of the type can be found for example by querying all_source/user_source view:
select text from user_source where name = 'SALES_PRODUCT_TY_LIST' order by line
Try this to get DDL:
SELECT dbms_log.substr(dbms_metadata.get_ddl('TYPE', 'SALES_PRODUCT_TY_LIST'), 32767,1)
FROM DUAL;
see: http://www.myoracleguide.com/s/gen_schema.htm
Ok i found something:
select *
from all_objects
where object_name like 'SALES%';
I have searched the net and I've found a post that uses the following snippet to check if a stored procedure exists:
select *
from USER_SOURCE
where type='PROCEDURE'
and name='my_stored_procedure.'
Is there any other way to check if a procedure exists?
Edited to add:
Before posting SQL Server ways, please I'm looking for ORACLE ways.
Alternatives:
USER_PROCEDURES:
SELECT *
FROM USER_PROCEDURES
WHERE object_name = 'MY_STORED_PROCEDURE'
USER_OBJECTS:
SELECT *
FROM USER_OBJECTS
WHERE object_type = 'PROCEDURE'
AND object_name = 'MY_STORED_PROCEDURE'
Something that worked for me!
SELECT text
FROM all_source
WHERE name = 'MY_SP_NAME'
ORDER BY line;
Alternatively you can try calling SP like this:
CALL MY_SP_NAME();
You might end up error like this, but that confirms you have SP defined there:
OCI Statement Execution failure.ORA-06553: PLS-306: wrong number or types of arguments in call to 'MY_SP_NAME'
The only way to see if a procedure exists in the database is though querying DBA_OBJECTS. The disadvantage here is that only a dba has access to this view. Second best is using all_objects. ALL_OBJECTS shows you the objects for which you have somehow a privilege. USER_OBJECTS only shows you your own objects.
Execute the query below in SQL*PLUS, ODBC Test,...
SELECT text FROM all_source WHERE name='MY_PROCEDURE' ORDER BY line
where MY_PROCEDURE is the stored procedure name.
Below is sample output:
Get Data All:
"TEXT"
"PROCEDURE Usp_Get_Blob
"(
"P_DOC_ID INT,
"P_DOC_TEXT OUT BLOB)
"as
"begin
" select B1
into p_doc_text
" from blobtest
" where ID = p_doc_id;
"end; "
I was not able to find stored procedure with any of the methods above.
Reason: stored procedure was inside package. Oracle uses packages to gather several stored procedures in one module.
This will display the stored procedure and its contents stored in the table.
select
name c1,
text c2
from
dba_source
where
name = upper('procedure_name')
order by
line asc;
select *
from USER_SOURCE
where type='PROCEDURE'
and name='my_stored_procedure.'
Since I am new to Oracle, please tell me what different ways to find packages, stored procedures, triggers, functions, indexes, tablespaces
Thanks
The following statement gives you an overview of all database objects in the current user:
SELECT
object_name,
object_type
FROM
user_objects;
If you are searching for documentation, you can look at Morgan's Library
You can download Oracle SQL Developer free. This allows you to explore all the objects in your database via a simple interface.
I shall walk you through the different shades of "all_object":
SQL> show user
USER is "C##SCOTT"
SQL>
Getting all the types of object:
select distinct object_type from all_objects;
EDITION
CONSUMER GROUP
SEQUENCE
SCHEDULE
PROCEDURE
OPERATOR
DESTINATION
WINDOW
SCHEDULER GROUP
PACKAGE
PROGRAM
LOB
XML SCHEMA
JAVA RESOURCE
JOB CLASS
DIRECTORY
TABLE
SYNONYM
INDEX
VIEW
FUNCTION
INDEXTYPE
JAVA CLASS
TYPE
EVALUATION CONTEXT
25 rows selected.
Now, you can zoom down to the "TABLE" type of object:
select object_name||','||object_id||','||owner from all_objects where object_type='TABLE' ;
Or all the objects of an owner:
select object_name||','||object_id||','||OBJECT_TYPE from all_objects where owner = 'SYS';
Trust me, you will learn more this way - anyone can click through any GUI tool, but to issue the SQL command, you will need some knowledge.