Help in Stored Procedure Required

Dear All,
I have an udf in my Sales Order u_EnqNo which has some numbers. I want to have a check if while booking the Sales Order if some particular numbers are there then in the project code field which is in the row level of Sales Order should have project code ending with SP ( Special Project).
I am trying to make an Stored Procedure but its somehow not working and been asking for SP when already SP is there.
--Project code for Sales Order - Special Projects
if  @transaction_type IN (N'A', N'U') AND (@Object_type IN ('17'))
begin
if exists (select * from rdr1 b,ordr a
where b.DocEntry=@list_of_cols_val_tab_del
and (b.Project is null or b.Project='' or b.Project NOT Like '%%_SP' and a.DocEntry=b.Docentry
and a.u_EnqNo ='95021729' or a.u_EnqNo ='95021970' or a.u_EnqNo ='95022171' or
a.u_EnqNo ='95021972' or a.u_EnqNo ='95022210' or a.u_EnqNo ='95017240' or
a.u_EnqNo ='95010501' or a.u_EnqNo ='95021280' or a.u_EnqNo ='95020277' or
a.u_EnqNo ='95021957' or a.u_EnqNo ='95017862' or a.u_EnqNo ='95021093' or
a.u_EnqNo ='95020915' or a.u_EnqNo ='95021907' or a.u_EnqNo ='95015477' or
a.u_EnqNo ='95100300' or a.u_EnqNo ='95100354' or a.u_EnqNo ='95100349' or
a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
a.u_EnqNo ='95021666' or a.u_EnqNo ='95021519' or a.u_EnqNo ='95022148'))
begin
select  @error=10 , @error_message = N' Special Project...Provide Special Project Code with Suffix as SP'
end
end
Kindly advise.
Regards,
Swamy

