Simple stored procedure - select with an if statement, returning a cursor

Hi,
I'm trying to create a very simple stored procedure, but having never worked with them before I'm not quite sure what I'm doing wrong.
Here's my code:
create or replace
procedure contact_return(
    v_contact_id IN varchar2,
    p_cursor OUT SYS_REFCURSOR)
AS
begin
  set sql_statement varchar2(4000) := '
    SELECT URN,
      FIRSTNAME,
      LASTNAME,
      TITLE,
      CREATED_DT,
      AREA_URN,
      MOBILE,
      WORK,
      EMAIL,
      ORG_NAME,
      ADDRESS,
      POSTCODE,
      IN_USE
    FROM CONTACT';
  if v_contact_id is not null then
    sql_statement := sql_statement || ' where urn = ' || v_contact_id;
  end if;
  open p_cursor for sql_statement;
end;
It's actually returning 2 errors:
Error(7,3): PL/SQL: SQL Statement ignored
Error(7,7): PL/SQL: ORA-00922: missing or invalid option
Which seem to be a problem with my set sql_statement line, but it looks correct to me?
Thanks

rajendra wrote:
Dear User,
It is not allowed to declare a variable inside the PL/SQL block means after begin ( in your case line no 7 ).
Lot of errors in your code.
Tell me your exact requirement and what you want to do , after that I will be able to solve your problem.
Thanks,
Rajendra
Well, you can declare after the begin, though it'll be as part of an embedded code block e.g.
SQL> ed
Wrote file afiedt.buf
  1  create or replace procedure contact_return(empno IN  number
  2                                            ,c     OUT SYS_REFCURSOR
  3                                            ) AS
  4  begin
  5    declare
  6      sql_statement varchar2(4000) := '
  7        select *
  8        from emp
  9        where empno = nvl(:1,empno)';
10    begin
11      open c for sql_statement using contact_return.empno;
12    end;
13* end;
SQL> /
Procedure created.
SQL> var x refcursor
SQL> exec contact_return(7788,:x);
PL/SQL procedure successfully completed.
SQL> print x;
     EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
      7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
so, it is allowed, as long as it's coded correctly.

