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.

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

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

  • 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')

  • 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

  • Need to create a Stored Procedure

    Hi,
    I have the following requirement. I have got securities historic tables in 2 of the databases and I need to compare the data in these tables based on some specific columns only.
    The output can be a table or a cursor. Can anyone help me out in doing this??
    I have 2 tables APP_DEVELOPMENT.SECMASTER_HIST and SECURITY.SECMASTER_HISTORY.
    CREATE TABLE APP_DEVELOPMENT.SECMASTER_HIST
    SECURITY_ALIAS NUMBER NOT NULL,
    COUPON NUMBER(28,12),
    CURRENCY_CODE CHAR(30 BYTE),
    INVESTMENT_TYPE CHAR(4 BYTE),
    ISSUE_NAME VARCHAR2(255 BYTE),
    PRIMARY_ASSET_ID CHAR(100 BYTE)
    EFFECTIVE_DATE DATE
    and
    CREATE TABLE SECURITY.SECMASTER_HISTORY
    SECURITY_ALIAS NUMBER,
    COUPON NUMBER(28,12),
    CURRENCY_CODE CHAR(30 BYTE),
    INVESTMENT_TYPE CHAR(4 BYTE),
    ISSUE_NAME VARCHAR2(255 BYTE),
    PRIMARY_ASSET_ID CHAR(100 BYTE)
    EFFECTIVE_DATE DATE
    I need to compare the CURRENCY_CODE,COUPON and INVESTMENT_TYPE column values.
    The output needed is a cursor or a table showing data from both the tables which differs based on the above mentioned 3 columns.
    NOTE:  SECURITY.SECMASTER_HISTORY is in a different DB and can be accessed via DB Links
    Thanks!

    select  CURRENCY_CODE,COUPON and INVESTMENT_TYPE, count(src1), count(src2)
      from ( select a.CURRENCY_CODE, a.COUPON, a.INVESTMENT_TYPE, 1 src1, to_number(null) src2 from <table1> a
             union all
             select b.CURRENCY_CODE, b.COUPON, b.INVESTMENT_TYPE, to_number(null) src1, 2 src2 from <table2> b
    group by  CURRENCY_CODE, COUPON, INVESTMENT_TYPE
    having count(src1) <> count(src2)
    order by 1,2,3
    See Ask Tom &amp;quot;comparing two table data and logging the...&amp;quot;

  • Need Detailed Help about storing at home, downloading on the go.

    I have a computer I have used itunes on without fail for about a year now, the only problem? I am running out of room on my laptop's hard drive, so I purchased a 1.5TB External Hard drive, which I would like to leave at home, I am currently moving all my itunes files to this new hard drive, however,
    1. I would still like to be able to sync my ipod on the go without losing the current music i have on my external drive at home.
    2. I would like to continue to download music onto my laptops hard drive, then transfer them to my itunes library on my new external hard drive when I return home. (as I am gone for work 2 weeks at a time) without messing up all my files.
    Is there an easy way to do this? what do I need to set my iphone options to so my stuff won't be deleted, and how can I download music to two different spots to keep my library nicely organized?

    Are you planning to take that hard drive with you when you're out and about? If so, then drag the entire iTunes folder (the entire folder, not just the iTunes Music folder) from your computer's internal drive to your desired location on the external drive. Then hold down the Shift key while launching iTunes. You'll be given a dialog box where you can select the iTunes library you want to use. Navigate to and select the iTunes folder in it's new location. iTunes will then be working entirely from the external drive, and you can repeat this procedure on any computer to which you connect your drive and iTunes should work the same as on your home system, including (to the best of my knowledge; I haven't tried this when hauling my secondary drive around) synching to your iPod.
    Note that this procedure assumes that all of your tracks are contained in the iTunes Music folder. If they're scattered around your volumes, moving them becomes much more complex. Note also that if you launch iTunes before the drive is connected and mounted, iTunes will automatically switch back to it's default location on the internal drive, in which case you'll have to quit and relaunch iTunes while holding down the Shift key and reselect the external drive.
    Warning: don't delete the tracks from the old location on the internal drive until you've confirmed that they're working correctly from the external drive.

  • Migrating from TSQL Need Help? printing multiple columns in Stored procedur

    I need to create a Stored Procedure which returns set of columns not all
    (for eg FirstName, LastName, Dept_Id) from emloyee table based on certain conditions.
    In TSQL, it is very simple to create such stored procedures which return full recordset(or subset).
    I tried creating explicit cursors but I can print only one record at a time. I dnt want concatenation of columns. I want seperate columns in ouput. How to achieve this.?
    Code : (But i can only concatenate and print results, what i want is diffrent columns)
    declare
    f_name employees.first_name%type;
    l_name employees.last_name%type;
    cursor c is
    select first_name,last_name
    from employees;
    begin
    open c;
    loop
    fetch c into f_name,l_name;
    exit when c%notfound;
    DBMS_OUTPUT.PUT_LINE (f_name||' '||l_name);
    end loop;
    close c;
    end;

    Another very informative article on ref cursors:
    PL/SQL 101 : Understanding Ref Cursors

  • Need to insert data in 2 tables thro stored procedure

    I need to create a stored procedure which will insert data in two tables. The procedure will get
    its inputs from an Oracle Developer Form which will be inserted into the tables.
    The 2 tables structure:
    1.FEES_MASTER
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Primary Key
    CS_ID NOT NULL NUMBER(8) -- Class Student ID; An enrolled student
    REC_DATE NOT NULL DATE -- Fees receipt date
    REC_AMOUNT NOT NULL NUMBER(6) -- Fees receipt amount
    2.FEES_DETAIL
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Foreign Key
    MONTH NOT NULL DATE -- First of each month to identify fee month
    Scenario:
    A student submits fees for 3 months through Master/Detail related blocks in a Developer Form as
    Under:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    I need to check each fees detail record for fees month duplication as well before inserting new records.
    How can this be achieved?
    Thanks in advance.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Fan Liu ([email protected]):
    create primary key in the detail table. i think it's FEES_ID + MONTH. then mark the columns in Forms as primary key property true, then call check_record_uniqueness built-in in on-check-unique trigger.<HR></BLOCKQUOTE>
    Thanks very much. But what I need is to ensure transaction integrity thro stored procedure. The system allows a certain CS_ID (i.e. Class Student ID, which is assigned a new one to every student annually) to submit fees for 12 months only, because a student stays in a class for a year. The 2 columns in the FEES_DETAIL table are composite primary key which only ensures that a certain FEES_ID will not be repeated for the same month. But suppose:
    1)this data already exist in the tables:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    2)And this data is currently being inserted:
    Fees Master
    Fees ID : 11300
    Class Student ID : 356
    Receipt Date : 04-FEB-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11300 01-JAN-2001
    11300 01-FEB-2001
    11300 01-MAR-2001
    The data in the 2nd condition is perfectly valid but the application can't allow a student to submit fees for a month which he has already submitted. Now only a stored procedure can make sure after checking that the same student doesn't pay fees for duplicate months. Another reason for my emphasis on stored procedure is that what if a user tries to insert data thro an SQL* Plus session instead of the Form.
    PROBLEM: Now the problem I am having is I don't know how the procedure will take input for multiple records from the FEES_DETAIL block in the Form.
    Please assist in this regard. Thanks.

  • I need Your Help for CAF/EU/GP/API Guided Procedures

    Hi everyone, I need your help about Guided procedures CAF API, I am developing an WEB DYNPRO Callable Object for Guided Procedures, but I need to get the task name of the running proceess on Guided Procedure once time a user initiated it, if is possible? Do you have an examples?
    Thenk you very much

    Hi,
    Yes you can retrieve the task name of the running process. Here is what you need to do.
    1. Get the process instance - IGPRuntimeManager - > getInstance()
    2. Get the IGPActivityInstance(s) from the process instance - processInstance.getChildrenInformation().
    3. Optionaly check if these child activities are Blocks or Actions. If Block drill further to get the Actions using getChildrenInformation().
    4. Retreive the IGPActionInstance(s) from the Block Activities.
    5. Get the IGPActivity object for these Actions using IGPActionInstance.getTemplate() method.
    6.  This object will have a method getTitle() which will retrive you the activity name.
    Hope this helps.
    Thanks
    Kiran

  • Flags needs to set to run stored procedure fast

    Hi,
    I need to understand what all flags that we need to set run stored procedure fast.
    e.g. set no count on command is one option, please redirect me to other command so that I can use those for each stored procedure.

    That is the only general option, however, no relationship to performance.  Other options may be appropriate depending on the program statements.
    To achieve good performance, optimize the stored procedure:
    http://www.sqlusa.com/articles/query-optimization/
    The underlying principles of stored procedure optimization:
    1. Each statement must be optimized
    2. Avoid unnecessary statements & excessive looping
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • How to Consum array returned by Stored Procedure through DB adapter in BPEL

    Hi all,
    Requirement is, from BPEL through DB Adapter I need to invoke a Stored Procedure in Oracle. Stored procedure takes a String as Input and will returns as Table type object (will return multiple row for a given input) as output. When I try to create a DB Adapter its throwing error as below.
    “…Parameter V_List_Info (output variable name) is of type EMPloyee.emp_detail_tbl which is either not supported or is not an Implemented datatype….”
    Appreciate your help to resolve this issue by suggesting some alternate options. Thanks in Advance,
    Mohan

    Thanks Vijay for your response.
    I have gone through the link which you have shared. This is having Table Type in Input parameter and we tried another stored procedure which has table type as Input Parameter and it works.
    But in my case, the out put is Table type and giving above mentioned error. Please let me know if you need any more details.
    Thanks,
    Mohan.

  • Executing a stored procedure from an Ifs Program

    I have a need to execute a stored procedure in another schema
    within the same database, and I need to receive an OUT parameter
    to continue processing. The oracle.ifs.server.sql.IfsConnection
    is not in my class path. Can someone tell me which jar file to
    adde to my classpath to have this funcitonality that IFS claim.
    Regards,
    Jeff

    Guys I need help with this one as soon as possible.

Maybe you are looking for

  • Firefox process starts but window doesn't open.

    All the suddenly when I start Firefox 11 the window doesn't appear but the process will start in task manager. Yesterday morning everything worked well, but when I came home at evening Microsoft Security Essentials wasn't starting it's protection. I

  • Is it possible to activate an ipad w/o an internet connection on a mac?

    Is it possible to activate an ipad without an internet connection on my mac? I have got a macbook pro with iTunes 10.1.2 (17) and an micro-sim card with a iPad 3G data plan, so I can use it directly with the iPad, but I have to activate the iPad at f

  • Iphone won't show up in itunes no matter what!

    I'm having the same non-sync problem that others are having with itunes 10.1 on Windows XP Pro SP3 not ever acknowledging my iphone. Could my graphics card have any effect on this? I have an Invidia Quadro FX 3400.4400 currently in the slot. If my ip

  • How can i buy an app if this app isn't en my country

    I need buy the app radio, but in my country Ecuador there isn't? How ca I do?

  • NT Realm and Properties Files

    Hi, Does anyone experience similar problem. I am using NT Realm using a user already define in my NT domain. The properties File for WLS required that password be present for the system user. Having this when I start weblogic, I can log onto WLS with