Error after creating a stored procedure

hi,
i m planning to create the below stored procedure and created but i m unable to execute this procedure,
please provide me the solution.
SQL> create or replace procedure test is
2 titl varchar(20);
3 typ varchar(20);
4 pric number(10);
5 nprice number(10);
6 begin
7 SELECT
8 title_id,
9 type,
10 price,
11 CASE type
12 WHEN 'history'
13 THEN price + 110
14 WHEN 'psychology'
15 THEN price + 120
16 WHEN 'computer'
17 THEN price + 140
18 ELSE price
19 END
20 AS "New price" into titl,typ,pric,nprice
21 FROM book
22 ORDER BY type ASC, title_id ASC;
23 dbms_output.put_line(titl || typ || pric || nprice);
24 end;
25 /
Procedure created.
SQL> set serverout on
SQL> exec test
BEGIN test; END;
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYS.TEST", line 8
ORA-06512: at line 1
SQL> show error
No errors.
thanks...

Hi,
Check you SQL query, Its returning mutiple rows which you are storing in variables.
If your data returns mutiple row then use cursor to iterate through it.
like
create or replace procedure test is
titl varchar(20);
typ varchar(20);
pric number(10);
nprice number(10);
cursor c is
SELECT title_id, type, price, CASE type WHEN 'history' THEN price + 110
                                                       WHEN 'psychology' THEN price + 120
                                                       WHEN 'computer'   THEN price + 140
                                                       ELSE price END AS "New price"
FROM book
ORDER BY type ASC, title_id ASC;
begin
for r in c loop
dbms_output.put_line(r.titl || r.typ || r.pric || r.nprice);
end;Twinkle

