cannot find function or procedure - oracle

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.

Related

ORACLE pass user defined object type as parameter to procedure

I am trying to attempt a bulk insert by using a FORALL in the Procedure .
I have tried the below steps to create the procedure :
**CREATE TYPE SECID_TABLE as TABLE OF VARCHAR2 INDEX BY NUMBER;**
CREATE PROCEDURE ASP_STOCK
(**p_secid IN SECID_TABLE**
) as
BEGIN
..
END;
But the above two statements do not compile. I am rather new to oracle and use aqua studio which doesnt seem to be verbose on the error statement.
Can someone please guide me?
There are two problems here.
The first problem is that you can't create an index-by table with an index type of NUMBER. SQLFiddle here Change the index type to PLS_INTEGER.
But even if you do THAT you're still going to get errors because an index-by table like this is a PL/SQL-only construct. SQLFiddle here.
You're going to have to do something else. Try an unindexed TABLE type, which is allowed at schema level. SQLFiddle here
Best of luck.

Get the DDL for a function in a package

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

Select All records from a table using SP in Oracle SQL Developer

I'm using SQL Oracle to build a stored procedure. I'm trying to build a stored procedure of the SQL-query below.And I want to return those data to a C# program.
select * from employee_master
I have tried following. Is this correct?
CREATE OR REPLACE PROCEDURE EMPLOYEE_SELECTALL (p_recordset OUTSYS_REFCURSOR)AS
BEGIN
OPEN p_recordset FOR
SELECT
*
FROM
EMPLOYEE_MASTER;
END EMPLOYEE_SELECTALL;
If you wish to build a stored procedure that return such resultset first of all you should check if you really need to do this. It's incidental and not recommended way for Oracle. But if you really need so, you should use REF CURSOR.
after executing your stored procedure in SQL Developer, it automatically brings back any output for you to view, including one or more ref cursors.
Example code and screenshots here

Error in select query in Oracle

I've used a select statement in stored procedure in oracle 11g xe.But an error is showing as
pls-00428-an INTO clause is expected with select statement
I just cannot understand the error.When i searched i found out that in pl/sql an into clause is needed.I'm using toad.But when i used sql editor same error is showing.
Here's my procedure
CREATE OR REPLACE PROCEDURE ACTSINFO.sp_Get_WorkDetails
IS
BEGIN
select * from workdetails;
END sp_Get_WorkDetails;
Oracle is different from Microsoft SQL Server and therefor returning a result set from a procedure (or function) is different as well.
What you are looking for is a "pipelined table function".
Please refer to the manual for a description and an example:
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53109
Here are some more examples from other sites:
http://www.oracle-developer.net/display.php?id=207
http://www.oracle-base.com/articles/misc/PipelinedTableFunctions.php
http://psoug.org/reference/pipelined.html
You are trying to write wrong syntax or improper use of SELECT statement. You have to either create a cursor or use SELECT .. INTO syntax to set scalar value to the local variables.

How to get information about a User-Defined Type?

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%';

Resources