You did not consider the precedence of the logical operators!
Try this:
--Project code for Sales Order - Special Projects
if  @transaction_type IN (N'A', N'U') AND (@Object_type IN ('17'))
begin
if exists (select * from rdr1 b,ordr a
where b.DocEntry=@list_of_cols_val_tab_del
and (b.Project is null or b.Project='' or b.Project NOT Like '%%_SP' and a.DocEntry=b.Docentry
and
(a.u_EnqNo ='95021729' or a.u_EnqNo ='95021970' or a.u_EnqNo ='95022171' or
a.u_EnqNo ='95021972' or a.u_EnqNo ='95022210' or a.u_EnqNo ='95017240' or
a.u_EnqNo ='95010501' or a.u_EnqNo ='95021280' or a.u_EnqNo ='95020277' or
a.u_EnqNo ='95021957' or a.u_EnqNo ='95017862' or a.u_EnqNo ='95021093' or
a.u_EnqNo ='95020915' or a.u_EnqNo ='95021907' or a.u_EnqNo ='95015477' or
a.u_EnqNo ='95100300' or a.u_EnqNo ='95100354' or a.u_EnqNo ='95100349' or
a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
a.u_EnqNo ='95100350' or a.u_EnqNo ='95028879' or a.u_EnqNo ='95021454' or
a.u_EnqNo ='95021666' or a.u_EnqNo ='95021519' or a.u_EnqNo ='95022148'
begin
select  @error=10 , @error_message = N' Special Project...Provide Special Project Code with Suffix as SP'
end
end
Or you can use a more simple form using this:
a.u_EnqNo in ('95021729', . . ., '95022148')

Similar Messages

  • Please help in Stored procedure? Psoting third time Urgent!!!

    Hi,
    We are running websphere3.5.3 on AS/400 machine with DB2Connect as local database.
    I am using com.ibm.db2.jdbc.app.DB2Driver
    We are trying to execute a servlet with stroedprocedure in it.
    In the bottom, I included complete error. Can some one help me? I tried so many things but nothing is working. Infact I could execute other storedprocedure which have hard code input values and outputvalues.
    Same stored procedure is working fine in coldfusion
    Following is creation, code, complete error of storedprocedure.
    I greatly appreciate your help.
    Thanks
    How we created stored procedure is
    create procedure fmgdata.test1
    in puserid char(10), in psuppno dec(7,0),in pitemno dec(5,0),out pmean dec(15,5),out pmedian dec(7,2), out
    pmode dec(7,2), out psamplefx dec(5,0), out pfmgdeal dec(7,2), out pfmgfist dec(7,2),out wrkdatmdy1 char(8),
    out wrkdatmdy2 char(8)
    language rpgle
    NOT DETERMINISTIC
    EXTERNAL NAME fmgdata.rdg002cf
    My code:
    public class storedProcServlet extends HttpServlet
    * Handle the GET Method
    public void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    PrintWriter output;
    String title = "Test Servlet2";
    // set the content type
    resp.setContentType("text/html");
    // write the output
    output = resp.getWriter();
    HttpSession session = req.getSession(true);
    output.println("<HTML><HEAD><TITLE>");
    output.println(title);
    output.println("</TITLE></HEAD><BODY>");
    // load the Db2driver bridge by referencing it
    try
    Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
    catch (Exception e)
    output.println("<P>Failed to load DB2driver.");
    return;
    output.println("<P>Loaded DB2driver.");
    String url = "jdbc:db2://s105k4tm//FMGDATA//SYSDATA//FMGLIB//SYSLIB//*USRLBL//QSYS//aaa";
    // get a connection
    try
    CallableStatement cstmt = null;
    ResultSet resultset = null;
    Connection con = DriverManager.getConnection(
    url, "QSECOFR", "wasadmin"); // User Name: sa, Password: "
    cstmt = con.prepareCall ("{call FMGDATA.test1(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
    if(cstmt == null)
    output.println("problem while callable statement");
    else
    output.println("create callable statement is Ok");
    output.println("Before 1");
    cstmt.setString(1,"MILAR");
    output.println("Before 2");
    cstmt.setDouble(2,21000);
    output.println("Before 3");
    cstmt.setDouble(3,65886);
    output.println("Before 4");
    cstmt.registerOutParameter(4, java.sql.Types.DOUBLE);
    output.println("Before 5");
    cstmt.registerOutParameter(5, java.sql.Types.DOUBLE);
    output.println("Before 6");
    cstmt.registerOutParameter(6, java.sql.Types.DOUBLE);
    output.println("Before 7");
    cstmt.registerOutParameter(7, java.sql.Types.DOUBLE);
    output.println("Before 8");
    cstmt.registerOutParameter(8, java.sql.Types.DOUBLE);
    output.println("Before 9");
    cstmt.registerOutParameter(9, java.sql.Types.DOUBLE);
    output.println("Before 10");
    cstmt.registerOutParameter(10, java.sql.Types.CHAR);
    output.println("Before 11");
    cstmt.registerOutParameter(11, java.sql.Types.CHAR);
    output.println("After 11");
    output.println("Before execute");
    cstmt.execute();
    output.println("After execute");
    catch (Exception e)
    e.printStackTrace(output);
    output.println("<P>This is output from a Stored Procedure Servlet.");
    output.println("</BODY></HTML>");
    output.close();
    //Handle the POST method. To handle POST, we will simple pass the request to the GET method
    public void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    doGet(req,resp);
    error
    Loaded DB2driver.
    create callable statement is Ok
    Before 1 Before 2 Before 3 Before 4 Before 5 Before 6 Before 7 Before 8 Before 9 Before 10 Before 11 After 11 Before execute
    com.ibm.db2.jdbc.app.DB2SQLException2: Trigger program or external routine detected an error. java/lang/Throwable.(Ljava/lang/String;)V+4 (Throwable.java:94) java/sql/SQLException.(Ljava/lang/String;Ljava/lang/String;I)V+1 (SQLException.java:43) com/ibm/db2/jdbc/app/DB2SQLException2.(Ljava/lang/String;Ljava/lang/String;I)V+1 (DB2SQLException2.java:300) com/ibm/db2/jdbc/app/DB2PreparedStatementRuntimeImpl.execute(II)I+40 (DB2PreparedStatementRuntimeImpl.java:387) com/ibm/db2/jdbc/app/DB2PreparedStatement.execute()Z+28 (DB2PreparedStatement.java:1381) storedProcServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+0 (storedProcServlet.java:19) javax/servlet/http/HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+32 (HttpServlet.java:740) javax/servlet/http/HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+25 (HttpServlet.java:853) com/ibm/servlet/engine/webapp/StrictServletInstance.doService(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+21 (ServletManager.java:626) com/ibm/servlet/engine/webapp/StrictLifecycleServlet._service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+46 (StrictLifecycleServlet.java:160) com/ibm/servlet/engine/webapp/ServletInstance.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Lcom/ibm/servlet/engine/webapp/WebAppServletInvocationEvent;)V+186 (ServletManager.java:360) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.handleWebAppDispatch(Lcom/ibm/servlet/engine/webapp/WebAppRequest;Ljavax/servlet/http/HttpServletResponse;Z)V+771 (WebAppRequestDispatcher.java:404) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.dispatch(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Z)V+443 (WebAppRequestDispatcher.java:203) com/ibm/servlet/engine/webapp/WebAppRequestDispatcher.forward(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+105 (WebAppRequestDispatcher.java:107) com/ibm/servlet/engine/srt/WebAppInvoker.handleInvocationHook(Ljava/lang/Object;)V+127 (WebAppInvoker.java:77) com/ibm/servlet/engine/invocation/CachedInvocation.handleInvocation(Ljava/lang/Object;)V+25 (CachedInvocation.java:67) com/ibm/servlet/engine/srp/ServletRequestProcessor.dispatchByURI(Ljava/lang/String;Lcom/ibm/servlet/engine/srp/ISRPConnection;)V+839 (ServletRequestProcessor.java:155) com/ibm/servlet/engine/oselistener/OSEListenerDispatcher.service(Lcom/ibm/servlet/engine/oselistener/api/IOSEConnection;)V+95 (OSEListener.java:300) com/ibm/servlet/engine/oselistener/SQEventListenerImp$ServiceRunnable.run()V+155 (SQEventListenerImp.java:230) com/ibm/servlet/engine/oselistener/SQEventListenerImp.notifySQEvent(Lcom/ibm/servlet/engine/oselistener/api/ISQEvent;)V+184 (SQEventListenerImp.java:104) com/ibm/servlet/engine/oselistener/serverqueue/SQEventSource.notifyEvent(Lcom/ibm/servlet/engine/oselistener/api/SQEventImp;)V+40 (SQEventSource.java:212) com/ibm/servlet/engine/oselistener/serverqueue/SQWrapperEventSource$SelectRunnable.notifyService()V+116 (SQWrapperEventSource.java:353) com/ibm/servlet/engine/oselistener/serverqueue/SQWrapperEventSource$SelectRunnable.run()V+124 (SQWrapperEventSource.java:220) com/ibm/servlet/engine/oselistener/outofproc/OutOfProcThread$CtlRunnable.run()V+104 (OutOfProcThread.java:248) java/lang/Thread.run()V+11 (Thread.java:479)
    This is output from a Stored Procedure Servlet.

    Thanks again Jschell,
    I will try to find out exactly what that stored proc is doing. They are saying this stored proc simply gets the values from database using inputs. No insert, delete or update.
    I am too thinking that sending inputs is giving problems.
    If you have any idea how can i format the inputs please let me know. Do you think any problem with driver??
    I did know the same is working in cold fusion fine. Basically it takes three values as inputs and gives 8 out put vaues. In cold fusion they formatted input such that
    AS/400 can under stand.
    In Cold Fusion they formatted as follows,
    <cfset supplier = Numberformat(supplier,'0000000')>
    <cfset item = Numberformat(item,'00000')>
    Even I am trying to do the same thing. It didn't work.
    I did execute some other simple sps where i give hard coded string as input retrieve int, double, strings as outputs.
    This is how they execute the same in cold fusion
    <cfstoredproc procedure="test1" datasource="#datasource#">          
    <cfprocparam type="In" cfsqltype="CF_SQL_CHAR" variable="puserid" value="#session.fsuser#">
    <cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="psuppno" value="#supplier#">
    <cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="pitemno" value="#item#">
    <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMean">
         <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMedian">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pMode">
              <cfprocparam type="Out" cfsqltype="CF_SQL_INTEGER" variable="psamplefx">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pfmgdeal">
              <cfprocparam type="Out" cfsqltype="CF_SQL_FLOAT" variable="pfmgfist">
              <cfprocparam type="Out" cfsqltype="CF_SQL_CHAR" variable="wrkdatmdy1">
              <cfprocparam type="Out" cfsqltype="CF_SQL_CHAR" variable="wrkdatmdy2">          
         </cfstoredproc>
    Thanks for any help,

  • Help: Using stored procedure to add new record in DB

    I am using stored procedures for a form. In DB, I have select and update procedures work without problems. However, for the insert procedure, it does not seem work right. Here is how things work for the insert procedure:
    1. On the form, I have an add record button, when this button is pressed, it calls the trigger "KEY_CREREC" with "create_record."
    2. A blank record is then shown on form. I then put in some test date. Apparently, this will cause "SYSTEM.STATUS" set to "CHANGED." when calling for commit, it only calls the DB update procedure.
    My question is how to make it call the insert procedure.
    Any suggestions are greatly appreciated.

    I just added to lines in key_commit to check the system.form_status:
    set_alert_property('AL_STOP', alert_message_text,'System Status: '||:system.form_status);
    al_button := show_alert('AL_STOP');
    After do_key('create_record') and some changes in fields, the :system.form_status shows "CHANGED.'
    Just wondering what will make the auto generated insert_procedure for the block to trigger. So far, no problems to do query and update with the DB stored procedure, but the insert does not seem working.
    Any help is greatly appreciated.
    P.S. The new post might be more clear:
    http://forums.oracle.com/forums/thread.jspa?threadID=675578&tstart=0
    Message was edited by:
    WJH

  • Help in stored procedure

    i have a stored procedure in MSSQL which needs to be migrated to oracle 10g,i have got problem related to migration.
    My mssql stored procedure is like as follows:
    create procedure sample(
    var1 varchar(20),
    var2 varchar(20) )
    as
    declare @V_TBL table(col1 varchar(20), col2 varchar(20))
    begin
    insert into @V_TBL(col1,col2)
    select col1,col2 from table1 where col1=@var1 and col2=@var2
    some more logic
    end
    now in oracle how do i create this variable table or some other way is there to solve this?

    > i have got problem related to migration.
    Yep.. and this is to be expected. Why? Because Oracle is different than SQL-Server. And it is because of these differences that the market buys Oracle. Not because Oracle is the same as SQL-Server, but because it is difference.
    The first thing you need to accept that migration is not going to be easy and painless - because of these differences.
    What works and works well in SQL-Server, can spell a performance disaster in Oracle. And vice versa.
    Why are temp tables typically used in SQL-Server and Sybase and Ingres and others? Because these databases have a different concurrency and isolation model than Oracle.
    In these products, Writers can block Readers and Readers can block Writers.
    In Oracle, a Reader will never block a Writer. A Writer will never block a Reader. One Writer will only ever block another Writer when vying for the same row. (and on a very rare occasion, when vying for the same data block that lacks sufficient transaction slots)
    Simple example. I open a cursor [SELECT * FROM emp]. I fetch 10 rows of a 100 rows. You start a transaction. You issue a [DELETE FROM emp] and commit. The EMP table is now empty. I fetch the next set of 10 rows using my cursor. What do I see?
    I see the next 10 rows as the EMP table looked like at the time I opened my cursor. I still see all 100 rows. Because that was The Truth at the time I opened my cursor. Oracle guarantees me a consistent read. No dirty reads.
    So the "tricks" you pulled in SQL-Server to work around the reader and writer blocking issue (a failure of SQL-Server ito providing read consistency), is not applicable in Oracle. And the reasons and methods for using temp tables in SQL-Server is not valid in Oracle.
    So when migrating SQL-Server stored proc code to Oracle.. it is a migration. Which means refactoring design and code. Do not expect to be able to simply port the design or code.

  • Need a help on stored procedure

    I have the sample data like the below.
    Employee Id Key Value
    1 Name Joe
    1 Age 28
    1 Addr Houston
    1 Sex M
         2 Addr Chicago     
    I need to get a result somethin like the below using a stored procedure.
    ID Name Age Addr Sex
    1 Jose 28 Houston M
    2     null     null     Chicago     null
    I need to write a stored proc for this......

    Assuming list of keys is static:
    with t as (
               select 1 employee_id,'Name' key,'Joe' val from dual union all
               select 1,'Age','28' from dual union all
               select 1,'Addr','Houston' from dual union all
               select 1,'Sex','M' from dual union all
               select 2,'Addr','Chicago' from dual
    select  employee_id,
            min(case key when 'Name' then val end) name,
            min(case key when 'Age' then val end) age,
            min(case key when 'Addr' then val end) addr,
            min(case key when 'Sex' then val end) sex
      from  t
      group by employee_id
      order by employee_id
    EMPLOYEE_ID NAME                                AGE     ADDR    SEX
              1 Joe                                 28      Houston M
              2                                             Chicago
    SQL> SY.

  • Help on Stored Procedure!

    Hi,
    I've this table AFM_USERS.
    CREATE TABLE AFM_USERS
    USER_PWD VARCHAR2(64 BYTE),
    USER_NAME VARCHAR2(64 BYTE),
    BAD_LOGIN NUMBER DEFAULT 0
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............0
    JOHN..............JOHN$.............0
    SMITH.............SMITH$............0
    KOSTER............KOSTER$...........0
    I've my application that connect Oracle via ODBC.
    When I connect, for example, with USER_NAME=ADAMS PASSWORD=ADAMS$ into sys.fga_log$ table I get 2 records:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.......TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34.....AFM........AFM_MODS....AFM_MODS.....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    When I connect, for example, with USER_NAME=SMITH PASSWORD=SMITH$ into sys.fga_log$ table I get others 2 records:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    When I connect, for example, with USER_NAME=SMITH PASSWORD=AAAA(Bad Password) into sys.fga_log$ table I get just one record:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:16:01,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    When I connect, for example, with USER_NAME=KOSTER PASSWORD=BBBBB(Bad Password) into sys.fga_log$ table I get just one record:
    OSUID.................OSHST......OBJ$SCHEMA....OBJ$NAME.....POLICYNAME.....TIMESTAMP..............LSQLTEXT...............................................................LSQLBIND
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:15:23,7030..SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):ADAMS
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS.......AFM_MODS....01/12/2008 7:15:26,7044....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34...AFM_SECURE....AFM_USERS....AFM_LOGIN....01/12/2008 7:15:35,7070...SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM........AFM_MODS......AFM_MODS....01/12/2008 7:15:38,7067.....SELECT afm_module,button,afm_module_it FROM afm_mods.................................
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN..01/12/2008 7:16:01,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):SMITH
    191.164.2.34\Sam...191.164.2.34....AFM_SECURE....AFM_USERS....AFM_LOGIN...01/12/2008 7:17:04,7067.......SELECT USER_NAME,USER_PSWD, COUNTER FROM afm_users WHERE user_name=:1....#1(5):KOSTER
    Now I'd like to create a stored procedure on sys.fga_log$ table that increase or decrease of 1 the COUNTER column of table AFM_USERS with these conditions:
    if I connect not correctly (user o password incorrect) I increase COUNTER of 1 (+1)
    if I connect correctly (user and password correct) I decrease COUNTER of 1 (-1)
    In my case I'd like to get like this:
    When I connect with USER_NAME=ADAMS PASSWORD=ADAMS$ I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$...............-1 -- (-1)
    JOHN..............JOHN$...................0
    SMITH.............SMITH$.................0
    KOSTER............KOSTER$.............0
    When I connect with USER_NAME=SMITH PASSWORD=SMITH$ I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$..............-1 -- (-1)
    KOSTER............KOSTER$...........0
    When I connect with USER_NAME=SMITH PASSWORD=AAAA(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$...............0 -- (+1)
    KOSTER............KOSTER$............0
    When I connect with USER_NAME=SMITH PASSWORD=BBBBB(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$............-1
    JOHN..............JOHN$.................0
    SMITH.............SMITH$...............1 -- (+1)
    KOSTER............KOSTER$...........0
    When I connect with USER_NAME=KOSTER PASSWORD=BBBBB(Bad Password) I'd like to get:
    execute my_stored_procedure;
    select *
    from AFM_USERS;
    USER_NAME.......USER_PSWD........COUNTER
    ADAMS.............ADAMS$..............-1
    JOHN..............JOHN$...................0
    SMITH.............SMITH$.................1
    KOSTER............KOSTER$..............1 -- (+1)
    How can I create my stored procedure?
    Thanks in advance.

    Raf Royal wrote:
    Hi,
    I've this table AFM_USERS.You do but we can't see them very well.
    After more than 250 posts on the forum we would expect you to be able to format any code and data on your posts you make here, rather than attempting to pad them out with lots of full-stops..............
    Edit your post and re-post the code/data with {noformat}{noformat} tags around it so that it's readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Urgent Help on Stored Procedure

    Hi,
    Could any one pls help me?
    The following is a stored proc where I'm trying to upload data from different tables into one single table. Queries #1 & #3[within cursor loop] are giving results for each policy nbr but #2 is returning no row which is correct in some occassion. I want the proc to go ahead and insert null values or Zero(either is O.K.) for #2 for all existing values of #1 & #3 for all policy numbers. But the proc is not proceeding further for other policy numbers as soon as it gets no value from #2 for the first policy number. It stops reading cursor for subsequent policy numbers and does no insert into the extract_rpts table. I'm using EXCEPTION handling but not working.
    Regards,
    Manojit.
    CREATE OR REPLACE PROCEDURE proc_upload_extract_data IS
    lv_POLICYNO extract_rpts.POLICYNO%TYPE;
    lv_ORIG_CONTR_CNT extract_rpts.ORIG_CONTR_CNT%TYPE :=0;
    lv_ANN_PMT_SUM_CNT extract_rpts.ANN_PMT_SUM_CNT%TYPE :=0;
    lv_ANN_GROSS_PMT_SUM_VAL extract_rpts.ANN_GROSS_PMT_SUM_VAL :=0;
    lv_stat varchar2(100);
    BEGIN
    /* Get all policy nbrs. */
    DECLARE CURSOR extr_pol IS
    SELECT DISTINCT policyno FROM master1;
    /* Following name will be referred for the cursor */
    get_pol extr_pol%ROWTYPE;
    /* Get all policy numbers from the cursor before extracting report data
    for each of the policies*/
    BEGIN
    OPEN extr_pol;
    LOOP
    FETCH extr_pol INTO get_pol;
    EXIT WHEN extr_pol%NOTFOUND;
    lv_POLICYNO := get_pol.policyno;
    /* 1. Original Contract Number */
    select count(policyno)
    into lv_ORIG_CONTR_CNT
    from master1
    where policyno = lv_POLICYNO
    group by policyno;
    /* 2. Annuity Payment Summation Count */
    select count(trxcode)
    into lv_ANN_PMT_SUM_CNT
    from master3
    where trxcode = 7 and
    policyno = lv_POLICYNO
    group by policyno;
    /* 3. Annuity-Gross Payment Summation Value */
    select sum(d.grosspay)
    into lv_ANN_GROSS_PMT_SUM_VAL
    from master3 c, master4 d
    where c.policyno = lv_POLICYNO and
    c.trxcode = 7 and
    c.policyno = d.policyno and
    c.DATETRXEFF = d.DATETPAY
    group by c.policyno;
    /* Now since the data for the policy number is loaded into local
    variables, it is inserted into the extract_rpts table */
    insert into extract_rpts
    POLICYNO,
    ORIG_CONTR_CNT,
    ANN_PMT_SUM_CNT,
    ANN_GROSS_PMT_SUM_VAL )
    values (
    lv_POLICYNO,
    lv_ORIG_CONTR_CNT,
    lv_ANN_PMT_SUM_CNT,
    lv_ANN_GROSS_PMT_SUM_VAL
    END LOOP; /* for the cursor extr_pol */
    CLOSE extr_pol;
    END;
    EXCEPTION
    WHEN OTHERS THEN
    lv_stat := 'Correct Record';
    commit;
    END; /* of the procedure proc_upload_extract_data */
    null

    Hi Manojit,
    Unfortunatly your question is not
    related to Oracle Spatial.
    Please try posting this to metalink.
    Thanks.
    Dan

  • Stored Procedure requires compilation before every run....

    I have one simple SP in Oracle 8. It gets complied very nicely. But after i execute that SP, its defination from the database is lost. I again have to compile and execute it. This means that everytime i have to execute this SP i have first compile....
    I can't understand why this is happening??? IIf anybody knows how this can be solved then plz let me know...

    following is the SP code. Its long but a simple SP. I am not modifying any underlying objects. I think even if they are modified the SP gets recompiled when called... Have a look at it and help me...
    procedure apptrack_ware_funding_retrieve
    al_seller_id IN NUMBER,
    al_julian_id_num IN NUMBER,
    as_pgm_type_cde_uw_out OUT VARCHAR2,
    as_trust_acct_ind_out OUT VARCHAR2,
    af_tran_amt_sum_out OUT NUMBER,
    as_updt_dt_tm OUT VARCHAR2,
    al_traunch_use_out OUT NUMBER,
    al_whse_line_lmt_out OUT NUMBER,
    as_rpt_end_dt_out OUT VARCHAR2,
    al_pay_down_amt_out OUT NUMBER,
    al_tot_trust_acct_adva_out OUT NUMBER, /* Date:07/21/2000 .Added By Sunil */
    al_tot_trust_acct_reversal_out OUT NUMBER, /* Date:07/21/2000 .Added By Sunil */
    al_trust_reversal_amt_out OUT NUMBER
    AS
    sql_err NUMBER;
    err_msg VARCHAR2(300);
    li_row_count NUMBER;
    BEGIN
    select count(1) into li_row_count
    from TRUST_ACCT_ACTIVITY
    where SEQ_NUM = (select max(SEQ_NUM) from TRUST_ACCT_ACTIVITY
    where SELLER_ID = al_seller_id and
    JULIAN_ID_NUM = al_julian_id_num) and TRAN_CDE = 'R';
    if li_row_count = 1 then
    select TRAN_AMT into al_trust_reversal_amt_out
    from TRUST_ACCT_ACTIVITY
    where SEQ_NUM = (select max(SEQ_NUM) from TRUST_ACCT_ACTIVITY
    where SELLER_ID = al_seller_id and
    JULIAN_ID_NUM = al_julian_id_num) and TRAN_CDE = 'R';
    else
    al_trust_reversal_amt_out := 0;
    end if;
    /* Anthony Start 07/06/2000.*/
    select count(1) into li_row_count
    from seller_pay_down
    where (seller_id = al_seller_id and
    julian_id_num = al_julian_id_num );
    if li_row_count > 0 then
    select sum(pay_down_amt) into al_pay_down_amt_out
    from seller_pay_down
    where (seller_id = al_seller_id and julian_id_num = al_julian_id_num);
    else
    al_pay_down_amt_out := 0;
    end if;
    /* Anthony End. 07/06/2000.*/
    /* Dhawal changes begin. 06/22/2000.*/
    select count(1) into li_row_count
    from seller
    where seller_id = al_seller_id;
    if li_row_count = 1 then
    select to_char(max(rpt_end_dt),'MM/DD/YYYY') into as_rpt_end_dt_out
    from seller_settlement_summary
    where seller_id = al_seller_id;
    end if;
    /* Dhawal changes end. 06/22/2000.*/
    select count(1)
    into li_row_count
    from seller_traunch
    where seller_id = al_seller_id;
    if li_row_count > 0 then
    select sum(traunch_use_lmt) into al_traunch_use_out from seller_traunch
    where seller_id = al_seller_id and
    traunch_type||eff_dt in (select traunch_type||max(eff_dt)
    from (select * from seller_traunch where seller_id = al_seller_id)
    group by traunch_type);
    end if;
    select count(1)
    into li_row_count
    from seller
    where seller_id = al_seller_id;
    if li_row_count > 0 then
    select whse_line_lmt
    into al_whse_line_lmt_out
    from seller
    where seller_id = al_seller_id;
    end if;
    select count(1) into li_row_count
    from underwriting_info
    where (julian_id_num = al_julian_id_num
    and loan_type = '08'
    and preflite_ind ='P');
    if li_row_count = 1 then
    select pgm_type_cde_uw into
    as_pgm_type_cde_uw_out
    from underwriting_info
    where (julian_id_num = al_julian_id_num
    and loan_type = '08'
    and preflite_ind ='P');
    end if;
    select count(1) into li_row_count
    from seller
    where seller_id = al_seller_id;
    if li_row_count = 1 then
    select trust_acct_ind into
    as_trust_acct_ind_out
    from seller
    where seller_id = al_seller_id;
    end if;
    select nvl(sum(tran_amt),0) into
    af_tran_amt_sum_out
    from trust_acct_activity
    where seller_id = al_seller_id;
    /* Date:07/21/2000 .Added By Sunil to calculate total of all trust account advances for seller id */
    select nvl(sum(tran_amt),0) into
    al_tot_trust_acct_adva_out
    from trust_acct_activity
    where seller_id =al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'F' ;
    /* End of Adddition -------- Sunil. */
    /* Date:07/21/2000 .Added By Sunil to calculate total of all trust account reversals for seller id */
    select nvl(sum(tran_amt),0) into
    al_tot_trust_acct_reversal_out
    from trust_acct_activity
    where seller_id =al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'R';
    /* End of Adddition -------- Sunil. */
    select count(1) into li_row_count
    from trust_acct_activity
    where seller_id = al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'F'
    and seq_num = (select max(seq_num) from trust_acct_activity
    where seller_id = al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'F');
    if li_row_count = 1 then
    select to_char(updt_dt_tm,'MM/DD/YYYY HH24:MI:SS') into as_updt_dt_tm
    from trust_acct_activity
    where seller_id = al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'F'
    and seq_num = (select max(seq_num) from trust_acct_activity
    where seller_id = al_seller_id
    and julian_id_num = al_julian_id_num
    and tran_cde = 'F');
    end if;
    dbms_output.put_line ('program Type Code UW = ' || as_pgm_type_cde_uw_out);
    dbms_output.put_line ('Trust Account Indicator = ' || as_trust_acct_ind_out);
    dbms_output.put_line ('Trust Account Current Balance = ' || af_tran_amt_sum_out);
    dbms_output.put_line ('Report End Date = ' || as_rpt_end_dt_out);
    EXCEPTION
    when others then
    sql_err := sqlcode;
    err_msg := sqlerrm;
    DBMS_OUTPUT.PUT_LINE (sql_err);
    DBMS_OUTPUT.PUT_line (err_msg);
    APPTRACK_UPDATE_ERRLOG('OTHERS', SQLCODE, SQLERRM, 'apptrack_ware_funding_retrieve', 'JULIAN_ID_NUM='||TO_CHAR(NVL(al_julian_id_num, 0)));
    raise_application_error(-20011,'Database Error - Database Error code = '||sql_err||', Database Error Text = '||err_msg);
    END apptrack_ware_funding_retrieve;

  • Stored Procedure requires compilation before every execute....

    I have one simple SP in Oracle 8. It gets complied very nicely. But after i execute that SP, its defination from the database is lost. I again have to compile and execute it. This means that whenever i have to execute this SP i have to first compile it....
    I can't understand why this is happening??? If anybody knows how this can be solved then plz let me know...

    does your code start off:
    procedure whatever is ...
    or
    create or replace procedure whatever is ...
    If the former, then you are defining a procedure within a script. If the second, then you are creating a procedure to be stored in the database.

  • How to convert MSSQL stored procedure to PostgreSQL

    Hi,
    Anyone can help me...?
    How to convert MSSQL stored procedure to PostgreSQL function?
    Is there any tool available to convert T-SQL from MSSQL to PostgreSQL?
    Thanks in advance

    Hello
    Here, I write one sample stored procedure of SQL Server which I need to convert into PostgreSQL. Please help me in this with PostgreSQL.
    Thanks in advance.
    Below is sample SQL Server stored procedure: require to convert into PostgreSQL stored procedure
    CREATE PROCEDURE [dbo].[usp_GetData_ByTableName]
    @TableName NVARCHAR(MAX)
    ,@IncludeKeepAlive BIT
    ,@RowsAffected BIGINT=0 OUTPUT
    ) AS
    BEGIN
    SET NOCOUNT ON
    DECLARE @SQL VARCHAR(MAX)
    Select data base on parameter.
    SET @SQL =
    SELECT *FROM '+@TableName+'
    WHERE 1=1
    +
    CASE WHEN (@IncludeKeepAlive = 0)
    THEN
    AND [MessageTransactionID] <> 152
    ELSE
    END
    EXECUTE SP_EXECUTESQL @SQL
    RETURN 0

  • How do I get return parameters from a stored procedure call?

    The Open SQL Statement has an option on the Advanced tab to specify a command type of 'stored procedure'. In addition to returning a recordset, a stored procedure can also return parameters (see http://support.microsoft.com/support/kb/articles/Q185/1/25.ASP for info on doing this with ADO). Is it possible to get those return parameters with TestStand? In particular, I want to be able to get error codes back from the stored procedure in case it fails (maybe there is another way).

    The Open SQL Statement step type does not fully support stored procedures. If the procedure returns a record set than you can fetch the values as you would a SELECT statement. Stored procedures require you to setup the parameters before the call and this is not yet supported. Bob, in his answer, made a reference to the Statements tab and I think that he was talking about the Database Logging feature in TS 2.0.
    If the stored procedure is returning a return value, it may return as a single column, single row recordset which can be fetched as you normally do a record set.
    Scott Richardson
    National Instruments

  • How to determine number of records in recordset returned by stored procedure?

    In TestStand 3.0 I am calling an SQL stored procedure where the stored
    procedure returns a recordset. Everything appears to work (I can
    iterate through the recordset and see that the data is valid).
    However, I can not figure out how to easilly determine how many
    records are actually in the recordset. Unlike the 'Open SQL
    Statement' step, in the 'Data Operation' step that actually invokes
    the stored procedure, there is no 'Number of Records Selected' option
    to specify a TestStand variable to accept this value. I know I could
    iterate through the returned recordset incrementing a counter until a
    Fetch fails, but for larger recordsets, traversing the table multiple
    times would be quite time consuming
    . I am hoping to avoid this if
    possible. Is there an easier way to get the number of records in a
    recordset returned from a stored procedure call?
    Bob

    Bob -
    The cursor type of the ADO Recordset object affects whether the number of records can be determined. The Recordset.RecordCount property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
    Because ADO does not let me set the cursor type for command objects which is what a stored procedure requires, it is up to the data source to determine the type of cursor and the support for record count.
    Scott Richardson (NI)
    Scott Richardson
    National Instruments

  • How to retrieve 'long' column with 32K length in Java stored procedure

    For some reasons, we are not using CLOB, BLOB, or BFILE to store large objects and I have to live with LONG. So I wrote a Java stored procedure to insert, select and manipulate a LONG column by retrieving the LONG into a java.lang.String class (which happens to be the Java class mapped to the LONG SQL datatype). It all works fine as long as the length of the value being retrieved is less than the magic figure of 32767 bytes (which is the restriction on LONG and VARCHAR2 datatype in PL/SQL as well). So looks like Oracle's implementation of the JVM limits String values to a max of 32767 bytes. Suggestions on how to overcome this limitation (other classes that you suggest or do I have to move to files)?
    Thanks,
    Jeet
    null

    the jvm has nothing to do with it ...
    this is a pol/sql limitation on parameters in stored procedures.
    and java stored procedures require a clal spec that makes the j-s-p look like a pl/qsl stored proc.

  • Call unix commands from stored procedures

    My stored procedure requires to call unix commands HOW DO I DO IT?
    null

    i do not know pl sql but in java you can use:
    Runtime.getRuntime().exec("YOUR UNIX COMMAND");
    real example:
    Runtime.getRuntime().exec("ls");
    but you must be careful with using that...
    especially if you want to wait till the process finishes..
    rgds,

  • Help required in JDBC Stored Procedure

    Hi All,
    i have a requirement where i need to update the Database table using Stored Procedure from PI.
    I have the receiver JDBC channel and have done the mapping.
    The stored procedure has inputs of type NUMBER, VARCHAR2,DATE. in the message mapping i tried passing the same values in the type field, it throwed an error like UnSuppoted Format. Then i changed the type to integer for NUMBER and String for Varchar2 then also it is throwing an error like
    +java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'PUT_XXXXX' ORA-06550: line 1, column 7: PL/SQL: Statement ignored +
    Can any please help with what type i need to send from PI to Stored procedure?
    Also, there two out type fileds defined in the Stored procedure..which i didnt create in my PI structure. Do we need to create that fileds in our structure?
    Please help me.
    Thanks,
    Hemanth.

    Hi Hemanth Kumar,
    I understand that you want to execute a stored procedure using JDBC receiver channel and looking at error message, you think there is an issue with type defined in Data Type.
    Now you need to debug step by step.
    Step 1:- In Interface Mapping Determination, do not refer to Operational Mapping (delete only OM from there, not the receiver Message Interface). By doing so, you are not call the OM (which refer to Graphical Mapping (MM refer to Data Type (which you think is wrong)). Note: As there is no OM, we need to send the exact payload required by receiver JDBC from Runtime Work Bench, for testing purpose.
    Step 2:- In receiver JDBC channel, change u2018Message Protocolu2019 from u201CXML SQL Formatu201D to u201CNative SQL Stringu201D. By doing this, you can do testing very fast; receiver JDBC channel will take only String. And we need to send the exact String which is needed by JDBC Stored Procedure. [Link1|http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7c24a75cf83672e10000000a114a6b/frameset.htm]
    Step 3:- Now from RWB test the scenario. Payload should like this, please take help of Data base team to find the String which needs to send.
    EXECUTE PUT_uspAddress @City = 'New York'
    OR If you have access to the database, logon to it directly and try running the Stored Procedure.
    Step 4:- Now, you should have the string which executes the Stored Procedure correctly to go ahead. Your job is 60% done.
    Step 5:- Now, in receiver JDBC channel, change u2018Message Protocolu2019 from u201CNative SQL Stringu201D to u201CXML SQL Formatu201D. So that receiver JDBC channel will take only XML.
    Step 6:- So now, you have to construct equalant XML structure to String you got in Step 4.
    It may look like this [Link2|http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7b72b2fde93673e10000000a114a6b/frameset.htm]
    <StatementName>
        <storedProcedureName action=u201D EXECUTEu201D>
           <table> PUT_uspAddress </table>
            < City [isInput=u201Dtrueu201D] type=SQLDatatype>val1</ City>
        </storedProcedureName >
      </StatementName>
    Step 7:- Now use the XML you have constructed in Step 6, to test the scenario from RWB. Try to correct if you come up with some errors. Your job is 90% done.
    Step 8:- Now, in Interface Mapping Determination refer back the Operational Mapping again, which contain the Message Mapping. Make sure that Message Mapping give the XML output same as XML you have developed in Step 6.
    FYI. 1. Whatever youu2019re sending, it will be converted to JDBC statement and will be executed on the database. logSQLStatement(JDBC Additional parameters sapnote_0000801367) will be show in logging not in payload.
    2. Most of the cases, type defined in Data Type has no control of what we can send in that element (except Date type). Let say, you can define an element u2018Ageu2019 as u2018numberu2019, but you can always send u201Casdfasdfu201D as input in Message Mapping.
    Regards,
    Raghu_Vamsee

Maybe you are looking for

  • Why won't iTunes let me use

    Sorry if this is basic or has already been answered, but I'm new to iPods and unfamiliar with iTunes. So, about a year ago I moved in with my current roommate who had an iPod. He had previously lived with his parents and had used their computer as th

  • 2 transformation with same datasource

    Hi  Can I assign one Datasource to 2 DSO . I want to create a transformation . I hv already creatred one transformation with one DSO and by using the DS , I am creating a transformation with other DSO . getting msg that , DS is not active . Is it pos

  • Upgrade to OS 10.7 from 10.6.8

    Why can't I upgrade my mac iOS from 10.6.8 to 10.7?

  • Uninstallation of SQL Express 2005

    Hi~ ALL I have an instance named HPWJA installed. I don't know why it is installed . not I am going to uninstall it. however I can't find an "SQL Server" item on "Add and remove" list. I only see item in "Server Configuration". How to clearly uninsta

  • Overcharged. Contact me. Number 07711030074

    Hello. First of all, my bill came to £69.63. I prepaid £35 using my credit card. I have been charged £69.63. Please ensure that £34.63 reaches my account today to remedy the situation. Secondly, this is a poor system for providing feedback and compla