Similar Messages

  • How to create a stored procedure that contains all 3 AFTER Triggers Update/Insert/Delete ?

    Hi guys, I'm trying to create a Stored procedure that will automatically add all 3 After triggers when executed on any given database, can someone please explain and give an example on how do I go about doing this ? I'd also like it to raise any errors
    that may come across, thanks in advance.

    Lets start with the question why do you need the triggers at all. Since SQL Server 2005 we can use an OUTPUT clause.
    This code can be re-written in SQL Server 2005 using the OUTPUT clause like below:
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    go
    Now from this example, you can see the integration of OUTPUT clause with existing DML syntax.
    Another common scenario is auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. The example below shows code that uses OUTPUT clause in UPDATE and DELETE
    statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • ERP2005 SR3 Create SAP Stored Procedures Error

    Hi Seniors,
    I have tried to install SAP ERP ECC 6.0 IDES ERP2005 SR3 , I got the error in installation step 19/26 (Create SAP Stored Procedures).
    OS : WIN 2008 SERVER
    DB : MS SQL 2008
    I have fallow the Note 1152240.
    Error log :
    ERROR 2010-03-02 12:08:20.282
    FCO-00011  The step ExeProcs with step key |NW_Onehost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|2|0|NW_CreateDBandLoad|ind|ind|ind|ind|10|0|NW_Postload|ind|ind|ind|ind|10|0|NW_Postload_MSS|ind|ind|ind|ind|2|0|MssProcs|ind|ind|ind|ind|1|0|ExeProcs was executed with status ERROR .
    Please help me, 
    Thank you,
    Sagar K

    > I have tried to install SAP ERP ECC 6.0 IDES ERP2005 SR3 , I got the error in installation step 19/26 (Create SAP Stored Procedures).
    >
    > OS : WIN 2008 SERVER
    > DB : MS SQL 2008
    See note 1244548 - IDES ERP 6.0 ECC 6.0 SR3:
    <...>
    Microsoft SQL Server 2008:
    An Installation of this IDES version on MSSQL 2008 is NOT possible.
    Please use MSSQL 2005 as database version
    <...>
    The reason is that the SAP_BASIS support package is too low.
    Markus

  • Problems in creating RLANG stored procedure in HANA studio

    Hi,
    While I am creating a stored procedure (using .hdbprocedure file) in HANA studio with language as RLANG, I am getting an error message like this: "It is not supported to use another language than sqlscript".
    I have the following setting configured.
    HANA System -> Administration -> Configuration ->indexserver.ini -> repository -> sqlscript_mode = UNSECURE
    Any clues will be appreciated.
    Best Regards
    Surya

    HI Raj,
    This happens even for the empty procedure as following
    PROCEDURE "IDMANALYTICS_OPER"."idmanalytics.hana.db.hdbprocedures::MC_ROLEMINING_CLUSTERING_R" ( )
      LANGUAGE RLANG
      SQL SECURITY INVOKER
      READS SQL DATA AS
    BEGIN
      Write your procedure logic
    END;
    The procedure that I wanted to write is following.
    PROCEDURE MC_ROLEMINING_CLUSTERING_R(IN rolemining_input "_SYS_BIC"."idmanalytics.hana.db.views/MC_ROLEMINING_VINPUT",
      IN params "IDMANALYTICS_DB"."idmanalytics.hana.db.hdbtables::MC_ROLEMINING_PARAMETER",
      OUT result MC_ROLEMINING_CLUSTERS_TYPE,
      OUT result_hierarchy MC_ROLEMINING_HIERARCHY_TYPE,
      OUT result_userorder MC_ROLEMINING_USERORDER_TYPE
    LANGUAGE RLANG AS
    BEGIN
      noofclusters <- params$INT_VALUE[1];
      simindex <- params$DOUBLE_VALUE[2];
      distancemethod="jaccard"
      clusteringmethod="complete"
      usercol <- rolemining_input$USER_ID
      privcol <- rolemining_input$PRIV_ID
      #--generate user-permission matrix from user-permission table
      uptable <- data.frame(users = usercol, privileges = privcol)
      uniqueusers <- sort(unique(uptable$users))
      uniqueprivileges <- sort(unique(uptable$privileges))
      upmatrixdata <- vector()
      index <- 0
      for(i in uniqueusers )
      for(j in uniqueprivileges) {
      row_to_find <- data.frame(users=i, privileges = j)
      if(duplicated(rbind(uptable, row_to_find))[nrow(uptable)+1]){
      upmatrixdata <- append(upmatrixdata, 1, after = index)
      else {
      upmatrixdata <- append(upmatrixdata, 0, after = index)
      index <- index +1
      upmatrix <- matrix(
      upmatrixdata ,
      nrow = length(uniqueusers),
      ncol = length(uniqueprivileges),
      byrow = TRUE,
              dimnames = list(
              uniqueusers,
                  uniqueprivileges
      #--apply hierarchical clustersing
      require(vegan)
      distance<-vegdist(upmatrix,method=distancemethod)
      clusters<-hclust(distance,method=clusteringmethod)
      #--fill clusters for given h and k
      if(noofclusters > 0){
      userclusters<-cutree(clusters,k=noofclusters)
      tempresult <- as.data.frame(userclusters)
      result <- data.frame(USER_ID=row.names(tempresult), CLUSTER_ID=tempresult$userclusters)
      if(noofclusters <= 0 & simindex >= 0){
      userclusters<-cutree(clusters,h=simindex)
      tempresult <- as.data.frame(userclusters)
      result <- data.frame(USER_ID=row.names(tempresult), CLUSTER_ID=tempresult$userclusters)
      #--fill role hierarchy
      clusters_merge <- as.data.frame(clusters$merge)
      clusters_height <- clusters$height
      clusters_order <- clusters$order
      result_hierarchy <- data.frame(HEIGHT=clusters_height, V1=clusters_merge$V1, V2=clusters_merge$V2)
      #--fill user order
      clusters_order <- clusters$order
      result_userorder <- data.frame(USERORDER=clusters_order)
    END;

  • Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.

    I am using VS 2012 and BizTalk 2013 and attempting to deploy an application to BizTalk when I get these errors:
    Error 47
    at Microsoft.BizTalk.Deployment.Assembly.BtsMap.Save()
       at Microsoft.BizTalk.Deployment.Assembly.BtsArtifactCollection.Save()
       at Microsoft.BizTalk.Deployment.Assembly.BtsAssembly.Save(String applicationName)
       at Microsoft.BizTalk.Deployment.BizTalkAssembly.PrivateDeploy(String server, String database, String assemblyPathname, String applicationName)
       at Microsoft.BizTalk.Deployment.BizTalkAssembly.Deploy(Boolean redeploy, String server, String database, String assemblyPathname, String group, String applicationName, ApplicationLog log)
    0 0
    Error 49
    Failed to add resource(s). Change requests failed for some resources. BizTalkAssemblyResourceManager failed to complete end type change request. Failed to deploy map "XXX.BTS2013.XXX.Maps.map_XXXX_R01_InsLabProc".
    Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present. Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.
    0 0
    Error 46
    Failed to deploy map "XXX.BTS2013.XXX.Maps.map_XXXX_R01_InsLabProc".
    Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.
    0 0
    I also tried to Import a MSI file from our test environment to see if that would work...got the same errors.  After spending hours (not kidding) looking for an answer, all I could find is that a hotfix would work.  So, I got the hotfix from Microsoft
    Support and applied it then rebooted.  Still getting the same errors.  I'm absolutely at a stand still.  Interesting that I got this application to deploy yesterday and then the next time I deployed it I started getting these errors.  I'm
    ready to pull my hair out!
    Is there an answer for this out there somewhere?  Any help would be appreciated.
    Thanks,
    Dave

    Hi Dave,
    Which hotfix have you applied? I don't think a hotfix of this issue is available for BizTalk 2013 yet. You should create a
    support ticket with Microsoft to get a solution.
    If this answers your question please mark as answer. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Pointbase : How can I create a stored procedure with Pointbase database?

    Hello,
    Excuse me for my english, I'm not anglophone. I try to create a stored procedure.
    This is my file SampleExternalMethods.java :
      import java.sql.*;    //import com.pointbase.jdbc.jdbcInOutDoubleWrapper;          public class SampleExternalMethods    {      // A connection object to allow database callback      static Connection conn = null;      static Statement l_stmt;      static Statement m_stmt;      static CallableStatement m_callStmt = null;      static ResultSet l_rs = null;          public static void main(String[] args)      {        try        {          String url = "jdbc:pointbase:server://localhost/pointbaseDB";          String username = "PBPUBLIC";          String password = "PBPUBLIC";          conn = DriverManager.getConnection(url, username, password);          doCreateProcedure();          doInvokeProcedure();        } catch (SQLException e) {          e.printStackTrace();        } finally {          if (m_stmt != null) {            try {              m_stmt.close();            } catch (Exception e) {              e.printStackTrace();            }          }          if (m_callStmt != null) {            try {              m_callStmt.close();            } catch (Exception e) {              e.printStackTrace();            }          }          if (conn != null) {            try {              conn.close();            } catch (Exception e) {              e.printStackTrace();            }          }        }      }                  public static void getCountry(String Iso_Code)      {        try        {          // Query the database for the country iso code          l_stmt = conn.createStatement();          l_rs = l_stmt.executeQuery( "SELECT * FROM countries"          + " WHERE country_iso_code ='" + Iso_Code + "'");          //Affichage du résultat de la requête          l_rs.next();          System.out.print(l_rs.getString(1) + " - ");          System.out.print(l_rs.getString(2) + " - ");          System.out.println(l_rs.getString(3));          // Close the result set          l_rs.close();        } catch (SQLException e) {          e.printStackTrace();        } finally {          if (l_rs != null) {            try {              l_rs.close();            } catch (Exception e) {              e.printStackTrace();            }          }          if (l_stmt != null) {            try {              l_stmt.close();            } catch (Exception e) {              e.printStackTrace();            }          }        }      }            public static void doCreateProcedure() throws SQLException {        // SQL statement to create a stored procedure        String SQL_CREATE_PROC = "CREATE PROCEDURE getCountry(IN P1 VARCHAR(30))"        + " LANGUAGE JAVA"        + " SPECIFIC getCountry"        + " NO SQL"        + " EXTERNAL NAME \"SampleExternalMethods::getCountry\""        + " PARAMETER STYLE SQL";        // Create a SQL statement        m_stmt = conn.createStatement();        // Execute the SQL        m_stmt.executeUpdate(SQL_CREATE_PROC);        // Close the statement        //m_stmt.close();      }          public static void doInvokeProcedure() throws SQLException {        // Create SQL to invoke stored procedures        String SQL_USE_PROC = "{ call getCountry(?) }";        // Create a callable statement with three binding parameters        m_callStmt = conn.prepareCall(SQL_USE_PROC);        m_callStmt.setString(1, "CA");        m_callStmt.executeQuery();        // Close the callable statement        //m_callStmt.close();      }    } 
    Afterwards, I have read this note in a Pointbase document:
    To invoke the dateConvert external Java method from a stored function, you must use the
    CREATE FUNCTION statement. The dateConvert external Java method is called from the
    class, SampleExternalMethods.
    In order for the database to access this external Java method, the class SampleExternalMethods
    must be included in the database CLASSPATH. For PointBase Embedded - Server Option, it
    must be in the Server CLASSPATH, but not in the Client CLASSPATH.
    If PointBase Server is run with the Java Security Manager, in the java policy file grant
    ’com.pointbase.sp.spPermission’ to the class that implements the external Java method.
    An "spPermission" consists of a class name with no action. The class name is a name of a class
    that could be used in creating a Stored Procedure in PointBase. The naming convention follows
    the hierarchical property naming convention and that is supported by
    "java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded
    by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
    contain any white spaces.
    I'm not sure, but I suppose that I must include the class SampleExternalMethods in a .jar file.
    The database CLASSPATH could be : C:\Sun\AppServer\pointbase\lib\
    These my files in this database CLASSPATH:
    pbclient.jar
    pbembedded.jar
    pbtools.jar
    pbupgrade.jar
    I have tryed to include the class SampleExternalMethods in pbclient.jar and pbembedded.jar with this command:
    jar -uf pbembedded.jar SampleExternalMethods
    Afterwards I do that,
    1) Start Pointbase
    2) Configuration of classpath
    set classpath=C:\Sun\AppServer\pointbase\lib\pbclient.jar
    set classpath=%classpath%;D:\J2EE\Ch07Code\Ch07_06
    I precise that my file SampleExternalMethods is into D:\J2EE\Ch07Code\Ch07_06\Ch07.
    Then, I run the program:
    D:\J2EE\Ch07Code\Ch07_06>java -Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver Ch07.SampleExternalMethods
    But I have an error message:
    Exception in thread "main" java.lang.NoClassDefFoundError: Ch07.SampleExternalMethods (wrong name: SampleExternalMethods)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.DefineClass(ClassLoader.java:539)
    The problem, I suppose, comes from that the class SampleExternalMethods
    must be included in the database CLASSPATH, but there is a pbserver.jar with pointbase normally, but I didn't find it. That's why I use pbembedded.jar or pbclient.jar in order to include the class SampleExternalMethods. May be I must start from C:\Sun\AppServer\pointbase\lib\ instead of D:\J2EE\Ch07Code\Ch07_06\Ch07?
    Please, can somebody helps me?
    Thank you in advance.
    cagou!

    jschell wrote:
    And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
    >And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
    >
    And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
    Thank you for your response, I have done two classes:
    SampleExternalMethods.java:
    package Ch07;
    import java.sql.*;*
    *public class SampleExternalMethods*
    *public static void getCountry(String Iso_Code)*
    *// A connection object to allow database callback*
    *Connection l_conn = null;*
    *Statement l_stmt = null;*
    *ResultSet l_rs = null;*
    *try*
    *String url = "jdbc:pointbase:server://localhost/pointbaseDB";*
    *String username = "PBPUBLIC";*
    *String password = "PBPUBLIC";*
    *l_conn = DriverManager.getConnection(url, username, password);*
    *// Query the database for the country iso code*
    *l_stmt = l_conn.createStatement();*
    *l_rs = l_stmt.executeQuery( "SELECT* FROM PBPUBLIC.COUNTRIES"
    +" WHERE country_iso_code ='"+ Iso_Code +"'");+
    +//Affichage du r&eacute;sultat de la requ&ecirc;te+
    +l_rs.next();+
    +System.out.print(l_rs.getString(1)+ " - ");
    System.out.print(l_rs.getString(2) +" - ");+
    +System.out.println(l_rs.getString(3));+
    +// Close the result set+
    +l_rs.close();+
    +} catch (SQLException e) {+
    +e.printStackTrace();+
    +} finally {+
    +if (l_rs != null) {+
    +try {+
    +l_rs.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +if (l_stmt != null) {+
    +try {+
    +l_stmt.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +if (l_conn != null) {+
    +try {+
    +l_conn.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +}+
    +}+
    +}+
    CreateMethods.java:
    +package Ch07;+
    +import java.sql.*;+
    +public class CreateMethods+
    +{+
    +// A connection object to allow database callback+
    +static Connection m_conn = null;+
    +static Statement m_stmt;+
    +static CallableStatement m_callStmt = null;+
    +public static void main(String[] args)+
    +{+
    +try+
    +{+
    +String url = "jdbc:pointbase:server://localhost/pointbaseDB";+
    +String username = "PBPUBLIC";+
    +String password = "PBPUBLIC";+
    +m_conn = DriverManager.getConnection(url, username, password);+
    +doCreateProcedure();+
    +doInvokeProcedure();+
    +} catch (SQLException e) {+
    +e.printStackTrace();+
    +} finally {+
    +if (m_stmt != null) {+
    +try {+
    +m_stmt.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +if (m_callStmt != null) {+
    +try {+
    +m_callStmt.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +if (m_conn != null) {+
    +try {+
    +m_conn.close();+
    +} catch (Exception e) {+
    +e.printStackTrace();+
    +}+
    +}+
    +}+
    +}+
    +public static void doCreateProcedure() throws SQLException {+
    +// SQL statement to create a stored procedure+
    +String SQL_CREATE_PROC = "CREATE PROCEDURE PBPUBLIC.getCountry(IN P1 VARCHAR(30))"+
    " LANGUAGE JAVA"
    +" SPECIFIC getCountry"+
    " NO SQL"
    +" EXTERNAL NAME \"SampleExternalMethods::getCountry\""+
    " PARAMETER STYLE SQL";
    // Create a SQL statement
    m_stmt = m_conn.createStatement();
    // Execute the SQL
    m_stmt.executeUpdate(SQL_CREATE_PROC);
    // Close the statement
    //m_stmt.close();
    public static void doInvokeProcedure() throws SQLException {
    // Create SQL to invoke stored procedures
    String SQL_USE_PROC = "{ call getCountry(?) }";
    // Create a callable statement with three binding parameters
    m_callStmt = m_conn.prepareCall(SQL_USE_PROC);
    m_callStmt.setString(2, "CA");
    m_callStmt.executeQuery();
    // Close the callable statement
    //m_callStmt.close();
    }But I have the same error message that previously.
    I have read this note and I suppose that the problem is linked:
    If PointBase Server is run with the Java Security Manager, in the java policy file grant
    *’com.pointbase.sp.spPermission’ to the class that implements the external Java method.*
    An "spPermission" consists of a class name with no action. The class name is a name of a class
    that could be used in creating a Stored Procedure in PointBase. The naming convention follows
    the hierarchical property naming convention and that is supported by
    *"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded*
    by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
    contain any white spaces.
    Can you explain me what I must to do in order to solve this problem of spPermission.
    Thanks.

  • Can I create a Stored Procedure That access data from tables of another servers?

    I'm developing a procedure and within it I'm trying to access another server and make a select into a table that belongs to this another server. When I compile this procedure I have this error message: " PLS-00904: insufficient privilege to access object BC.CADPAP", where BC.CADPAP is the problematic table.
    How can I use more than one connection into an Oracle Stored Procedure?
    How I can access tables of a server from a Stored Procedure since the moment I'm already connected with another server?
    Can I create a Stored Procedure That access data from tables of another servers?

    You need to have a Database Link between two servers. Then you could do execute that statement without any problem. Try to create a database link with the help of
    CREATE DATABASE LINK command. Refer Document for further details

  • Syntax of creating a stored procedure in Ms Access

    I need to create a stored procedure in Ms Access and i need to create it via a java program .This is the query i have written
    CREATE PROCEDURE procProductsList As
    Select A.Id,B.L_Name from Transaction A,Member B where A.Id = B.Id and A.Id = [@emp] and A.Name = [@name].But when i try to run it i get an error as Syntax error in CREATE TABLE statement.Plz could sumone help.

    //Creates a stored procedure as a resultset
    boolean createStoredProcedure(String strSql,Connection connect)
    Statement stmt=null;     
         int columnCount=0;
         try
              if(connect.isClosed()==true)
                   return false;
                   else
                   stmt=connect.createStatement();
                   stmt.executeUpdate(strSql);                                             
              } //End else
         } //End try
         catch(SQLException sql)
              System.out.print("Sql Exception caught");
              sql.printStackTrace();
              return false;
         } //End catch
         return true;
         } //End function
    //Function for passing the number of parameters in the parameters list
    String getInvokeParamsList(Vector vector)
         String strParamsInvokeList = new String("");
         if(vector==null)
    strParamsInvokeList=null;
         else
              strParamsInvokeList += "(";
              for(int i=0; i < vector.size(); i++)
                   strParamsInvokeList += "?";
                   if(i < (vector.size() - 1))
                        strParamsInvokeList += ", ";
              strParamsInvokeList += ")";
         return strParamsInvokeList;
    //Calls a stored Procedure
    ResultSet callStoredProcedure(Connection connect,String strProcedureName,Vector vecValues)
         ResultSet rs=null;
         try
                   CallableStatement cs = connect.prepareCall("{call " + strProcedureName + getInvokeParamsList(vecValues) + "}");
                   for(int i=0;i<vecValues.size();i++)
                   cs.setString(i+1,(String)vecValues.get(i));
                   rs = cs.executeQuery();
    catch(SQLException sql)
              System.out.print("Sql Exception caught: " + sql.toString());
              sql.printStackTrace();
    catch(NullPointerException npexp)
              System.out.print("NullPointerException Exception caught: " + npexp.toString());
              npexp.printStackTrace();
         return rs;//End catch
    class database1
              public static void main(String[] args)
                   try
                        String strFilepath="C:\\trainee";
                        String strFilename="config.xml";
                        String strvendor="TICPEN0001003";
                        String str1="CREATE PROCEDURE procProductsList As Select A.Id,B.L_Name from Transaction A,Member B where A.Id = B.Id and A.Id = [@emp] and A.Name = [@name]";
                        String proc="stproc";
                        int columnCount=0;
                        clsDatabase clsdb=new clsDatabase(strFilepath,strFilename,strvendor);
                        Connection boolConn=clsdb.getConnect();
                        Vector vec=new Vector();
                        if(boolConn!=null)
                             System.out.println("Connection established");     
                             vec.add("3");
                        vec.add("Glove");
                             boolean b1=clsdb.createStoredProcedure(str1,boolConn);
                             if(b1==true)
                                  ResultSet rs1=clsdb.callStoredProcedure(boolConn, proc, vec);
                                       if(rs1==null)
                                       System.out.println("rs1 null");
                                  else
                                       ResultSetMetaData rsmd = rs1.getMetaData();                         
                                       columnCount = rsmd.getColumnCount();
                                       while(rs1.next())
                                            for(int i=1 ;i<=columnCount; i++)
                                                 String value=rs1.getString(i);
                                                 System.out.println(value);
                             else
                             System.out.print("Stored Procedure not created");
                   else
                        System.out.println("Connection not established");      
    catch(Exception e)
                        //System.out.println("Exception caught4: " + e.toString());
                        e.printStackTrace();
                   }                                                                                          //End catch
         }                                                                                          //End main
    }

  • Beginner - trying to create a stored procedure.

    I want to create a stored procedure, where the person calling the procedure only has to up date the date_key :
    The procedure is just creating a table and will be ran every couple days.
    Create or replace procedure WklyHVCReport (date_transaction number)
    Is
    Begin
    EXECUTE_IMMEDIATE
    create table reporting_dept.HVC_Weekly
    as
    select a.msisdn, sum(d.amt_gross * -1.0) as Amt
    from clarity_mis.dim_subscriber_vw a
    join clarity_mis.dim_customer_account_vw b on a.customer_account_id = b.customer_account_id
    join clarity_mis.fact_balance_transaction_vw c on a.subscriber_key = c.subscriber_key
    join clarity_mis.dim_transaction_vw d on c.transaction_key = d.transaction_key
    where a.flag_is_last_msisdn_owner = 'Y'
    and a.sub_base_group = 'ACTIVE'
    and (b.data_protection != 'No Contact Preferred' or b.data_protection is null)
    and c.date_transaction_key >= || date_transaction ||
    and d.transaction_sub_cat = 'Purchased Credit'
    group by a.msisdn having sum(d.amt_gross * -1.0) >= 80
    end;
    I keep getting this error,
    Error(6,1): PLS-00103: Encountered the symbol "?" when expecting one of the following: := . ( @ % ;
    - can you point me in the right direction ?

    Hello
    Sorry to jump in but I think it would be worth you having a look at packages. Packages allow you to group together stored procedures and functions that have a common purpose - similar idea to libraries, DLL etc.
    In your example, if you have several different reports for HVC (I'm making a big guess that HVC has some sort of relevance to the business or a peice of software), you could have a sinlge package that contains all of them. They are then logically grouped and you can potentially share logic between them.
    A package is formed of a specification and a body. In the specification you are defining procedures that are "publicly" callable and in the body you are writing the implementation of those procedures.
    You can also specify procedures that can only be called within the package body and are not visible outside. So for example if you wanted to log how often each report is run and by whom, you could have a procedure only declared in the body that will record those details in a separate table.
    CREATE TABLE hvc_report_log
    (   report_name     VARCHAR2(100) NOT NULL,
        username        VARCHAR2(30) NOT NULL,
        used_date       DATE NOT NULL
    --This is the specification
    CREATE OR REPLACE PACKAGE hvcreports
    AS
        PROCEDURE p_Weekly (date_transaction number);
        PROCEDURE p_Monthly (date_transaction number);
    END;
    --This is the implementation in the body.
    CREATE OR REPLACE PACKAGE BODY hvcreports
    AS
        --This procedure can only be called from within the package body
        PROCEDURE p_LogUsage( p_report_name    hvc_report_log.report_name%TYPE)
        IS
        BEGIN
            INSERT
            INTO
                hvc_report_log
                (   report_name,
                    username,
                    used_date
            VALUES
                (   p_report_name,
                    USER,       --Built in function that returns
                                --the currently logged in oracle user
                    SYSDATE     --Returns the current date and time
        END;
        PROCEDURE p_Weekly (date_transaction number)
        IS
         begin
          p_LogUsage('hvc_weekly');
           insert into hvc_weekly (msisdn, amt)
             select   a.msisdn,
                   sum (d.amt_gross * -1.0) as amt
             from    clarity_mis.dim_subscriber_vw a
                  join clarity_mis.dim_customer_account_vw b
                    on a.customer_account_id = b.customer_account_id
                  join clarity_mis.fact_balance_transaction_vw c
                    on a.subscriber_key = c.subscriber_key
                  join clarity_mis.dim_transaction_vw d
                    on c.transaction_key = d.transaction_key
             where        a.flag_is_last_msisdn_owner = 'Y'
                   and a.sub_base_group = 'ACTIVE'
                   and (b.data_protection != 'No Contact Preferred'
                     or b.data_protection is null)
                   and c.date_transaction_key >= date_transaction
                   and d.transaction_sub_cat = 'Purchased Credit'
             group by a.msisdn
             having   sum (d.amt_gross * -1.0) >= 80;
         end ;   
        PROCEDURE p_Monthly (date_transaction number)
        IS
        begin
          p_LogUsage('hvc_monthly');   
          insert into hvc_monthly (msisdn, amt)
            select   a.msisdn,
                 sum (d.amt_gross * -1.0) as amt
            from    clarity_mis.dim_subscriber_vw a
                join clarity_mis.dim_customer_account_vw b
                  on a.customer_account_id = b.customer_account_id
                join clarity_mis.fact_balance_transaction_vw c
                  on a.subscriber_key = c.subscriber_key
                join clarity_mis.dim_transaction_vw d
                  on c.transaction_key = d.transaction_key
            where        a.flag_is_last_msisdn_owner = 'Y'
                 and a.sub_base_group = 'ACTIVE'
                 and (b.data_protection != 'No Contact Preferred'
                  or b.data_protection is null)
                 and c.date_transaction_key >= date_transaction
                 and d.transaction_sub_cat = 'Purchased Credit'
            group by a.msisdn
            having   sum (d.amt_gross * -1.0) >= 80;
        end ;     
    END;
    /You can then call them in pretty much the same way as with stand alone stored procedures
    BEGIN
        hvcreports.p_Weekly(1);
        hvcreports.p_Monthly(1);
    END;
    EXEC hvcreports.p_Weekly(1);
    EXEC hvcreports.p_Monthly(1);Hopefully I've not muddied the water too much. Here's some links to the documentation...
    Documentation hope page for 11gR2
    http://www.oracle.com/pls/db112/homepage
    PL/SQL language reference
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e25519/toc.htm
    PL/SQL development guide
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/toc.htm
    SQL Language reference
    http://download.oracle.com/docs/cd/E11882_01/server.112/e26088/toc.htm
    HTH
    David

  • Error message for running stored procedure

    Hello expert,
    I got error message for a stored procedure running as follows, will you please tell me what that error is? what is the reason for that error? appreciate very much.
    Job name=PROD DWH REPORT MART LOAD.1
    Job owner=DEVTEAM
    Job type=SQL Script
    Job status=Error
    Occurred At=Aug 9, 2011 5:26:29 AM EDT
    Target Name=proddw(Database Instance)
    Job output=
    Command:Output Log
    SQL*Plus: Release 10.2.0.3.0 - Production on Tue Aug 9 03:00:07 2011
    Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
    SQL> SQL> SQL> SQL> Connected.
    SQL> SQL> SQL> SQL> SQL> SQL>
    TO_CHAR(SYSDATE,'DD-
    09-aug-2011 03:00:07
    SQL> SQL>
    Many Thanks,

    What error? I can't see an error.

  • Error while executing the stored procedure through sender JDBC adapter

    Hi All,
    I am getting below error while executing the stored procedure through sender JDBC adapter.
    Database-level error reported by JDBC driver while executing statement 'exec SapgetNextEntity 'SalesOrder''. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
    what is the problem? any idea to anyone...
    regards
    Ramesh

    hi Dharamveer,
    I am not getting below statement for your reply
    Try to use Refrence Cursor it will return u reference of resultset.
    I mention SP like this
    exec SapgetNextEntity 'SalesOrder'
    SapgetNextEntity -
    > SP Name
    SalesOrder----
    > Parameter I am passing...
    regards
    Ramesh

  • Strange error while executing a stored procedure: Incorrect syntax near '@p0'

    All, I am getting a strange error while executing a stored procedure: Incorrect syntax near '@p0'  using JDBC CallableStatment.
    Here is my code...
    CallableStatement cStmt = con.prepareCall("{call SET CHAINED ON EXEC <dbName>.<schemaName>.<SPName> (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
    cStmt.setString(1, "2012005881");
    cStmt.setString(2, "07");
    cStmt.setString(3, "10");
    cStmt.setString(4, "Case title");
    cStmt.setString(5, "Open");
    java.sql.Date dt1 = new java.sql.Date(2014,10,20);
    cStmt.setDate(6, dt1);
    cStmt.setString(7, "01");
    cStmt.setString(8, "N");
    cStmt.setString(9, "ADA Test");
    cStmt.setString(10, "N");
    cStmt.setString(11, "English");
    cStmt.setString(12, "N");
    cStmt.setString(13, "N");
    cStmt.setString(14, "N");
    cStmt.setString(15, "N");
    cStmt.setString(16, "N");
    cStmt.setString(17, "N");
    cStmt.setString(18, "07");
    cStmt.setString(19, "10");
    cStmt.setString(20, "juache0");
    java.sql.Date dt2 = new java.sql.Date(2014,10,20);
    java.sql.Date dt3 = new java.sql.Date(2014,10,20);
    cStmt.setDate(21, dt2);
    cStmt.setDate(22, dt3);
    cStmt.setString(23, "userid0");
    cStmt.setString(24, "");
    cStmt.setString(25, "");  
    cStmt.setString(26, "");
    java.math.BigDecimal bg1 = new java.math.BigDecimal(10);
    cStmt.setBigDecimal(27, bg1);
    cStmt.setString(28, "userid");
    cStmt.setString(29, "userid");
    int hadResults = cStmt.executeUpdate();
    Your help is greatly appreciated.
    I am executing the above using Jconnect3.0 driver, inside WebSphere Application Server V8.0
    Thanks
    Nags

    NOTE: I don't work with JDBC/jConnect so (at this point) just some questions ...
    1 - are you sending this to ASE, ASA, IQ, or some other RDBMS?
    2 - what is the value of <schemaname>?
    3 - do you have other prepareCall() instances that successfully call a stored proc? [would be interesting to see if there's a difference in the format of the calls]
    A quick google search shows a couple ways to submit a stored proc execution to the RDBMS, with the format depending on the format expected by the target RDBMS.
    I'm wondering if you really need/want the parentheses around the argument list, ie, what happens if you change
    from
    -- parentheses around args
    EXEC <dbName>.<schemaName>.<SPName> ( ?,?,?,?,?,...,? )
    to
    -- no parentheses around args
    EXEC <dbName>.<schemaName>.<SPName> ?,?,?,?,?,...,?
    In ASE if I wrap the parameters in parentheses I get the same error you're getting:
    ================== w/ parentheses => error
    1> sp_who (sa)
    2> go
    Msg 102, Level 15, State 1:
    Server 'CC1_V1', Line 1:
    Incorrect syntax near 'sa'.   <<=== sa == @p0 ??
    ================== w/out parentheses => works
    1> sp_who sa
    2> go
    fid spid status  loginame origname ...
       0   17 running sa       sa       ...
    ==================

  • How to create a stored procedure and use it in Crystal reports

    Hi All,
    Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
    Thanks in advance.

    If you are using MSSQL SERVER then try creating a stored procedure like this
    create proc Name
    select * from Table
    by executing this in sql query analyzer will create a stored procedure that returns all the data from Table
    here is the syntax to create SP
    Syntax
    CREATE PROC [ EDURE ] procedure_name [ ; number ]
        [ { @parameter data_type }
            [ VARYING ] [ = default ] [ OUTPUT ]
        ] [ ,...n ]
    [ WITH
        { RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]
    [ FOR REPLICATION ]
    AS sql_statement [ ...n ]
    Now Create new report and create new connection to your database and select stored procedure and add it to the report that shows all the columns and you can place the required fields in the report and refresh the report.
    Regards,
    Raghavendra
    Edited by: Raghavendra Gadhamsetty on Jun 11, 2009 1:45 AM

  • Error saving map. Stored procedure returned non-zero result BizTalk Bug

    Hallo all
    MSDN is reporting this Bug.
    "Error saving map. Stored procedure returned non-zero result." error message when you deploy the BizTalk Server 2010 applications in BizTalk Server 2010 Administration Console"
    http://support.microsoft.com/kb/2673264/en-us
    I am having this problem in BizTalk 2013. Is this correct? or I am doing something wrong..
    This error occured as I was about to deploy BizTalk application from Visual studio 2012 to BizTalk 2013.
    If this bug is available in 2013, where can I get a fix for it..
    Thanks in Advance
    AKE

    Hi AKE,
    Fix for this bug in BizTalk Server 2013 is not publicly available yet. Only option to get the fix for this bug is to contact:
    http://support.microsoft.com/contactus/?ws=support
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

  • How to create a stored procedure in a dynamic schema

    Hi,
    I want to create a stored procedure in a dynamic shcema (schema name will be known at run time). Can any one guide me on this.
    I tried using define var1=schema1; and then in create or replace procedure &var1.porcName( ) but it is not working
    Thanks

    SQL> alter session set current_schema=<my schema>;
    Now create the stored procedure. It will be created in the session's current schema.

Maybe you are looking for

  • What's wrong with my iPod?!

    I've had my 5G iPod for a while now, and it has always worked in perfect condition. While I was listening to some music on it yesterday, all of a sudden the screen froze. It wasn't on hold, and the backlight remained on. After a few minutes, the ligh

  • Photoshop elements 6 raw image problems.

    PROBLEM 1:  I recently purchased a Canon 7D and got a free copy of PSE6, and I had to upgrade to camera raw 5.6 to view raw files.  I am now able to view raw files, but still get a error; "DLL c:\Programfiles\adobe\photoshop elements 6.0\Plug-Ins\Cam

  • Make non-mandatory field in Logical Database 'SDF'  mandatory.

    Hi all, I want to make a non-mandatory field 'Chart of Accounts'  in Logical Database 'SDF'  mandatory in my Z program. Please let me know how this can be done? I tried defining the select-option in my zprogram but it gives error saying the parameter

  • Workcentre Capacity

    Hi Experts, We want to maintain the capacity of work centre can you please answer the following : 1.We have created workcenter such as AUTO at second level & AUTO-WELD,AUTO-FITT on third level in Hierarchy. Could you tell me how I have to maintain th

  • How to generate possiable no of words by taking A-Z letters using java

    How to generate possiable no of words by taking A-Z letters using java.please give the code don't take repeation of letters ex: lets take a,b,c & the possiable no of words are list below a b c ab ac ba bc ca cb