Similar Messages

  • Simple stored procedure to validate multiple customer account numbers without defining a type

    I would like to create a simple stored procedure to validate up to 1-10 different customer account numbers at a time and tell me which ones are valid and which ones are invalid (aka exist in the Accounts table).  I want it to return two columns, the
    account number passed in and whether each is valid or invalid.  
    The real catch is I don't want to have to define a type and would like to do it with standard ANSI sql as my application has to support using multiple dbms's and not just sql server.  Thanks!

    Hi again :-)
    Now we have the information to help you :-)
    I write the explanation in the code itself. Please read it all and if you have any follow up question then just ask
    This solution is for SQL Server and it is not fit for all data sources. Please read all the answer including the comments at the end regarding other data sources. Basically you can use one String with all the numbers seperated by comma and
    use a SPLIT function in the SP. I give you the solution using datatype as this is best for SQL Server.
    In this case you should have a split function and this is very different from one database to another (some have it build it, most dont)
    ------------------------------------------------------------------- This part call DDL
    CREATE TABLE Accounts(
    AccountNbr [char](10) NOT NULL,
    CustomerName [varchar](100) NOT NULL,
    CONSTRAINT [PK_Accounts] PRIMARY KEY CLUSTERED ([AccountNbr] ASC)
    GO
    ------------------------------------------------------------------- This part call DML
    INSERT INTO Accounts(AccountNbr, CustomerName)
    SELECT
    cast(cast((9000000000* Rand() + 100000) as bigint ) as char(10)) as AccountNbr
    ,SUBSTRING(CONVERT(varchar(255), NEWID()), 0, 11) as CustomerName
    GO
    ------------------------------------------------------------------- Always I like to check the data
    SELECT * from Accounts
    GO
    /* Since you use random input in the DML and I need to check valid or in-valid data,
    Therefore I need to use this valid AccountNbr for the test!
    AccountNbr CustomerName
    6106795116 E689A83F-A
    -------------------------- Now we sytart with the answer ------------------------------------
    -- You should learn how to Create stored Procedure. It is very eazy especially for a developr!
    -- http://msdn.microsoft.com/en-us/library/ms345415.aspx
    -- dont use the SSMS tutorial! use Transact-SQL
    -- Since you want to insert unknown number of parameters then you can use Table-Valued Parameters as you can read here
    -- http://msdn.microsoft.com/en-us/library/bb510489.aspx
    -------------------------- Here is what you looking for probably:
    /* Create a table type. */
    CREATE TYPE Ari_AcountsToCheck_Type AS TABLE (AccountNbr BIGINT);
    GO
    /* Create a procedure to receive data for the table-valued parameter. */
    CREATE PROCEDURE Ari_WhatAccountsAreValid_sp
    @AcountsToCheck Ari_AcountsToCheck_Type READONLY -- This is a table using our new type, which will used like an array in programing
    AS
    SET NOCOUNT ON;
    SELECT
    T1.AccountNbr,
    CASE
    when T2.CustomerName is null then 'Not Valid'
    else 'Valid'
    END
    from @AcountsToCheck T1
    Left JOIN Accounts T2 On T1.AccountNbr = T2.AccountNbr
    GO
    -- Here we can use it like this (execute all together):
    /* Declare a variable that references the type. */
    DECLARE @_AcountsToCheck AS Ari_AcountsToCheck_Type;
    /* Add data to the table variable. */
    Insert @_AcountsToCheck values (45634),(6106795116),(531522),(687),(656548)
    /* Pass the table variable data to a stored procedure. */
    exec Ari_WhatAccountsAreValid_sp @AcountsToCheck = @_AcountsToCheck
    GO
    ------------------------------------------------------------------- This part I clean the DDL+DML since this is only testing
    drop PROCEDURE Ari_WhatAccountsAreValid_sp
    drop TYPE Ari_AcountsToCheck_Type
    -------------------------- READ THIS PART, for more details!!
    -- validate up to 1-10 different customer account numbers at a time
    --> Why not to validate alkl ?
    --> SQL Server work with SET and not individual record. In most time it will do a better job to work on one SET then to loop row by row in the table.
    -- tell me which ones are valid and which ones are invalid (aka exist in the Accounts table)
    --> If I understand you correctly then: Valid = "exist in the table". true?
    -- I want it to return two columns, the account number passed in and whether each is valid or invalid.
    --> It sound to me like you better create a function then SP for this
    -- The real catch is
    -- I don't want to have to define a type
    --> what do you mean by this?!? Do you mean the input parameter is without type?
    -- and would like to do it with standard ANSI sql
    --> OK, I get that you dont want to use any T-SQL but only pure SQL (Structured Query Language),
    --> but keep inmind that even pure SQL is a bit different between different databases/sources.
    -->
    -- as my application has to support using multiple dbms's and not just sql server.
    --> If you are looking a solution for an applicatin then you probably should use one of those approach (in my opinion):
    --> 1. You can use yourown dictunery, or ini file for each database, or resources which is the build in option forwhat you are looking for
    --> You can create for each data source a unique resources
    --> If the queries that need to be execut are known in advance (like in this question), then you can use the above option to prepare the rigt query for each data source
    --> Moreover! one of those resources can handle as general for "other ources"
    --> 2. There several ORM that already do what you ask for and know how to work with different data sources.
    --> You can use those ORM and use their query languge instead of SQL (for example several work with LINQ).
    I hope this is helpful :-)
    [Personal Site] [Blog] [Facebook]

  • Error Calling a simple stored procedure

    Hello. I'm using the code below to call a simple stored procedure which returns a number. Why does it throw the exception (Also below)?
    Thank you,
    Alek
    =======================
    Code:
    import java.sql.*;
    public class Connect
    public static void main (String[] args)
    Connection conn = null;
    //CallableStatement stmtMySQL = null;
    long local_callkey = 0;
    try
    Class.forName("com.mysql.jdbc.Driver");
    String userName = "abc";
    String password = "def";
    String url = "jdbc:mysql://mysqlserver/sxma";
    Class.forName ("com.mysql.jdbc.Driver").newInstance ();
    conn = DriverManager.getConnection (url, userName, password);
    System.out.println ("Database connection established");
    String theMySQLCall = "{?=call sxma.sp_getnumber()}";
    CallableStatement stmtMySQL = conn.prepareCall(theMySQLCall);
    stmtMySQL.registerOutParameter(1, Types.INTEGER);
    stmtMySQL.execute();
    int res = stmtMySQL.getInt(1);
    if(res!=0)
    throw new Exception("MySQL Query exception return code: " + String.valueOf(res) + ")");
    else
    local_callkey = stmtMySQL.getLong(1);
    System.out.println("Local key is: " + local_callkey);
    catch (Exception e)
    System.err.println ("Cannot connect to database server!");
    e.printStackTrace();
    finally
    if (conn != null)
    try
    conn.close ();
    System.out.println ("Database connection terminated");
    catch (Exception e) { /* ignore close errors */ }
    ================
    Exception:
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
         at java.lang.String.charAt(String.java:444)
         at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:951)
         at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1277)
         at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3640)
         at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:506)
         at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:401)
         at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4072)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4146)
         at com.mysql.jdbc.Connection.prepareCall(Connection.java:4120)
         at Connect.main(Connect.java:20)
    Thank you for your help

    Well, there's certainly something about that line that it doesn't like.
    I'm not really familiar enough with MySQL to remote-debug this one for you, but it seems to be dying while trying to reconcile that call to its metadata for the sproc. Check the sproc declaration -does it return a single out value? Or does it have a single out value in the parameter list (not the same thing, I think) ? And so on.
    Also, with the amended call that I provided is the failing stack trace identical, or slightly different? If different, could you post that too please?
    Finally, do you have a known good sproc call that you can sanity check against? Perhaps take one of the examples from the MySQL site and check that that will work with their reference code?

  • Stored Procedure Call with only Input Parameter

    Hi, The Example at Oracle Toplink Developer's Guide, Volume 5 uses an output param named IS_VALID. How Can I Call a Stored Procedure that has only Input Param ? If I don't use an Ouput Param Toplink throw the following Exception:
    *Excepción [TOPLINK-4002]* (Oracle TopLink - 10g Release 3 (10.1.3.3.0) (Build 070620)): oracle.toplink.exceptions.DatabaseException Excepción Interna: java.sql.SQLException: ORA-00900: invalid SQL statement
    Here's the Sample Code Depicted at the Guide:*
    Example 98–48 Stored Procedure Call with an Output Parameter
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("CHECK_VALID_POSTAL_CODE");
    call.addNamedArgument("POSTAL_CODE");
    call.addNamedOutputArgument(
    "IS_VALID", // procedure parameter name
    "IS_VALID", // out argument field name
    Integer.class // Java type corresponding to type returned by procedure
    ValueReadQuery query = new ValueReadQuery();
    query.setCall(call);
    query.addArgument("POSTAL_CODE");
    Vector parameters = new Vector();
    parameters.addElement("L5J1H5");
    Number isValid = (Number) session.executeQuery(query,parameters);
    Here's my code
    StoredProcedureCall call = new StoredProcedureCall();
         call.setProcedureName("MYSTOREDPROCEDURE");
         call.addNamedArgument("INPUTPARAM1");
         call.addNamedArgument("INPUTPARAM2");
         call.addNamedArgument("INPUTPARAM3");
         call.addNamedArgument("INPUTPARAM4");
         call.addNamedArgument("INPUTPARAM5");
         call.addNamedArgument("INPUTPARAM6");
         ValueReadQuery query = new ValueReadQuery();
         query.setCall(call);
         query.addArgument("INPUTPARAM1");
         query.addArgument("INPUTPARAM2");
         query.addArgument("INPUTPARAM3");
         query.addArgument("INPUTPARAM4");
         query.addArgument("INPUTPARAM5");
         query.addArgument("INPUTPARAM6");
    Vector parameters = new Vector();
         parameters.addElement("INPUTVALUE1");
         parameters.addElement("INPUTVALUE2");
         parameters.addElement("INPUTVALUE3");
         parameters.addElement("INPUTVALUE4");
         parameters.addElement("INPUTVALUE5");
         parameters.addElement("INPUTVALUE6");
         uow.executeQuery(query,parameters);
    Regards,
    Manuel

    You need to use a DataModifyQuery as your query does not return anything.
    James : http://www.eclipselink.org

  • Error when linking report to stored procedure defined with one input parm

    Error when linking report to stored procedure defined with one input parameter
    The report will work ok, when the parameter is removed from the stpred procedure
    An unhandled win32 exception occurred in crw32.exe[4480]
    Stored Proc (sql server 2005)
    USE [Allegro]
    GO
    /****** Object:  StoredProcedure [dbo].[SP_Test]    Script Date: 07/08/2009 10:42:14 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[SP_Test](@valuationmode VARCHAR(55)) as
    Begin
    select
         valuation,
         valuationtime,
         valuationmode
    from valuation
    where valuationmode = @valuationmode;
    End;

    This is an example of a stored procedure that is trying to be linked to a new report as the only datasource.
    If I remove the parameter I can create a report, however this will return all of the results of thw query to the report, rather than the desired results. If I add the parameter on the Crystal Report, the stored procedure then has to return all of the results to Crystal and then perform the filtering of records. By using a parameter in the stored procedure, you should be able to do all of the filtering as part of the query on the databse server, making this more efficient.

  • Show the result of a simple stored procedure

    Hi,
    I am new to Application Express and I would like to test a simple stored procedure. The doc and examples are not very clear to me. Basically, I have a procedure that takes an id and returns the table of elements corresponding to this id. Here's an example :
    create or replace function myProc(id varchar2 := 'NULL')
    return nameList is
    myList nameList;
    begin
    myList := getNames(id);
    return myList;
    end myProc;
    I built a form that takes as input the id but I could not figure out how to show the returned table in a report, i.e. how to attach the procedure to an event and how to display the result. Could someone explain me how to perform this task.
    Best,
    Othman.

    If you are so new to ApEx, you will not want to start using procedures before understanding
    how the whole system works. Looking at your requirement, using a procedure to report
    on a table is not required. However, I have an example how to use procedure with
    in and out parameters on a page:
    http://htmldb.oracle.com/pls/otn/f?p=31517:70
    In this demo application you may finde some usefull examples.
    Denes Kubicek

  • Problem with JDBC results calling simple stored procedure in VC 7.0

    Hi all,
    I am building a simple VC model which calls a stored procedure on a JDBC database. I have created the system in the portal, defined the alias and user mapping, the connection test is fine and the VC "find data" lists my bespoke stored procedure.
    The stored procedure is :
    CREATE PROCEDURE dbo.dt_getBieUsers
    AS
    select * from dbo.emailuserlink
    GO
    When I test it using query analyser, it returns 3 records each with the two fields I expect - user and email address.
    I drag the model onto the workspace in VC and create an input form ( with just a submit button ). i drag the result port out to create a table. This has no fields in it.
    I build and deploy as flex and the app runs, I click the submit button and SUCCESS! I get 3 records in my table each with 2 fields. The data is all correct. The problem with this is the fields are determined at runtime it seems.
    I go back to the table and add 2 columns "email" and "address".
    i build and deploy and run the app. Again I get 3 records, but this time the contents of all of the rows is not data, but "email" and "address". The data has been replaced by the header texts in all of the rows.
    Can anyone help? Why isn't the data being put in my columns as I would expect?
    I tried to build and deploy the app as Web Dynpro rather than Flex to see if it was a bug in Flex. The application starts but when I click the submit button to run the JDBC stored procedure I get a 500 Internal Server Error
    com.sap.tc.wd4vc.intapi.info.exception.WD4VCRuntimeException: No configuration is defined for the entry JDBCFunction
        at com.sap.tc.wd4vc.xglengine.XGLEngine.createComponentInternal(XGLEngine.java:559)
        at com.sap.tc.wd4vc.xglengine.XGLEngine.getCompInstanceFromUsage(XGLEngine.java:362)
        at com.sap.tc.wd4vc.xglengine.XGLEngine.getCompInstance(XGLEngine.java:329)
        at com.sap.tc.wd4vc.xglengine.wdp.InternalXGLEngine.getCompInstance(InternalXGLEngine.java:167)
        at com.sap.tc.wd4vc.xglengine.XGLEngineInterface.getCompInstance(XGLEngineInterface.java:165)
    The JDBC connection I am using has a connection URL of jdbc:sap:sqlserver://localhost;DatabaseName=BIEUSERS
    and a driver class of com.sap.portals.jdbc.sqlserver.SQLServerDriver
    Can anyone solve my wierd problems?
    Cheers
    Richard

    Hi Richard,
    After you drag and drop the data service, right click on it and choose "Test data service". Then click on "Execute" and after you see the result on the right, click on "Add fields" button (inside the same window). Now you'll see that the fields are on the tabel. This is required only for JDBC data services, since this data (how the resultset is built) is not know in DT and it needs to be run firest - then analysed and only then you have to add the fields to the table).
    Regards,
    Natty

  • VC 7.0 Oracle stored procedures resultset with ref cursor

    Can VC (we are on NW7 SP13) handle Oracle's datatype ref cursor - which is the standard solution in Oracle to return result sets - as the return value of a stored procedure?
    When testing a data service in the VC story board based upon a simple Oracle function like:
    create or replace package pkg_dev
    is
       type t_cursor is ref cursor;
    end;
    create or replace function vc_stub return pkg_dev.t_cursor
    as
    l_cursor pkg_dev.t_cursor;
    begin
    open l_cursor for select ename from emp;
    return l_cursor;
    end;
    (just as example - I know that could be easily retrieved using the BI JDBC connector framework and accessing tables / views)
    I am always running in the "portal request failed ( Could not execute Stored Procedure)" error - so I am not able to use the "add fields" function to bind the output.
    The defaulttrace contains entries like:
    Text: com.sap.portal.vc.HTMLBRunTime
    [EXCEPTION]
    com.sapportals.connector.execution.ExecutionException: Could not execute stored procedure
    Caused by: java.sql.SQLException: Invalid column type
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    We deployed Oracle's own jdbc-driver for Oracle 10g. Using that driver and a portal jdbc connector framework entry the stored procedures of the Oracle database user mapped to the portal user are discovered and available in the "Find Data Services" section.

    We deployed the drivers as described in the HowTo Papers (e.g.Hwo to Configure UD Connect on the J2EE Server for JDBC Access to External Databases). When deploying the drivers you assign a freely definable name for the set of Oracle's jar-files (eg. oracle_10) as library name. Having deployed the drivers in that way only System Definitions via BI JDBC connector framework were working. With a little help from SAP Support (call lasted more than 2 months till a very capable member of the support team made things working in a very short time) we got the portal jdbc connection with Oracle's jar-files working:
    Here are instructions how to add reference:
    1. Connect to the j2ee using telnet, e.g in the cmd window type:
    telnet <host> <port> + 8, enter uid and pwd of j2ee admin.
    2. jump 0
    3. add deploy
    4. change_ref -m com.sapportals.connectors.database <your lib name>       <your lib name = oracle_10>
    Trying to manually add this reference in visual admin connector container for JDBCFactory failed - reference could be added and saved, but then disappeared (at least in NW7 with SP12). Adding the reference as described above solved the problem.

  • Help writing a simple stored procedure

    Hello, all:
    I have normally done fine writing functional anonymous procedures, but I want to tighten up my trade a little. I have been looking through my PL/SQL book and the examples are too simple for the creation of a stored procedure along these lines:
    create or replace procedure convertPIDM( iv_PIDM number)
    is
    v_PIDM number;
    v_Banner_ID varchar2;
    v_first_name varchar2;
    v_first_name varchar2;
    begin
    /* select spriden_id, spriden_first_name, spriden_last_name from spriden */
    select spriden_id into v_Banner_ID from spriden
    where spriden_pidm = iv_PIDM
    and spriden_change_ind is null;
    DBMS_OUTPUT.put_line('Banner ID: ' || v_Banner_ID );
    end;
    I am getting a "Warning: compiled but with compilation errors." I don't understand why. Could someone point the issue out to me, please.
    Thank you.

    Okay, the answer almost bit me. I forget to add the size (ranges) to the varchar2.
    create or replace procedure convertPIDM( iv_PIDM number)
    is
    v_PIDM number;
    v_Banner_ID varchar2(8);
    v_first_name varchar2(30);
    v_first_name varchar2(30);
    begin
    --select spriden_id, spriden_first_name, spriden_last_name from spriden
    select spriden_id into v_Banner_ID from spriden
    where spriden_pidm = iv_PIDM
    and spriden_change_ind is null;
    DBMS_OUTPUT.put_line('Banner ID: ' || v_Banner_ID );
    end;
    show errors

  • SSRS. Not passing fields/parameters to report when stored procedure keeps parameters inside IF statement

    So what I mean:
    I have stored procedure like this:
    CREATE PROCEDURE sp_Example
    @param1 NVARCHAR(20) = '',
    @param2 DATE = ''
    AS
    BEGIN
    IF (SELECT COUNT(*) FROM Table1 WHERE (Name = @param1 OR @param1 = '') AND (StartDate = @param2 OR @param2 = '')) > 2
    BEGIN
    SELECT Name, Date, Price, Etc
    FROM Table2
    WHERE (Name = @param1 OR @param1 = '') AND (StartDate = @param2 OR @param2 = '')
    END
    IF (SELECT COUNT(*) FROM Table1 WHERE (Name = @param1 OR @param1 = '') AND (StartDate = @param2 OR @param2 = '')) < 2
    BEGIN
    SELECT Name, Date, Price, Etc
    FROM Table3
    WHERE (Name = @param1 OR @param1 = '') AND (StartDate = @param2 OR @param2 = '')
    END
    END
    So in stored procedure are some input parameters and they are passed into IF statement.
    If I use this stored procedure as report's dataset (Microsoft Visual Studio 2013) in following:
    Add
    Dataset > Query
    Type: Stored Procedure > sp_Example It
    do NOT get any fields, but get parameters
    If I use this stored procedure in following:
    Add
    Dataset > Query
    Type: Text > EXECUTE
    sp_Example It get all required fields, but do NOT get parameters
    Of course If I add manually parameters or fields It not working.
    If I change IF statement
    in stored procedure something like:
    IF (1 < 3)
    BEGIN
    SELECT Name, Date, Price, Etc
    FROM Table3
    WHERE (Name = @param1 OR @param1 = '') AND (StartDate = @param2 OR @param2 = '')
    END
    It normally working in report (getting all fields and parameters). So problem is that I pass parameters to IF statement.
    Have you any ideas how to pass parameters to IF statement
    and get It correctly working on report?

    Hi Stanisolvas,
    Per my understanding that you are experending some issue when using the stored procedure to create the dataset, you can't get the fields to display under the dataset, right?
    I have tested on my local environment with the same script as your and can't reproduce the issue, Please try to check and provide more details information according to below points:
    What do you mean of not get any fields, Is that mean no table header along with the value will display? If you got any error message, please provide it.
    Did you use any temp table in the stored procedure, if so, the issue can be caused by the temp table you are using, please don't use temp table in it which will cause no fields display.
    If you use the second method to execute the procedure, please check to make sure you have added the script like below to make the parameters display in the report:
    exec sp_Example @Param1=@Param1,@Param2=@Param2
    Please execute the stored procedure in the SQL Server Management Studio like below to see if the stored procedure will works fine:
    exec sp_Example @Param1='Test1',@Param2='2014-10-15'
    If this work fine in the management studio, please try to create an new report to re-add this procedure.
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Error in a simple stored procedure

    Hi all,
    I am problem in calling the following stored procedure.
    CREATE OR REPLACE PROCEDURE sp_procedure (yearVar char)
    AS
    cp char;
    BEGIN
    SELECT DISTINCT id INTO cp FROM Directory
    WHERE year = 'yearVar';
    END sp_procedure;
    Calling part in my jsp page :
    String query = "{Call sp_crossCostPool(?)}";
    CallableStatement cstmt = con.prepareCall(query);     
    cstmt.setInt(1,1);
    ResultSet rs = cstmt.executeQuery();
    while (rs.next()){
    out.println(rs.getString(1));
    Error : SQLException: ORA-01403: no data found ORA-06512: at "APPINF.SP_CROSSCOSTPOOL", line 5 ORA-06512: at line 1
    Which part that I go wrong?? Could someone please give me some advice?
    By the way, as I am new to store procedure I have some qns on it.. what does it mean by this sentence -->cstmt.setInt(1,1);
    what does it do?? By looking at my calling part.. how does it pass the input parameter to the stored procedure?
    Thanks alot..

    Hi again.. I have new errors when i want to test it out at sqlplus..
    my stored procedure goes like this :
    CREATE OR REPLACE PROCEDURE sp_CostPool1 (yearVar IN Int, etyVar IN varChar, optVar IN varChar, valVar IN int)
    AS
    cp int;
    ety char(3);
    BEGIN
    SELECT DISTINCT costpool_id, entity INTO cp, ety FROM Table WHERE year = yearVar and entity = etyVar and optVar = valVar;
    END sp_CostPool1;
    SQL> exec sp_crossCostPool1 (2002, CSG, ubr6, 372);
    begin sp_crossCostPool1 (2002, CSG, ubr6, 372); end;
    ERROR at line 1:
    ORA-06550: line 1, column 32:
    PLS-00201: identifier 'CSG' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Can I know what is wrong??

  • Stored Procedure Universe with Webi and Xcelcius

    Business Objects XI 3.0, Xcelcius 2008
    Created a stored procedure Universe on top of SQL Server 2005.  The stored procedure inserts a row into a table, and works fine when calling it from SQL Server server.  When I call it from Webi it wraps a transaction around the call and rolls it back after executing it.
    Are the new Stored Procedure Universes in 3.0 meant to be only "read only" and don't allow inserts/updates/deletes commands in the stored procedures they execute ? Seems a little short sighted if they are.
    Thanks,
    Keith
    Edited by: Keith Johnson on Aug 16, 2008 11:30 PM

    Keith,,
    absolutely with universe designer you can never use such like those procedures, you can not use insert or update statements on those procedure, it will give you errors.
    but in xcelsius, you can do it with another layer
    check this please
    xml data button
    http://resources.businessobjects.com/support/cx/samples/learning/downloads/ttv4-xml_data_button.pdf
    XCELSIUS DYNAMIC DATA SOURCE
    Dynamic datasources for Xcelsius
    good luck

  • Stored Procedure error with JDBC:ODBC

    Hi,
    I am trying to run a stored procedure on RDMS (Uniaccess ODBC). This has 2 input parameters and returns a resultset of 3 columns. The following is the error I am getting and am stumped. Please help..
    (similar call statement works with VB and ADO)
    --------output ---------------
    Calling MGC005
    inside resultset sun.jdbc.odbc.JdbcOdbcCallableStatement@129206
    row 1
    get string 0004
    get string 00000
    get string
    SQLEcception : java.sql.SQLException: [AIS][UniAccess ODBC Driver]Invalid Column Number//Specified column is before the column specified in the previous call
    ----------------------source code ------------------
    import java.awt.Graphics;
    import java.sql.*;
    public class JdbcTest {
    public JdbcTest() {
         Connection con;
         CallableStatement stmt;
    try {
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    catch (Exception ex) {
    System.out.println ("Database Driver not found");
    System.exit(0);
    try {
    String msDbUrl = "jdbc:odbc:CMS_TEST_ODBC";
    con = DriverManager.getConnection(msDbUrl, user, password );
    stmt = con.prepareCall("{ call MGC005(?, ?)}");
              stmt.setString( 1, "CH" );
              stmt.setString( 2, "ARRINGTON0909170320010615" );
    //          stmt.registerOutParameter( 1, java.sql.Types.VARCHAR);
    //          stmt.registerOutParameter( 2, java.sql.Types.VARCHAR );
    //           stmt.registerOutParameter( 3, java.sql.Types.VARCHAR );
              System.out.println( "Calling MGC005 " );
         ResultSet rs = stmt.executeQuery();
              while (rs.next()) {
    System.out.println( " inside resultset " + rs.getStatement() );
    System.out.println( " row " + rs.getRow() );
    System.out.println( " get string " + rs.getString(1) );
    System.out.println( " get string " + rs.getString(2) );
    System.out.println( " get string " + rs.getString(3) );
              String i = rs.getString (1);
              String s = rs.getString (2);
              String t = rs.getString (3);
    String text = i + " " + s ;
    System.out.println ( " Output " + text);
         stmt.close();
    con.close();
    } catch( SQLException ex ) {
    System.out.println ("SQLEcception : " + ex);
    public static void main(String[] args) {
    new JdbcTest();
    }

    Hi,
    The error seems to occur on the line:
    String i = rs.getString (1);
    The error exactly states what is occuring: "Specified column is before the column specified in the previous call". Try limiting the call to getString() to one for each column for each row.
    Try replacing these lines:
    System.out.println( " get string " + rs.getString(1) );
    System.out.println( " get string " + rs.getString(2) );
    System.out.println( " get string " + rs.getString(3) );
    String i = rs.getString (1);
    String s = rs.getString (2);
    String t = rs.getString (3);
    with something like:
    String i = rs.getString (1);
    System.out.println( " get string " + i);
    String s = rs.getString (2);
    System.out.println( " get string " + s);
    String t = rs.getString (3);
    System.out.println( " get string " + t);
    Hope this works,
    Kurt.

  • Stored Procedure Call with Connection Pools

    Hi everybody,
    I have changed my Database-Connection to Connection Pooling.
    No I try to call a stored procedure like this:
    Connection connection;
    CallableStatement callStmt;
    Integer sp_result;
    //--- Set callable stored procedure
    String call = "{?=call myStoredProcedure(?,?,?)}";
    try {
    if( connection != null ) {
    callStmt = connection.prepareCall( call );
    callStmt.registerOutParameter( 1, java.sql.Types.INTEGER );
    callStmt.setInt( 2, 3 );
    callStmt.setString( 3, plz );
    callStmt.setString( 4, ort );
    callStmt.execute( call );
    sp_result = new Integer( callStmt.getInt(1) );
    callStmt.close();
    result = sp_result.intValue();
    } else {
    log.error( "Connection = null" );
    } catch( SQLException ex ) {
    log.error( ex.toString() );
    ServletUtils.forwardRequest(this, request, response,
    "/error.jsp", "errorMsg", ex.toString() );
    Without Connection Pooling, my Connection is of
    'weblogic.jdbc.mssqlserver4.MicrosoftConnection'
    With Connection Pooling my Connection is of
    'weblogic.jdbc2.rmi.SerialConnection'
    And now, the stored procedure can't be found anymore.
    There comes an SQLException:
    Gespeicherte Prozedur 'myStoredProcedure' konnte nicht gefunden werden.
    Severity 16, State 62, Procedure 'myDBServer null', Line 5
    One possibility is that the SerialConnection can't call the stored procedure
    like the Microsoft-specific Connection (I use MS-SQL-Server)
    Another is that the call have to be another stucture.
    I would be pleased if somebody is expirienced in this behaviour.
    Thousand thanx,
    Hammer.

    You need to use a DataModifyQuery as your query does not return anything.
    James : http://www.eclipselink.org

  • REF CURSOR RETURNED FROM STORED PROCEDURE OPENED WITH CURRENT_USER PRIVILEGES

    Hi.
    I was wondering if anyone knows when this bug will be fixed. The bug# is 899567 off of metalink.
    I am running into this problem as well, and we do not want to use OCI/SQLNet as the fix. We have an application with secure data concerns and only want to give access to stored procedures to an application user.
    Thanks,
    Brad

    I'm using version 8.1.6.0.0 on a W2K server.
    PS: a strange behaveour
    if i try to insert a row using the following anonymous pl/sql block
    begin
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    end;
    i get the following error msg
    ERROR at line 1:
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-302: component 'OBJ_T' must be declared
    but if i use only the sql command from the sql plus prompt
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    the row is inserted.
    OBJ_T is the object type(id number, label varchar2, class ref class_t),
    OBJECTS is a table of obj_t,
    CLASS_T is an object type(id number, label varchar2)
    CLASSES is a table of CLASS_T.
    null

Maybe you are looking for