sql server equivalent procedure in Oracle

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default sql server equivalent procedure in Oracle

    Hi I am a Coldfusion + Sql Server Programmer. Now I am working with Oracle
    which is new to me.

    I want to know how to create multiple recorset through oracle procedure
    eqiuvalent to SQL server procedure:

    create procedure test
    (
    @id number
    )
    as
    select * from table1 where id=@id
    select * from table2 where id=@id
    select * from table3 where id=@id



    CF code to call sql server procedure is

    <cfstoredproc procedure = " test" dataSource = "#datasource#" username =
    "#dbaccount#" password = "#dbpassword#">
    <cfprocparam type = "IN" CFSQLType = CF_SQL_number dbvarname="@ID" value =
    "#ID#">
    <cfprocresult name = "rs1" recordset="1">
    <cfprocresult name = "rs2" recordset="2">
    <cfprocresult name = "rs3" recordset="3">
    </cfstoredproc>



    reenaroy Guest

  2. Similar Questions and Discussions

    1. Does MySQL have a Stored Procedure equivalent?
      I've only used ASP and MS SQL Server before but I want to learn PHP and MySQL. Does MySQL have an equivalent of Microsoft's Stored Procedures (i.e....
    2. How to do equivalent to Crypt:CBC of Perl in Oracle pl/sql
      Look on CPAN for extproc-perl. Install (or have your DBA install); enjoy. nataraj wrote: -- Ron Reidy Oracle DBA
    3. Oracle/SQL Server and Informix Equivalent Command
      UNLOAD TO '/home/datadump/tablename.dmp' SELECT cField1, '~', cField2, (...) FROM sourcetable ?!! -----Original Message----- From: Ray M ...
    4. Oracle RowNum Equivalent
      Hello, I'm looking for an equivalent of the Oracle RowNum function in SQL Server, or some other method of solving this problem. In the DDL below...
    5. Is there any equivalent of Sql Server's temporary table in Oracle
      On Thu, 05 Dec 2002, gamaz@eathlink.net wrote: Let Oracle do the temporary set building. You code the join. -- Galen Boyer
  3. #2

    Default Re: sql server equivalent procedure in Oracle

    Use 3 stored procedures for each table and run them consequently or
    create one PL/SQL procedure using IF THEN structure (one for each table) and
    pass additional IN parameter from CF page on which value condition will be
    based. In cf run this procedure 3 times with values of new parameter values
    you need.

    CF_Oracle Guest

  4. #3

    Default Re: sql server equivalent procedure in Oracle

    Simplified code (more elegant solution) of Oracle stored procedure:
    CREATE OR REPLACE PROCEDURE test(p_ID IN NUMBER, p_table_name IN VARCHAR) AS
    BEGIN
    SELECT * FROM p_table_name
    WHERE iID = p_id
    END;

    In calling page:
    <cfstoredproc procedure = " test" dataSource = "#datasource#" username =
    "#dbaccount#" password = "#dbpassword#">
    <cfprocparam type = "IN" CFSQLType = CF_SQL_number
    variable = "p_ID"
    value = "#p_ID#">
    <cfprocparam type = "IN" CFSQLType = CF_SQL_varchar
    variable = "p_table_name"
    value = "#p_table_name#">
    </cfstoredproc>



    CF_Oracle Guest

  5. #4

    Default Re: sql server equivalent procedure in Oracle

    You need to use reference cursors in your stored procedure to pass your results
    back. Since you have to declare the reference cursor as a REF CURSOR, you need
    to declare it in a PL/SQL package specification, and your stored procedures
    need to be in a PL/SQL package. I have attached an example of the package and
    package spec declaration, with the procedure declaration as well.

    You can use the same ColdFusion code that you posted.

    Phil


    CREATE OR REPLACE PACKAGE test_pkg IS

    TYPE ref_cur_type
    IS REF CURSOR;

    PROCEDURE test_sp (in_id IN NUMBER, out_res1 OUT ref_cur_type,
    out_res2 OUT ref_cur_type,out_res3 OUT ref_cur_type);

    END test_pkg;
    /

    CREATE OR REPLACE PACKAGE BODY test_pkg IS

    PROCEDURE test_sp (in_id IN NUMBER, out_res1 OUT ref_cur_type,
    out_res2 OUT ref_cur_type,out_res3 OUT ref_cur_type)
    IS

    BEGIN

    OPEN out_res1
    FOR
    SELECT *
    FROM table1
    WHERE id=in_id;

    OPEN out_res2
    FOR
    SELECT *
    FROM table2
    WHERE id=in_id;

    OPEN out_res3
    FOR
    SELECT *
    FROM table3
    WHERE id=in_id;

    END test_sp;

    END test_pkg;
    /

    paross1 Guest

  6. #5

    Default Re: sql server equivalent procedure in Oracle

    Thanks Paross,

    you are right. Procedure is working perfectly.

    Only one thing I want to add.

    It should be resultset in place of recordset in these lines
    <cfprocresult name = "rs1" recordset="1">
    <cfprocresult name = "rs1" recordset="1">
    <cfprocresult name = "rs1" recordset="1">
    I know this was my fault :(

    reenaroy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139