How to use arrays in stored procedure??Please do help me.......

hi, i need to make a procedure where i may execute a query.The query returns multiple rows.Now i want to use 1 row.i needs to fetch all colums as out parameter...can anyone please help me.....i will be very thankful to the person.

you cannot just force only one column from a select statement to be a out parameter, you need to collect all the columns into a collection type and use the collection type as out parameter or use refcursor as out parameter and fetch the rows
using collection type
create type obj_typ is object(
a_val number,
b_val varchar2(100)
create type nest_typ is table of obj_typ
create or replace procedure retrieve_emp(mgr_no number,e_details out nest_typ) is
begin
select obj_typ(empno,ename) bulk collect into e_details from emp
where mgr = mgr_no;
end;
declare
nest_var nest_typ;
begin
retrieve_emp(7698,nest_var);
for i in 1..nest_var.count loop
dbms_output.put_line(nest_var(i).a_val || ' - '||nest_var(i).b_val);
end loop;
end;
7499 - ALLEN
7521 - WARD
7654 - MARTIN
7844 - TURNER
7900 - JAMESUsing ref cursor
create or replace procedure retrieve_emp2(mgr_no number,e_details out sys_refcursor) is
begin
OPEN e_details FOR select empno,ename from emp
where mgr = mgr_no;
end;
declare
empno_val emp.empno%type;
ename_val emp.ename%type;
edetails_ref_Cur sys_refcursor;
begin
retrieve_emp2(7698,edetails_ref_Cur);
loop
fetch edetails_ref_cur into empno_val,ename_val;
exit when edetails_ref_cur%notfound;
dbms_output.put_line(empno_val ||' - '||ename_val);
end loop;
close edetails_ref_cur;
end;
7499 - ALLEN
7521 - WARD
7654 - MARTIN
7844 - TURNER
7900 - JAMESHTH,
Prazy

Similar Messages

  • How to use @prompt for stored procedure in universe

    Hi,
    I am using Bo XI R3.1 and universe was built on stored procedures and database is sql server 2005.
    I would like to show the list of values for prompts in report which they are based on parameters given for stored procedures in universe. Instead of typing the value for prompts the user should select some values for the prompt.
    I've tried in the universe putting the prompt syntax but didn't work could any one please let me know how this will be achived
    Thanks in advance,
    Eswar

    Hi Eswar,
    Please try the following steps mentioned below:
    1. Go to Insert -> click Tables and Import the table which needs to assign LOVu2019s into Universe panel.
    Objects which are created on tables may appear in inactive mode.
    2. Right click on the stored procedure -> Click on Edit stored procedures.
    3. Click on the Browse universe objects from Stored Procedure Editor. (Button avaial on the left)
    4. Select the object which you want to assign for the List of values.
    5. Enter the desired text which you want to display in the WebI reports in the Edit prompt Label.
    6. Export the Universe.
    Before doing the above steps:
    While creating for SP Univ, a parameter screen appears after selecting SP. In the "Value" field enter a dummy value and
    from the "Next Execution" drop down at the right select "Prompt me for a value".
    Regards,
    Rohit

  • How to use &APP_ID. inside stored procedure.

    Hello, I have created one stored procedure. I am calling it from my process code. I want to use so many page variables like &APP_ID. I do not want to pass it as argument. Is it possible to use those variables without passing it in to procedure.? (&page_id. and also some application level variables )
    Any help is appreciated.
    Thank you.

    Ashif:
    The APEX documentation describes in detail the various ways of referencing APEX session state.
    http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/concept.htm#BEICHBBG
    Local variables declared in your process block are not available in APEX' session state. Hence you cannot refence such variables in a stored procedure.
    Varad

  • Using Parameterized Arrays in Stored Procedure

    I tried following code to pass array value to stored procedure but its giving error, as I am new to this procedure, please advise what am I missing ?
    Best Regards,
    Luqman
    My code is as below.
    CREATE TYPE num_array AS table of number;
    create or replace procedure give_me_an_array
    ( p_array in num_array )
    as
    begin
    for i in 1 .. p_array.count
    loop
    dbms_output.put_line( p_array(i) );
    end loop;
    end give_me_an_array;
    declare
    mdata num_array;
    begin
    mdata(1) := 1234;
    mdata(2) := 10;
    give_me_an_array(mdata);
    end;

    Hi Satya,
    Now I got it, thanks,
    Can you please advise, if I use the same stored procedure for EMP Table and use my array values to retrieve the selected EMPNo
    I tried following but I could not succeed.
    When I compile the stored procedure, error occurs:
    "inconsistent datatypes: expected NUMBER got NUM_ARRAY"
    for example:
    CREATE TYPE NUM_ARRAY AS TABLE OF NUMBER;
    Create or Replace Package TB_Data
    Is Type CV_Type Is REF CURSOR;
    END TB_DATA;
    Create or Replace Stored Procedure give_me_an_array
    (CV IN OUT TB_DATA.CV_TYPE,
    MEmpNo In Num_Array)
    Is
    Begin
    Open CV for
    Select * from EMP
    Where Empno in MEmpNo;
    End myProc;
    declare
    mdata num_array:=num_array(7839,7844);
    begin
    give_me_an_array(mdata);
    end;
    Best Regards,
    Luqman

  • How to find the columns and tables used in a stored procedure?

    Hi,
    Can someone suggest how to find the columns and tables used within a stored procedure?
    Thanks
    VBK

    For example:
    SQL> create or replace
      2    procedure p1
      3      is
      4          cnt number;
      5      begin
      6          select count(*) into cnt from emp;
      7  end;
      8  /
    Procedure created.
    SQL> select  referenced_owner,
      2          referenced_name
      3    from  dba_dependencies
      4    where owner = 'SCOTT'
      5      and name = 'P1'
      6      and referenced_type = 'TABLE'
      7  /
    REFERENCED_OWNER               REFERENCED_NAME
    SCOTT                          EMP
    SQL> SY.

  • How to customize events, execute stored procedures using JSF and ADF BC

    As a java beginner, I started with developing simple web application using JSF and ADF business component through visual and declarative approach. I need to know how to customize events, execute stored procedures, invoke functions on triggering events associated with rich controls. for eg. how to write customized functions on button click or checkbox click events to achieve business requirement and can be modified whenever required.
    Edited by: 792068 on Aug 31, 2010 9:40 PM

    Which business layer is prefered to create interactive data model: 1. ADF business components or 2. Enterprise JavaBeans using Java persistance API (JPA) or 3. Toplink 4. Portlets
    which minimizes writing low level codes and how much OOPS knowledge is required for creating above business layer binding data to viewcontroller layer?

  • How to select from a stored procedure?

    Lets say I have a simple stored procedures
    Create Procedure stp_test
    As
    Begin
     Select * from tbl1
    End
    Go
    I would like to be able to do this in SSMS (actually, I want to do this from ADODB)
    Select top 10 * from ...stp_test... Order By rowID
    It looks like I want to use OpenQuery on the stored Procedure, but I have not been able to do it correctly.  How can I query my stored procedure?
    Rich P

    It looks like I want to use OpenQuery on the stored Procedure, but I have not been able to do it correctly.  How can I query my stored procedure?
    If you want to use the OPENQUERY method , use the following.. follow this link...
    http://stackoverflow.com/questions/209383/select-columns-from-result-set-of-stored-procedure
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • How to output value from stored procedure

    Hi folks, I need to output the OrderFK from a stored procedure not really sure how to achieve this any help or tips much appreciated.
    Sql code below
    USE [TyreSanner]
    GO
    /****** Object: StoredProcedure [dbo].[AddCustomerDetails] Script Date: 11/12/2014 20:56:34 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    /***********************Declare variables ***********************/
    /******tblCustomer******/
    @Forename nvarchar(50),
    @Surname nvarchar(50),
    @HouseNo nvarchar(50),
    @CustAddress nvarchar(50),
    @Town nvarchar(50),
    @Postcode nvarchar(50),
    @ContactNo nvarchar(50),
    @EmailAddress nvarchar(50),
    /******tblLink_OrderProduct******/
    @ProductQuantity int,
    @TotalProductSaleCost decimal,
    @ProductFK int,
    @FittingDate date,
    @FittingTime Time
    As
    DECLARE @CustomerFK int;
    DECLARE @OrderFK int;
    Begin TRANSACTION
    SET NOCOUNT ON
    INSERT INTO [TyreSanner].[dbo].[Customer](Forename, Surname, HouseNo, CustAddress, Town, Postcode, ContactNo, EmailAddress)
    VALUES (@Forename,@Surname,@HouseNo,@CustAddress,@Town,@Postcode,@ContactNo,@EmailAddress)
    Set @CustomerFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Order] (CustomerFK)
    VALUES (@CustomerFK)
    SET @OrderFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
    VALUES
    (@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime)
    COMMIT TRANSACTION

    Hi brucey54,
    There’re several ways to capture the value from a Stored Procedure. In you scenario, I would suggest 2 options, by an output parameter or by a table variable.
    By an output Parameter, you need to make a little bit modification on your code as below:
    USE [TyreSanner]
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    @Forename nvarchar(50),
    @FittingDate date,
    @FittingTime Time,
    @OrderFK int output
    As
    DECLARE @CustomerFK int;
    --DECLARE @OrderFK int;
    Run the following code, Then @OrderFKvalue holds the value you’d like.
    DECLARE @OrderFKvalue int;
    EXEC AddCustomerDetails(your parameters,@OrderFKvalue output)
    Anyway if you don’t like to add one more parameter, you can get the value by a table variable as well. Please append “SELECT @OrderFK;” to your Procedure as below:
    USE [TyreSanner]
    GO
    ALTER PROCEDURE [dbo].[AddCustomerDetails]
    SET @OrderFK = SCOPE_IDENTITY()
    INSERT INTO [TyreSanner].[dbo].[Link_OrderProduct](OrderFK, ProductFK, ProductQuantity, TotalProductSaleCost, FittingDate, FittingTime)
    VALUES
    (@OrderFK, @ProductFK, @ProductQuantity, @TotalProductSaleCost, @FittingDate, @FittingTime);
    SELECT @OrderFK;
    Then you can call the Stored Procedure as below:
    DECLARE @T TABLE (OrderFK INT);
    INSERT @T EXEC AddCustomerDetails(your parameters) ;
    SELECT OrderFK FROM @T;
    There’re more options to achieve your requirement, please see the below link:
    How to Share Data between Stored Procedures
    If you have any question, feel free to let me know.
    Best Regards,
    Eric Zhang

  • How to pass arry in stored procedure

    I want to pass an array thru a JDBC to a stored procedure
    how can i pass a java variable string array to the store procedure using JDBC.
    here is my package for array:
    CREATE OR REPLACE PACKAGE TABLE_TYPES
    AS
    TYPE tString IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER;
    END;
    here is my store procedure:
    CREATE OR REPLACE PROCEDURE Declassification
    (P_COMPANY_ID IN SECURITY.COMPANY_ID%TYPE,
    P_SECURITY_NAME IN SECURITY.SECURITY_NAME%TYPE,
    P_SECURITY_SYMBOL IN SECURITY.SECURITY_SYMBOL%TYPE,
    P_CURRENCY IN SECURITY.CURRENCY%TYPE,
    P_ISIN IN SECURITY.ISIN%TYPE,
    P_LISTING_DATE IN VARCHAR2,
    P_SECTOR IN SECURITY.SECTOR%TYPE,
    P_INDUSTRY IN SECURITY.INDUSTRY%TYPE,
    P_PAR_VALUE IN VARCHAR2,
    P_PAR_VALUE_AS_OF IN VARCHAR2,
    P_BOARDLOT IN VARCHAR2,
    P_BOARDLOT_AS_OF IN VARCHAR2,
    P_MARKET_PRICE IN VARCHAR2,
    P_REQD_PUBLIC_OWN_PERC IN VARCHAR2,
    P_STATUS IN SECURITY.STATUS%TYPE,
    P_SECURITIES IN Table_Types.tString,
    P_ID OUT SECURITY.SECURITY_ID%TYPE)
    AS
    P_SECURITY_ID SECURITY.SECURITY_ID%TYPE;
         rec_count NUMBER;
    BEGIN
         SELECT COUNT(*)
         INTO rec_count
         FROM SECURITY;
         IF rec_count > 0 THEN
              SELECT MAX(TO_NUMBER(security_id)) + 1
              INTO P_SECURITY_ID
              FROM SECURITY;
         ELSE
              P_SECURITY_ID:=1;
         END IF;
              INSERT INTO SECURITY
              VALUES(P_SECURITY_ID, P_COMPANY_ID, P_SECURITY_NAME, P_SECURITY_SYMBOL, 'COMMON',
                        P_CURRENCY, P_ISIN, TO_DATE(P_LISTING_DATE,'mm/dd/yyyy'), P_SECTOR, P_INDUSTRY, TO_NUMBER(P_PAR_VALUE),
                        TO_DATE(P_PAR_VALUE_AS_OF,'MM/DD/YYYY'), TO_NUMBER(P_BOARDLOT), TO_DATE(P_BOARDLOT_AS_OF,'MM/DD/YYYY'),
                        TO_NUMBER(P_MARKET_PRICE), TO_NUMBER(P_REQD_PUBLIC_OWN_PERC), P_STATUS);
              INSERT INTO SECURITY_FINANCIAL(SECURITY_ID)
              VALUES (P_SECURITY_ID);               
              INSERT INTO SECURITY_TOTAL(SECURITY_ID)
                        VALUES (P_SECURITY_ID);
         COMMIT;
    END Declassification;

    I want to pass an array thru a JDBC to a stored
    procedure
    how can i pass a java variable string array to the
    store procedure using JDBC.
    here is my package for array:
    CREATE OR REPLACE PACKAGE TABLE_TYPES
    AS
    TYPE tString IS TABLE OF VARCHAR2(10) INDEX BY
    Y BINARY_INTEGER;
    END;
    There are two ways to pass in Arrays to stored procedures in Oracle:
    1. Define an Oracle TYPE outside a package and then use oracle.sql.ARRAY and oracle.sql.ArrayDescriptor to explain to the driver how the array is structured. This is what Avi has shown how to do.
    2. You can also pass in INDEX BY arrays of VARCHAR2 or NUMBER, provided they are indexed by BINARY_INTEGER. This is what you appear to want. In order to do this you'll probably need the 10g JDBC driver and code that uses the 'setPlsqlIndexTable' method of 'OraclePreparedStatement' to bind your array.
    Be careful about the values you pass into the 'setPlsqlIndexTable' method. You have to specify in advance how much data you expect to get back and how long each row is. The driver allocates memory based on these numbers. You code also needs to cope with arrays that have null elements.
    I work for a company that makes a JDBC code generator. A list of common situations we've encountered when working with Index By tables can be found here:
    http://www.orindasoft.com/public/PL-SQL%20Recordstwo.php4?siteloc=PL-SQL%20Recordstwo#probix
    David Rolfe
    Orinda Software
    Dublin, Ireland
    www.orindasoft.com
    Orinda Software makes OrindaBuild, which writes JDBC calls for PL/SQL and SQL.

  • Find all tables used in a stored procedure

    Hi,
    I have a requirement where i have to find all the tables used in a stored procedures from different  databases.
    Ex: i have a stored procedure where i use few tables from MASTER database and some from STAGE database.When i have written a query to find all tables used in the stored procedure, i am getting only those database table where i run the query and procedure
    exists.
    I have stored procedure SP1 in Master database, but i use the tables from both master and stage.
    When i run this, i am getting the tables only from Master database but not from stage. i hope my requirement is clear.
    I am trying to find all the tables from all databases used by a stored proc.
    ;WITH stored_procedures AS (
    SELECT 
    o.name AS proc_name, oo.name AS table_name,
    ROW_NUMBER() OVER(partition by o.name,oo.name ORDER BY o.name,oo.name) AS row
    FROM sysdepends d 
    INNER JOIN sysobjects o ON o.id=d.id
    INNER JOIN sysobjects oo ON oo.id=d.depid
    WHERE o.xtype = 'P')
    SELECT proc_name, table_name FROM stored_procedures
    WHERE row = 1
    ORDER BY proc_name
    Please advice

    Your question is not entirely clear. You need to run the query on different databases.
    You may find this blog post helpful
    How to get information about all databases without a loop
    Check the last script in that blog post and modify to your particular purpose.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to convert SQL server stored procedures to Oracle 11g

    Hi Experts,
    In SQL server 30 stored procedures are there how to convert all the stored procedure
    from SQL server to Oracle 11g.
    Please help me,
    Thanks.

    ramya_162 wrote:
    In SQL server 30 stored procedures are there how to convert all the stored procedure
    from SQL server to Oracle 11g.
    The single most fundamental concept you need to understand (grok in its fullness) is:
    ORACLE IS NOT SQL-SERVER
    There is very little, to NOTHING, in common between T-SQL (a language extension to SQL) and PL/SQL (integration of SQL with the language Ada, part of ALGOL family of languages that includes Pascal and C++).
    So taking a T-SQL procedure and porting it as is to PL/SQL is plain stupid.
    Why?
    Oracle sucks at trying to be SQL-Server.
    So how do you migrate from SQL-Server to Oracle?
    By taking the REQUIREMENTS that the T-SQL procedures address, and addressing these requirements using Oracle SQL and PL/SQL.

  • Database updation using XML and stored Procedure?

    Hello,
    I want to perform updation in multiple tables using XML files.Please suggest can I do updation using xml and stored procedure.
    If yes then which is more efficient and takes less time.
    1.Updation using xml files only
    2.Updation using xml files with stored procedure.
    3.Stored procedure alone.
    If direct xml and stored procedure communication is possible.then please write how.
    Thanks in advance for any help.

    Here's a sample. The next code drop of the XSQL Servlet will make the easy-to-do from within XSQL Pages:
    package package1;
    import org.w3c.dom.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Class1 extends Object {
    public static void main( String[] arg ) throws Exception {
    Connection conn = getConnection();
    CallableStatement ocs = conn.prepareCall("begin ? := App.HotItems('PAUL'); end;");
    ocs.registerOutParameter(1,OracleTypes.CURSOR);
    ocs.execute();
    ResultSet rs = ((OracleCallableStatement)ocs).getCursor(1);
    OracleXMLQuery oxq = new OracleXMLQuery(conn,rs);
    System.out.println(oxq.getXMLString());
    oxq.close();
    rs.close();
    ocs.close();
    conn.close();
    public static Connection getConnection() throws Exception {
    String username = "scott";
    String password = "tiger";
    String dburl = "jdbc:oracle:thin:@localhost:1521:xml";
    String driverClass = "oracle.jdbc.driver.OracleDriver";
    Driver d = (Driver)Class.forName(driverClass).newInstance();
    return DriverManager.getConnection(dburl,username,password);
    null

  • How to call pl/sql stored procedure in JDBC query dialogbox

    Hi,
    how to call pl/sql stored procedure in JDBC query dialogbox(reports 9i) .
    Cheers,
    Raghu

    please refer : Re: problem If you have more doubts, please ask in that question.

  • How to check performance for Stored procedure or Package.

    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.

    user13483989 wrote:
    Hi ,
    Can any one please tell me , how to check performance for Stored procedure or Function or Package
    Thanks&Regards,
    Sanjeev.Oracle has provided set of Tools to monitor the Performance.
    Profilers being one of them; If you wish to understand more on PL/SQL Optimization, please read PL/SQL Optimization and Tuning.
    See example of DBMS_PROFILER.
    See example of PLSQL Hierarchial Profiler

  • How to list dependencies of stored procedure in a package in oracle

    hi gurus,
    can any body help me to solve the below issue?
    how to list dependencies of stored procedure in a package in oracle?
    advanced thanks...

    It sounds like you're going to have trouble because you're trying to track dependencies at a more fine-grained level than Oracle does (at least prior to 11g, which I know does finer-grained dependency tracking for columns, so there may be something that would help you there).
    In Oracle, the entity is the package body. The procedure within the package does not have dependencies and does not depend on anything, it is part of the package body, which does have dependencies. You can see what tables are used by the package body via DBA_DEPENDENCIES. But if you're trying to track the dependencies for a particular procedure in a package, you'd either have to manually examine the code or you'd have to write your own PL/SQL parser.
    Justin

Maybe you are looking for

  • Should I buy the 4g iPod touch now? April 2012

    Hello. I am looking to buy a new iPod touch, but I need the latest and greatest. Now, here are my speculations: The New iPad just came out, so I don't know when Apple is going to have their next event. I assume theier next even will be in about 2 mon

  • Legal control error

    HI  ALL, I am getting following warning message while creating sales order for some materials . ,we have Legal control for order typy (or) check as "c"--legal control check in dispatch and export area "Reference number of a document from back error"

  • Symbol corruption in ibooks

    Hello All,      The symbols in my compositions are not working in ibooks, but they work perfectly in Safari, Firefox and Chrome.  They used to work in ibooks on my ipad until late December, then they suddenly seemed to become corrupt.  When the pages

  • How to covert .rdf(windows version) to .rep (Solaris) version

    Hi I have developed a report (.rdf) in windows. I want to deploy it in solaris machine. Application server is installed in the solaris machine only. I did the following and I received the following error bash-2.05$ /u02/oradata/data/APPS/bin/rwconver

  • Sa password is blank?

    Folks, Why does callmanager does not change the password of sa after the install? It asks for SQL password and still the sa passwors is blank and any odbc source can connect to the callmanager database when connecting to it?? why such a big security