Error in Simple Stored Precedure!!

Hi Folks,
I am new to oracle...At present i'm working in MS SQL Server...I am trying to write a small stored procedure which retrieves a result set(ie rows) from a given table in Oracle 8i.I have written a procedure as
create procedure test is
begin
select * from stu;
end
and I executed the above procedure.It was showing Procedure created with compilation errors.What would be the problem?.Same procedure is executing with out any errors in SQL Server.
Can anyone pls give me a solution for this?.
Thanks in advance,
Murali

Murali,
I answered a question just like this a little while ago. I programmed TSQL for about 5 years and yes it would be nice if PL/SQL could return a data stream, but it doesn't. However as I explain below I use a method I like even better, since I would rather have an object (a view) that I can get this data from anyway. Do remeber a function can return a data stream though so you might want to consider that as well. Anyway this is what I had said ...
--[START NOTE]
I've run into this problem allot with Oracle. If I was to point out the biggest difference between PL/SQL and TSQL it is this ability your wanting, to have a data stream come back from a oracle function/proc/package. In TSQL you can make a proc that simply says, SELECT * from T1, and when you execute this, you get a data stream back. Oracle does not do this, but there is a flip side. There is a different approach I've realized to this and I would NOT use this data return stream ability even if it was supported. This is what I usually do when I want data from a package ...
Use a VIEW.
Call a procedure that creates a database VIEW of the SELECT query you want. (you will have to remember the name of the view) , Then simply do SELECT * FROM <view name you made>. Doing it in this fashion allows so many more abilities than just getting a data set back. Your data set is now an object which you can query over again and even other sessions have access to it. See the basic example below ...
SQL> create or replace PROCEDURE sp_sql (ps_in_sql in varchar2)
2 as
3 ls_sql varchar2(2000) := upper(trim(ps_in_sql));
4 BEGIN
5 execute immediate ls_sql;
6 end sp_sql;
7 /
Procedure created.
SQL> show errors
No errors.
SQL>
SQL> execute sp_sql('create or replace view v1 (N1) as select distinct t1.n1 from t1 order by t1.n1'
PL/SQL procedure successfully completed.
SQL> select * from v1;
N1
1
2
3
4
5
6
7
8
9
10
10 rows selected.
This is just the basic principle to get a data stream back from running a single execute command, with one additional SELECT * from VIEW. The main way I use this ability is just passing the WHERE clause and recompile the view inside the procedure, since I may want a date range, an IN clause, other criteria, but in the end I just do 1 EXECUTE and SELECT * from VIEW.
This method is better that just trying to get a proc to return a data stream. Make the proc create an object that you can bind to with active objects (like grids, drop down boxes, etc.), and after you now have the view to even do more complex SQL on, since you CANT query your data stream to get only the 'JOHN DOE' entries back.
Anyway I hope this helps a little, try it and you'll find this works very well.
Tyler.
--[END NOTE]

Similar Messages

  • ORA-00942 error in simple stored proc

    Guys,
    I'm trying to learn to write some procedures in oracle and have started with the following;
    CREATE OR REPLACE PROCEDURE sp__who
    IS
    BEGIN
    FOR rec IN (SELECT s.SID, s.serial#, p.spid, s.osuser, s.program,
    s.status
    FROM v$process p, v$session s
    WHERE p.addr = s.paddr)
    LOOP
    DBMS_OUTPUT.put_line ('SID: ' || rec.SID);
    DBMS_OUTPUT.put_line ('Serial Nbr: ' || rec.serial);
    DBMS_OUTPUT.put_line ('SPID: ' || rec.spid);
    DBMS_OUTPUT.put_line ('OS User: ' || rec.osuser);
    DBMS_OUTPUT.put_line ('Program: ' || rec.program);
    DBMS_OUTPUT.put_line ('Status: ' || rec.status);
    DBMS_OUTPUT.put_line ('------------------------------');
    END LOOP;
    END sp__who;
    SHOW ERRORS;
    This is failing with a PL/SQL: ORA-00942: table or view does not exist - it seems to be complaining about v$session and v$process - I do have access to these as I can run the select by itself fine...
    Any ideas why?
    Also, can anyone suggest a good website for learning PL/SQL and oracle procedure writing?
    Cheers!
    Pete

    I'm a DBA (Sybase / SQL Server DBA!) and I'm learning to support oracle instances in my current role.
    The stored procedure will be used to extract a list of users active or otherwise in the database... Ideally giving enough information to make decisions easier when it comes to killing processes, etc. Replicating in part, the sybase equivalent stored procedures. (long term plan will be to recreate all the sybase sp_ procedures in oracle)
    What's written so far is obviously very basic and will need further enhancements to make it useful as intended - but having zero experience of writing procs in Oracle I thought it best to start with a simple select :-)

  • 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?

  • 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.

  • ERROR-Logging of Stored Procedure (Stop / Going on after error + logging)

    Hi @all,
    I am using a Stored Procedure which is very simple:
    =>The stored procedure is selecting many tousands of records from table1 + table2.
    => Some values (records) will be summarized (aggregated/group by).
    =>After this selection and summarizing, this records will be deleted from table3 (if they exist in table3).
    =>Then the selected records will be inserted in table3.
    Now I want to do the following:
    Is there a way to log the errors of the stored procedure?
    For example, the stored procedure is copying many thousands of records.
    If there is a problem on copying/ inserting a record to table3, then I want a error-log in a loggin_table.
    Is there a way to write the error-logs from a stored procedure to a special table in database?
    I want to do this in 2 ways:
    1) On error the error is logged and the stored procedure is stopped.
    2) On error the error is logged and the stored procedure is going on to insert/summarize the next record.
    I don't know how I can get these errors of a stored procedure. Maybe it isn't possible? Or is it better to use a function?
    Hope anyone can give me a hint?
    Thanks a lot.
    Best regards,
    Tim

    Hi
    option one:
    as i know you can have another table without primer key (log table).
    then before you insert into table, select the record count using primary key. if it is duplicate then put those record into the table.
    option two:
    write the log into file.
    declare
    f utl_file.file_type;
    s varchar2(200);
    begin
    f := utl_file.fopen('SAMPLEDATA','sample1.txt','R');
    loop
    utl_file.get_line(f,s);
    dbms_output.put_line(s);
    end loop;
    exception
    when NO_DATA_FOUND then
    utl_file.fclose(f);
    end;
    refer : http://www.psoug.org/reference/OLD/utl_file.html
    regards
    upul.
    Edited by: Upul Indika on Apr 9, 2009 12:45 PM

  • I can no longer open excel documents in my doc to go app. Error message simple reads can not open attachment. And the attachment is now a winmail.dat

    I can no longer open excel documents in my doc to go app. Error message simple reads can not open attachment. And the attachment is now a winmail.dat

    winmail.dat files usually mean the email has been sent in rich text format - you could either the person who sent it to send it in a different format e.g. plain text or HTML, or there are a few apps in the store that support it (search for winmail.date in the store).
    winmail.dat files : http://support.apple.com/kb/TS1506

  • RMAN-03015: error occurred in stored script Memory Script

    getting this error during
    target db is 10202 & aux is 10204 ?
    duplicate target database to dcxt;
    RMAN> connect TARGET SYS/spurs_04@capq;
    PL/SQL package SYS.DBMS_BACKUP_RESTORE version 10.02.00.03 in TARGET database is not current
    PL/SQL package SYS.DBMS_RCVMAN version 10.02.00.03 in TARGET database is not current
    connected to target database: CAPQ (DBID=2420849281)
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-00601: fatal error in recovery manager
    RMAN-03004: fatal error during execution of command
    RMAN-10039: error encountered while polling for RPC completion on channel clone_default
    RMAN-10006: error running SQL statement: select action from gv$session where sid=:1 and serial#=:2 and inst_id=:3
    RMAN-10002: ORACLE error: ORA-03114: not connected to ORACLE
    RMAN-10041: Could not re-create polling channel context following failure.
    RMAN-10024: error setting up for rpc polling
    RMAN-10005: error opening cursor
    RMAN-10002: ORACLE error: ORA-03114: not connected to ORACLE
    RMAN-03002: failure of Duplicate Db command at 05/21/2010 15:32:29
    RMAN-03015: error occurred in stored script Memory Script
    RMAN-06136: ORACLE error from auxiliary database: ORA-01092: ORACLE instance terminated. Disconnection forced
    ORA-00704: bootstrap process failure
    ORA-39700: database must be opened with UPGRADE option
    oracle:tuldcorpadb01:dcxt$
    Edited by: DBA2008 on May 21, 2010 3:37 PM

    never mind, i resolved this by switching duplicate db to 10203....and adjusting log_arch_dest .....

  • BPM: write to DB, BPM error, rollback of stored data in database possible??

    hello together,
    i will have following problem:
    i will send information from outside through XI over BPM and RFC to a SAP r/3 system. if the bpm process has an error after the storing information into the database all changes in the database have to be make undo. but how can i do this? how can i handle a rollback in the database regarding to BPM?
    thanks a lot
    alex

    Hi Sravya,
    it is not a specified error. i just want to know how to handle an error or exception if data are stored in a database (rollback and so on).
    the next question i have: when a bpm will be stopped by an exception handling or an error and i have the possibility to restart it (haven't i??) at which point of the bpm the restart will begin? at the point of error or at the start point of the bpm??
    thanks a lot
    alex

  • 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]

  • 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

  • Missing Defines Error in Simple Java Stored Procedure

    Anyone have any suggestions on what might be causing the unusual behavior described below? Could it be a 10g java configuration issue? I am really stuck so I'm open to just about anything. Thanks in advance.
    I am writing a java stored procedure and am getting some SQLException's when executing some basic JDBC code from within the database. I reproduced the problem by writing a very simple java stored procedure which I have included below. The code executes just fine when executed outside of the database (10g). Here is the output from that execution:
    java.class.path=C:\Program Files\jEdit42\jedit.jar
    java.class.version=48.0
    java.home=C:\j2sdk1.4.2_04\jre
    java.vendor=Sun Microsystems Inc.
    java.version=1.4.2_04
    os.arch=x86
    os.name=Windows XP
    os.version=5.1
    In getConnection
    Executing outside of the DB
    Driver Name = Oracle JDBC driver
    Driver Version = 10.1.0.2.0
    column count=1
    column name=TEST
    column type=1
    TEST
    When I execute it on the database by calling the stored procedure I get:
    java.class.path=
    java.class.version=46.0
    java.home=/space/oracle/javavm/
    java.vendor=Oracle Corporation
    java.version=1.4.1
    os.arch=sparc
    os.name=Solaris
    os.version=5.8
    In getConnection
    We are executing inside the database
    Driver Name = Oracle JDBC driver
    Driver Version = 10.1.0.2.0
    column count=1
    column name='TEST'
    column type=1
    MEssage: Missing defines
    Error Code: 17021
    SQL State: null
    java.sql.SQLException: Missing defines
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
    at oracle.jdbc.driver.OracleResultSetImpl.getString(Native Method)
    at OracleJSPTest.test(OracleJSPTest:70)
    Here is the Java code:
    // JDBC classes
    import java.sql.*;
    import java.util.*;
    //Oracle Extensions to JDBC
    import oracle.jdbc.*;
    import oracle.jdbc.driver.OracleDriver;
    public class OracleJSPTest {
    private static void printProperties(){
         System.out.println("java.class.path="+System.getProperty("java.class.path"));
         System.out.println("java.class.version="+System.getProperty("java.class.version"));
         System.out.println("java.home="+System.getProperty("java.home"));
         System.out.println("java.vendor="+System.getProperty("java.vendor"));
         System.out.println("java.version="+System.getProperty("java.version"));
         System.out.println("os.arch="+System.getProperty("os.arch"));
         System.out.println("os.name="+System.getProperty("os.name"));
         System.out.println("os.version="+System.getProperty("os.version"));
    private static Connection getConnection() throws SQLException {
         System.out.println("In getConnection");      
    Connection connection = null;
    // Get a Default Database Connection using Server Side JDBC Driver.
    // Note : This class will be loaded on the Database Server and hence use a
    // Server Side JDBC Driver to get default Connection to Database
    if(System.getProperty("oracle.jserver.version") != null){
              System.out.println("We are executing inside the database");
              //connection = DriverManager.getConnection("jdbc:default:connection:");                    
              connection = new OracleDriver().defaultConnection();
    }else{
         System.out.println("Executing outside of the DB");
         DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
         connection = DriverManager.getConnection("jdbc:oracle:thin:@XXX.XXX.XXX.XX:XXXX:XXXX","username","password");
    DatabaseMetaData dbmeta = connection.getMetaData();
    System.out.println("Driver Name = "+ dbmeta.getDriverName());
    System.out.println("Driver Version = "+ dbmeta.getDriverVersion());
    return connection;
    public static void main(String args[]){     
         test();     
    public static void test() {   
         printProperties();
    Connection connection = null; // Database connection object
    try {
         connection = getConnection();
         String sql = "select 'TEST' from dual";
         Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);     
         ResultSetMetaData meta = rs.getMetaData();     
         System.out.println("column count="+meta.getColumnCount());
         System.out.println("column name="+meta.getColumnName(1));
         System.out.println("column type="+meta.getColumnType(1));
         if(rs.next()){
              System.out.println(rs.getString(1));
    } catch (SQLException ex) { // Trap SQL Errors
         System.out.println("MEssage: " + ex.getMessage());
         System.out.println("Error Code: " + ex.getErrorCode());
         System.out.println("SQL State: " + ex.getSQLState());
         ex.printStackTrace();
    } finally {
    try{
    if (connection != null || !connection.isClosed())
    connection.close(); // Close the database connection
    } catch(SQLException ex){
    ex.printStackTrace();
    Message was edited by:
    jason_mac

    Jason,
    Works for me on Oracle 10.1.0.3 running on Red Hat Enterprise Linux AS release 3 (Taroon).
    Java code:
    import java.sql.*;
    * Oracle Java Virtual Machine (OJVM) test class.
    public class OjvmTest {
      public static void test() throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:default:connection:");
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
          ps = conn.prepareStatement("select 'TEST' from SYS.DUAL");
          rs = ps.executeQuery();
          if (rs.next()) {
            System.out.println(rs.getString(1));
        finally {
          if (rs != null) {
            try {
              rs.close();
            catch (SQLException sqlEx) {
              System.err.println("Error ignored. Failed to close result set.");
          if (ps != null) {
            try {
              ps.close();
            catch (SQLException sqlEx) {
              System.err.println("Error ignored. Failed to close statement.");
    }And my PL/SQL wrapper:
    create or replace procedure P_J_TEST as language java
    name 'OjvmTest.test()';And here is how I execute it in a SQL*Plus session:
    set serveroutput on
    exec dbms_java.set_output(2000)
    exec p_j_testGood Luck,
    Avi.

  • 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??

  • SSRS dataset throws error when another stored procedure is called inside dataset stored procedure

    Hello;
    I am using Report Build 3.0, I have a simple report which gets data using dataset which is created from a Stored Procedure. I have another stored procedure which updates the data in the table which is used for the report. I want to get the live data on report everytime
    the report is run so that I call that stored procedure (sp_updatedata) inside my report dataset stored procedure and here where my report fails as it throws error while creating dataset.
    Here is sample:
    sp_updatedata (this only returns "Command(s) completed successfully"
    Create Proce sp_getReportData
    As
    Begin
    Exec sp_updatedata -- I call it to update the data before it displays on the report
    Select * from customers
    End
    If I remove this line it works.
    Exec sp_updatedata -- I call it to update the data before it displays on the report
    Thanks
    Essa Mughal

    Hi MESSA,
    According to your description, you create a dataset based on a stored procedure. In this procedure, it calls another procedure. Now it throws error when creating dataset. Right?
    In Reporting Services, when creating dataset, all the query or stored procedure will be executed in SSMS. So if the procedure can be executed in SSMS, it supposed to be working in SSRS. However, it has a limitation in SSRS. In a dataset, it can only return
    one result set.
    In this scenario, I don't think it's the issue of calling other procedure inside of procedure. Because we tested in our local environment, it works fine. I guess the sp_updatedata returns a result set, and the "select * from customers" returns
    another result set. This might be the reason cause the error.
    Reference:
    Query Design Tools in Report Designer SQL Server Data Tools (SSRS)
    Reporting Services Query Designers
    If you still have any question, please post the error message and the store procedure (sp_updatedata).
    Best Regards,
    Simon Hou

  • Error calling a stored procedure from C#

    Please help me!
    I'm new in .net technology.
    I have an Oracle 9i server and an application in .net C# language.
    I'm trying to call a stored procedure written in plsql.
    This is the testing procedure:
    CREATE OR REPLACE PROCEDURE TEST_PROC
    par_1 in number
    as
    begin
    insert into tbltestinput (number_col) values (par_1);
    commit;
    end;
    And the calling code is:
    OracleCommand objCmd = new OracleCommand("TEST_PROC",conn);
    objCmd.CommandType = CommandType.StoredProcedure;
    OracleParameter inPar_1 = new OracleParameter();
    inPar_1.OracleType = OracleType.Number;
    inPar_1.Direction = ParameterDirection.Input;
    inPar_1.Value = 123456;
    objCmd.Parameters.Add(inPar_1);
    objCmd.ExecuteNonQuery();
    It returns this error:
    Exception Message: ORA-06550: row 1, column 7: PLS-00306: wrong number or types of arguments in call to 'TEST_PROC' ORA-06550: row 1, column 7: PL/SQL: Statement ignored
    Exception Source: System.Data.OracleClient
    The stored procedure is very very simple to test only the call.
    Anybody can help me.
    Thanks !!!!

    Hello,
    System.Data.OracleClient == Microsoft provider for Oracle (whereas this is the Oracle Data Provider for .NET forum).
    However, the MS provider operates in Bind By Name mode, so you might try adding this to your code:
    inPar_1.ParameterName = "par_1";Perhaps that will help a bit,
    Mark

  • 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

Maybe you are looking for

  • Credit block in third party

    Hi, while creating third party sales order because of credit it is blocking when i remove the block in VKM3 again back to sales order here purchase org. is missing it is required field. If i give a purchase org. here and if  i try to save again but o

  • How to determine the Xcelsius Theme and Colour scheme used in a dashboard

    I would like to know what colour scheme and xcelsius Theme has been used in creating a given dashboard.  Kindly share this information Thanks

  • INTEGRATION_DIRECTORY_HMI: Connection fails

    Parameters are the same like in Installation guide except Client. This parameter is empty. SICF -> default_host -> sap -> xi -> cache shows client parameter empty too.     <b>XIISUSER is in roles:</b>      SAP_SLD_CONFIGURATOR      SAP_XI_IS_SERV_USE

  • CSV Data Output

    Hi, I would like to know how I can automate the output of data collected in CSV format? Manual intervention i.e. output and subsequent Server upload is not efficient. I would like to have the data output, such as a CSV file, as an email attachment wh

  • I have some problems with element Panel Label and Message.

    I have some problems with element Panel Label and Message. When I create form from VO attributes then I have Label for input text element. If I use Panel Label and Message element then I need to copy LABEL from input text element to Panel Label and M