Please help-PLSQL complex procedure writing

Hi all,
I am back again and requesting your help on this.I want your help to properly write the below code because now i feel-that its very confusing and not easily readable and following the program is tough.
I want to replace the same looping done below in many places using a function/or any other approaches.Then,need all your important suggestions in any other ways,approach...i can do the same which would be good for performance and best practices here.
Please help me as i am very stuck with this and struggling so much.
For any suggested things-please help me with the new code which will be very helping
CREATE OR REPLACE PROCEDURE "TEST_PROCEDURE" (
   p_strtplanid    test_training_plan.tplan_id%TYPE,
   p_strpersonid   test_person.person_id%TYPE,
   p_strorg_id     test_org.org_id%TYPE
IS
  /*Here declarartion of variables */
BEGIN
   /*Since TP is presently in LR,verify if its completed or not*/
   SELECT COUNT (learning_record_id)
     INTO v_inttpcompltd
     FROM test_learning_record lr
    WHERE lr.catalog_item_type = 'training-plan'
      AND lr.status IN ('PASSED', 'WAIVED', 'TESTED_OUT')
      AND lr.lr_catalog_history_id = p_strtplanid
      AND lr.lr_person_id = p_strpersonid
      AND lr.lr_org_id = p_strorg_id;
   /*Credit based */
   SELECT is_credit_based
     INTO v_intcreditbased
     FROM test_training_plan
    WHERE tplan_id = p_strtplanid;
   IF (v_inttpcompltd > 0)
   THEN
      IF (v_intcreditbased = 1)
      THEN
         DBMS_OUTPUT.put_line ('Starting Credit based ');
         v_inttotreqactcompltd :=
            fn_tp_get_cmpltd_act_cnt (p_strtplanid,
                                      p_strpersonid,
                                      p_strorg_id
         SELECT NVL (EXTRACT (tplan_xml_data, '//numberOfCredits/text()').getstringval
                     0
                NVL (EXTRACT (tplan_xml_data, '//accreditingOrg/text()').getstringval
                     0
           INTO v_intrequiredcredits,
                v_straccreditingorg
           FROM test_training_plan
          WHERE tplan_id = p_strtplanid;
         SELECT accred_org_id
           INTO v_straccreditingorg
           FROM test_tp_acc_org
          WHERE tplan_id = p_strtplanid;
         IF (v_intrequiredcredits > v_inttotreqactcompltd)
         THEN
            DBMS_OUTPUT.put_line ('test_tp_acc_org ');
            FOR obj IN (SELECT t_objective_id,
                               NVL (required_credits, 0) required_credits
                          FROM test_tp_objective
                         WHERE tplan_id = p_strtplanid)
            LOOP
               DBMS_OUTPUT.put_line
                  (   ' Looping each Objective******************************'
                   || obj.t_objective_id
               SELECT NVL (SUM (lcdt.credit_hours), 0)
                 INTO v_inttotreqacttobecompltd
                 FROM test_train_obj_activity toa,
                      test_tp_objective tpobj,
                      test_learningactivity_credits lcdt,
                      test_tp_acc_org acc_org
                WHERE lcdt.learning_activity_id = toa.activity_id
                  AND lcdt.acc_org_id = v_straccreditingorg
                  AND toa.t_objective_id = tpobj.t_objective_id
                  AND tpobj.tplan_id = acc_org.tplan_id
                  AND toa.t_objective_id = obj.t_objective_id
                  AND tpobj.tplan_id = p_strtplanid
                  AND tpobj.t_objective_id = obj.t_objective_id
                  AND toa.is_required = 1;
               DBMS_OUTPUT.put_line
                               (   'Total credits for required activities****'
                                || v_inttotreqacttobecompltd
               --get credits for non event activities
               SELECT NVL (SUM (credit_hours), 0)
                 INTO v_intnoneventbasedactcredit
                 FROM test_tp_objective tobj,
                      test_train_obj_activity toa,
                      test_learningactivity_credits lac,
                      test_learning_record lr,
                      test_tp_learning_activity tplplr,
                      test_learning_record tplr
                WHERE tobj.t_objective_id = obj.t_objective_id
                  AND toa.t_objective_id = tobj.t_objective_id
                  AND toa.activity_id = lac.learning_activity_id
                  AND toa.activity_id = lr.lr_catalog_history_id
                  AND toa.is_required = 1
                  AND lr.learning_record_id = tplplr.activity_lp_lr_id
                  AND tplplr.tp_lp_lr_id = tplr.learning_record_id
                  AND tobj.tplan_id = p_strtplanid
                  AND tplr.lr_catalog_history_id = p_strtplanid
                  AND acc_org_id = v_straccreditingorg
                  AND lr.lr_person_id = p_strpersonid
                  AND tplr.lr_person_id = p_strpersonid
                  AND lr.status IN ('PASSED', 'WAIVED', 'TESTED_OUT');
               --Get credits for events
               SELECT NVL (SUM (credit_hours), 0)
                 INTO v_inteventbasedactcredit
                 FROM test_learningactivity_credits lac
                WHERE lac.learning_activity_id IN (
                         SELECT event_id
                           FROM test_tp_objective tobj,
                                test_train_obj_activity toa,
                                test_learning_record lr,
                                test_event_sessions sessions,
                                test_tp_learning_activity tplplr,
                                test_learning_record tplr
                          WHERE tobj.t_objective_id = obj.t_objective_id
                            AND tobj.t_objective_id = toa.t_objective_id
                            AND toa.activity_id = sessions.event_id
                            AND toa.is_required = 1
                            AND sessions.event_session_id =
                                                      lr.lr_catalog_history_id
                            AND lr.learning_record_id =
                                                      tplplr.activity_lp_lr_id
                            AND tplplr.tp_lp_lr_id = tplr.learning_record_id
                            AND tplr.lr_catalog_history_id = p_strtplanid
                            AND tobj.tplan_id = p_strtplanid
                            AND tplr.lr_person_id = p_strpersonid
                            AND lr.lr_person_id = p_strpersonid
                            AND lr.status IN
                                           ('PASSED', 'WAIVED', 'TESTED_OUT'))
                  AND acc_org_id = v_straccreditingorg;
               v_inttotreqactcompltd :=
                        v_intnoneventbasedactcredit + v_inteventbasedactcredit;
               DBMS_OUTPUT.put_line
                            (   ' Total credits of reqd. completed activities'
                             || v_inttotreqactcompltd
               IF (v_inttotreqacttobecompltd <= v_inttotreqactcompltd)
               THEN
                  DBMS_OUTPUT.put_line
                     (   '****** START INSIDE OBJ-COUNT COMPLETED************** '
                      || obj.required_credits
                  v_strreturnval :=
                     fn_tp_obj_comp_act_cdt (p_strpersonid,
                                             p_strtplanid,
                                             obj.t_objective_id,
                                             v_intcreditbased
                  DBMS_OUTPUT.put_line (   'FN_TP_GET_CMPLTD_ACT_CNT'
                                        || v_strreturnval
                  IF (obj.required_credits > v_strreturnval)
                  THEN
                     DBMS_OUTPUT.put_line
                               || obj.required_credits
*I want to write a function/or any other approaches to do the below looping and SELECT functionality and also read the return certain values selected.*
*Most importantly- this query being run in several places throughout the whole main program and everytime I have to put this SQL there and*
*which has increased the code by huge amount.*
**Another thing is-I want to remove the NOT IN below and use a different approach.
                     /*Start processing of new activity */
                     FOR activity IN
                        (SELECT objact.activity_id, objact.activity_type,
                                objact.is_required
                           FROM test_training_plan tp,
                                test_tp_objective tp_obj,
                                test_train_obj_activity objact
                          WHERE tp.tplan_id = tp_obj.tplan_id
                            AND tp.tplan_id = p_strtplanid
                            AND tp_obj.t_objective_id = obj.t_objective_id
                            AND tp_obj.t_objective_id = objact.t_objective_id
                            AND objact.activity_id NOT IN (
                                   SELECT tplplr.activity_id
                                     FROM test_learning_record lr,
                                          test_learning_record lr1,
                                          test_tp_learning_activity tplplr
                                    WHERE lr.lr_catalog_history_id =
                                                            tplplr.activity_id
                                      AND lr.learning_record_id =
                                                      tplplr.activity_lp_lr_id
                                      AND tplplr.tp_lp_lr_id =
                                                        lr1.learning_record_id
                                      AND lr1.lr_catalog_history_id =
                                                                  p_strtplanid
                                      AND lr.lr_person_id = p_strpersonid
                                      AND lr1.lr_person_id = p_strpersonid
                                      AND lr.status IN
                                             ('PASSED', 'WAIVED',
                                              'TESTED_OUT'))
                            AND objact.activity_id NOT IN (
                                   SELECT event_id
                                     FROM test_train_obj_activity toa,
                                          test_event_sessions sessions,
                                          test_learning_record lr1,
                                          test_tp_learning_activity tplearnact,
                                          test_learning_record tplr
                                    WHERE toa.activity_id = sessions.event_id
                                      AND sessions.event_session_id =
                                                     lr1.lr_catalog_history_id
                                      AND lr1.learning_record_id =
                                                  tplearnact.activity_lp_lr_id
                                      AND tplearnact.tp_lp_lr_id =
                                                       tplr.learning_record_id
                                      AND tplr.lr_catalog_history_id =
                                                                  p_strtplanid
                                      ---AND toa.is_required = 1
                                      AND toa.t_objective_id =
                                                            obj.t_objective_id
                                      AND tplr.lr_person_id = p_strpersonid
                                      AND lr1.lr_person_id = p_strpersonid
                                      AND lr1.status IN
                                             ('PASSED', 'WAIVED',
                                              'TESTED_OUT')))
                     LOOP
                        /*The function should return data so that i can validate them as the below ones*/
                        IF (activity.activity_type = 'Course')
                        THEN
                           sp_test_assign_coursetp (p_strpersonid,
                                               activity.activity_id,
                                               p_strpersonid,
                                               activity.activity_type,
                                               activity.is_required,
                                               p_strtplanid,
                                               v_straccreditingorg,
                                               obj.t_objective_id,
                                               v_strlpid
                        ELSIF (activity.activity_type = 'Test')
                        THEN
                           sp_assign_testtp (p_strpersonid,
                                             activity.activity_id,
                                             p_strpersonid,
                                             activity.activity_type,
                                             activity.is_required,
                                             p_strtplanid,
                                             v_straccreditingorg,
                                             obj.t_objective_id
                        END IF;
                     END LOOP;
                     DBMS_OUTPUT.put_line ('Case of Optional Activity');
                  ELSE
                     /*Start processing of new activity */
                     FOR activity IN
                        (SELECT objact.activity_id, objact.activity_type,
                                objact.is_required
                           FROM test_training_plan tp,
                                test_tp_objective tp_obj,
                                test_train_obj_activity objact
                          WHERE tp.tplan_id = tp_obj.tplan_id
                            AND tp.tplan_id = p_strtplanid
                            AND tp_obj.t_objective_id = obj.t_objective_id
                            AND objact.is_required = 1
                            AND tp_obj.t_objective_id = objact.t_objective_id
                            AND objact.activity_id NOT IN (
                                   SELECT tplplr.activity_id
                                     FROM test_learning_record lr,
                                          test_learning_record lr1,
                                          test_tp_learning_activity tplplr
                                    WHERE lr.lr_catalog_history_id =
                                                            tplplr.activity_id
                                      AND lr.learning_record_id =
                                                      tplplr.activity_lp_lr_id
                                      AND tplplr.tp_lp_lr_id =
                                                        lr1.learning_record_id
                                      AND lr1.lr_catalog_history_id =
                                                                  p_strtplanid
                                      AND lr.lr_person_id = p_strpersonid
                                      AND lr1.lr_person_id = p_strpersonid
                                      AND lr.status IN
                                             ('PASSED', 'WAIVED',
                                              'TESTED_OUT'))
                            AND objact.activity_id NOT IN (
                                   SELECT event_id
                                     FROM test_train_obj_activity toa,
                                          test_event_sessions sessions,
                                          test_learning_record lr1,
                                          test_tp_learning_activity tplearnact,
                                          test_learning_record tplr
                                    WHERE toa.activity_id = sessions.event_id
                                      AND sessions.event_session_id =
                                                     lr1.lr_catalog_history_id
                                      AND lr1.learning_record_id =
                                                  tplearnact.activity_lp_lr_id
                                      AND tplearnact.tp_lp_lr_id =
                                                       tplr.learning_record_id
                                      AND tplr.lr_catalog_history_id =
                                                                  p_strtplanid
                                      AND toa.is_required = 1
                                      AND toa.t_objective_id =
                                                            obj.t_objective_id
                                      AND tplr.lr_person_id = p_strpersonid
                                      AND lr1.lr_person_id = p_strpersonid
                                      AND lr1.status IN
                                             ('PASSED', 'WAIVED',
                                              'TESTED_OUT'))
                     LOOP
                        /*Move the TP only for required ids */
                        IF (activity.activity_type = 'Course')
                        THEN
                           SP_TEST_ASSIGN_COURSETP (p_strpersonid,
                                               activity.activity_id,
                                               p_strpersonid,
                                               activity.activity_type,
                                               activity.is_required,
                                               p_strtplanid,
                                               v_straccreditingorg,
                                               obj.t_objective_id,
                                               v_strlpid
                        ELSIF (activity.activity_type = 'Test')
                        THEN
                           sp_assign_testtp (p_strpersonid,
                                             activity.activity_id,
                                             p_strpersonid,
                                             activity.activity_type,
                                             activity.is_required,
                                             p_strtplanid,
                                             v_straccreditingorg,
                                             obj.t_objective_id
                        END IF;
                     END LOOP;
                  END IF;
               ELSE
                  DBMS_OUTPUT.put_line
                     ('*********/*No of required credits is more then completed
                            ******Start processing of new activity */'
                  /*Start processing of new activity */
                  FOR activity IN
                     (SELECT objact.activity_id, objact.activity_type,
                             objact.is_required
                        FROM test_training_plan tp,
                             test_tp_objective tp_obj,
                             test_train_obj_activity objact
                       WHERE tp.tplan_id = tp_obj.tplan_id
                         AND tp.tplan_id = p_strtplanid
                         AND tp_obj.t_objective_id = obj.t_objective_id
                         AND objact.is_required = 1
                         AND objact.t_objective_id = tp_obj.t_objective_id
                         AND objact.activity_id NOT IN (
                                SELECT tplplr.activity_id
                                  FROM test_learning_record lr,
                                       test_learning_record lr1,
                                       test_tp_learning_activity tplplr
                                 WHERE lr.lr_catalog_history_id =
                                                            tplplr.activity_id
                                   AND lr.learning_record_id =
                                                      tplplr.activity_lp_lr_id
                                   AND tplplr.tp_lp_lr_id =
                                                        lr1.learning_record_id
                                   AND lr1.lr_catalog_history_id =
                                                                  p_strtplanid
                                   AND lr.lr_person_id = p_strpersonid
                                   AND lr1.lr_person_id = p_strpersonid
                                   AND lr.status IN
                                           ('PASSED', 'WAIVED', 'TESTED_OUT'))
                         AND objact.activity_id NOT IN (
                                SELECT event_id
                                  FROM test_train_obj_activity toa,
                                       test_event_sessions sessions,
                                       test_learning_record lr1,
                                       test_tp_learning_activity tplearnact,
                                       test_learning_record tplr
                                 WHERE toa.activity_id = sessions.event_id
                                   AND sessions.event_session_id =
                                                     lr1.lr_catalog_history_id
                                   AND lr1.learning_record_id =
                                                  tplearnact.activity_lp_lr_id
                                   AND tplearnact.tp_lp_lr_id =
                                                       tplr.learning_record_id
                                   AND tplr.lr_catalog_history_id =
                                                                  p_strtplanid
                                   AND toa.is_required = 1
                                   AND toa.t_objective_id = obj.t_objective_id
                                   AND tplr.lr_person_id = p_strpersonid
                                   AND lr1.lr_person_id = p_strpersonid
                                   AND lr1.status IN
                                           ('PASSED', 'WAIVED', 'TESTED_OUT')))
                  LOOP
                     /*Move the TP only for required ids */
                     IF (activity.activity_type = 'Course')
                     THEN
                        sp_assign_coursetp (p_strpersonid,
                                            activity.activity_id,
                                            p_strpersonid,
                                            activity.activity_type,
                                            activity.is_required,
                                            p_strtplanid,
                                            v_straccreditingorg,
                                            obj.t_objective_id,
                                            v_strlpid
                     ELSIF (activity.activity_type = 'Test')
                     THEN
                        sp_assign_testtp (p_strpersonid,
                                          activity.activity_id,
                                          p_strpersonid,
                                          activity.activity_type,
                                          activity.is_required,
                                          p_strtplanid,
                                          v_straccreditingorg,
                                          obj.t_objective_id
                     END IF;
                  END LOOP;
               END IF;
               FOR lr_lp_act IN (SELECT tplplr.activity_id,
                                        tplplr.tp_lp_lr_id
                                   FROM test_tp_objective tp_obj,
                                        test_train_obj_activity toa,
                                        test_learning_record lr,
                                        test_tp_learning_activity tplplr,
                                        test_learning_record tplr
                                  WHERE tplplr.activity_lp_lr_id =
                                                         lr.learning_record_id
                                    AND lr.lr_catalog_history_id =
                                                               toa.activity_id
                                    AND tplplr.tp_lp_lr_id =
                                                       tplr.learning_record_id
                                    AND tp_obj.t_objective_id =
                                                            toa.t_objective_id
                                    AND tp_obj.tplan_id = p_strtplanid
                                    AND tplplr.lp_lr_flag = 'LR'
                                    AND tp_obj.t_objective_id =
                                                            obj.t_objective_id
                                    AND lr.status IN
                                           ('PASSED', 'WAIVED', 'TESTED_OUT')
                                    AND lr.lr_person_id = p_strpersonid
                                    AND tplr.lr_person_id = p_strpersonid)
               LOOP
                  DBMS_OUTPUT.put_line
                      (   'Get data for the activity to update TPs LP id****'
                       || v_strlpid
                  DBMS_OUTPUT.put_line
                     (   'Values which I am updating----lr_lp_act.activity_id---'
                      || obj.t_objective_id
                  DBMS_OUTPUT.put_line
                     (   'Values which I am updating----lr_lp_act.activity_id---'
                      || lr_lp_act.activity_id
                  DBMS_OUTPUT.put_line
                     (   'Values which I am updating----lr_lp_act.tp_lp_lr_id---'
                      || lr_lp_act.tp_lp_lr_id
                  UPDATE test_tp_learning_activity
                     SET tp_lp_lr_id = v_strlpid
                   WHERE activity_id = lr_lp_act.activity_id
                     AND tp_lp_lr_id = lr_lp_act.tp_lp_lr_id;
                  UPDATE test_learning_record
                     SET is_for_training_plan = 'NO'
                   WHERE learning_record_id IN (
                                     SELECT activity_lp_lr_id
                                       FROM test_tp_learning_activity
                                      WHERE tp_lp_lr_id =
                                                         lr_lp_act.tp_lp_lr_id);
               END LOOP;
            END LOOP;
            DELETE FROM test_learning_record_details
                  WHERE learning_record_id =
                           (SELECT learning_record_id
                              FROM test_learning_record
                             WHERE lr_catalog_history_id = p_strtplanid
                               AND lr_person_id = p_strpersonid
                               AND status = 'PASSED');
            DBMS_OUTPUT.put_line
               ('UPDATE
                                    test_learning_record_details'
            DELETE FROM test_learning_record
                  WHERE learning_record_id =
                           (SELECT learning_record_id
                              FROM test_learning_record
                             WHERE lr_catalog_history_id = p_strtplanid
                               AND lr_person_id = p_strpersonid
                               AND status = 'PASSED');
         END IF;

Hello, as I mentioned on the other thread, views are the way to go here, not functions (they can be expensive from a performance perspective).
Therefore, for each group of repeated SELECTs, can you create a view based on that SELECT, and then substitute the view for the SELECTs in this code, and repost it (you know the code best) -- it will be easier then to rationalise it, and it would seem very likely that the LOOPs could be minimised if not eliminated altogether.
Edit
For example, you could try something like:
CREATE OR REPLACE VIEW TEST_EVENT_V
AS
  SELECT event_id
                                     FROM test_train_obj_activity toa,
                                          test_event_sessions sessions,
                                          test_learning_record lr1,
                                          test_tp_learning_activity tplearnact,
                                          test_learning_record tplr
                                    WHERE toa.activity_id = sessions.event_id
                                      AND sessions.event_session_id =
                                                     lr1.lr_catalog_history_id
                                      AND lr1.learning_record_id =
                                                  tplearnact.activity_lp_lr_id
                                      AND tplearnact.tp_lp_lr_id =
                                                       tplr.learning_record_id
                                      AND tplr.lr_catalog_history_id =
                                                                  p_strtplanid
                                      ---AND toa.is_required = 1
                                      AND toa.t_objective_id =
                                                            obj.t_objective_id
                                      AND tplr.lr_person_id = p_strpersonid
                                      AND lr1.lr_person_id = p_strpersonid
                                      AND lr1.status IN
                                             ('PASSED', 'WAIVED',
                                              'TESTED_OUT'))And then replace all the NOT INs associate with that SQL with:
AND objact.activity_id NOT IN (
SELECT event_id
   FROM TEST_EVENT_V)

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,

  • Please help with Debug procedure

    Could someone please guide me ..... I am a first timer.  I have an app that runs in Xcode and before I send it off to Apple I would like to (in an ideal world) debug it on both my 5s and my iPad.  I am sure that there is probably an easy procedure that I have to go through in order to put it on both devices but never having done it before I am a bit in the dark.  Would someone who has done this before please give me a hand.  Latest OS is on the phone and iPad and iTunes connect is on the MBP, not sure if that is key.  Many thanks

    There's not too much to say. Just change your target to your devices and build. Hopefully you won't have to do too much debugging. Have you reviewed all of the hoops necessary to submit an app? You will need video previews and screenshots. I find that once I get an app stable enough to complete this process, it is pretty much ready to go.

  • Please Help: create a procedure that needs a sys view

    Hi gurus,
    I am trying to create a stored procedure that opens a cursor for a select on a view owned by sys, but the errors says table or view does not exist. I can select * from the view (sys.mgw_gateway) from SQL*Plus or any other tool. Anyone have an idea why I get the ORA-00942: table or view does not exist error when I try to create a procedure? Here is the simple SQL statement for the procedure (I just want the users to see if the messaging gateway is running) and that's all in it.
    open p_MGWStatus for
         select AGENT_STATUS, AGENT_PING, to_char(LAST_ERROR_DATE, 'mm/dd/yyyy hh24:mi') as LastErrorDate,
         LAST_ERROR_MSG
         from sys.mgw_gateway;
    Thanks a lot.
    Ben

    Hi
    To allow the view owned by sys in a procedure, you have to grant select on that particular view to the owner of that procedure.
    Suggestion: may or may not be acceptable: create your own view in system schema (if it has the privilege to select that view else in sys schema) with the required column of the sys view and grant this newly created view to the owner of the procedure.
    Regards
    Opps! Very late reply
    Message was edited by:
    Anurag Tibrewal

  • Sql-need help very complex query

    Hi all,
    I have a big SELECT statement hen i run it,it gives ORA-22813 error.
    Ora-22813:- The Collection value from one of the inner sub queries has exceeded the system limits and hence this error.
    It would be really great if you all could please help me in re-writing the inner join SELECTS in any other way so that we can process large amout of data.
    SELECT * FROM (SELECT
    mcat.CATALOG_ITEM_ID,
    mcat.CATALOG_ITEM_NAME ,
    mcat.DESCRIPTION,
    mcat.CATALOG_ITEM_TYPE,
    mcat.DELIVERY_METHOD,
    XMLElement("TRAINING_PLAN",XMLAttributes( TP.TPLAN_ID as "id" ),
    XMLELEMENT("COMPLETE_QUANTITY", TP.COMPLETE_QUANTITY),
    XMLELEMENT("COMPLETE_UNIT", TP.COMPLETE_UNIT),
    XMLElement("TOTAL_CREDITS", TP.numberOfCredits ),
    XMLELEMENT("IS_CREDIT_BASED", TP.IS_CREDIT_BASED),
    XMLELEMENT("IS_FOR_CERT", TP.IS_FOR_CERT),
    XMLELEMENT("ACCREDIT_ORG_NAME", TP.ACCRED_ORG_NAME),
    XMLELEMENT("ACCREDIT_ORG_ID", TP.accredit_org_id ),
    XMLElement("OBJECTIVE_LIST", TP.OBJECTIVE_LIST )
    ).extract('/').getClobVal() AS PLAN_LIST
    FROM
    student_master_catalog mcat
    INNER JOIN
    (SELECT stu_tp.TPLAN_ID,
    stu_tp.COMPLETE_QUANTITY,
    stu_tp.COMPLETE_UNIT,
    stu_tp.TPLAN_XML_DATA.extract('//numberOfCredits/text()').getStringVal() as numberOfCredits,
    stu_tp.IS_CREDIT_BASED,
    stu_tp.IS_FOR_CERT,
    stu_oa.ACCRED_ORG_NAME,
    stu_tp.TPLAN_XML_DATA.extract('//accreditingOrg/text()').getStringVal() as accredit_org_id,
    objective_list.OBJECTIVE_LIST
    FROM
    student_training_catalog stu_tp
    LEFT OUTER JOIN
    stu_accrediting_org stu_oa on stu_tp.TPLAN_XML_DATA.extract('//accreditingOrg/text()').getStringVal() = stu_oa.ACCRED_ORG_ID
    INNER JOIN
    (SELECT *
    FROM
    (SELECT
    stu_tpo.TPLAN_ID AS OBJECTIVE_TPLAN_ID,
    XMLAgg(
    XMLElement("OBJECTIVE",
    XMLElement("OBJECTIVE_ID",stu_tpo.T_OBJECTIVE_ID ),
    XMLElement("OBJECTIVE_NAME",stu_to.T_OBJECTIVE_NAME ),
    XMLElement("OBJECTIVE_REQUIRED_CREDITS_OR_ACTIVITIES",stu_tpo.REQUIRED_CREDITS ),
    XMLElement("ITEM_ORDER", stu_tpo.ITEM_ORDER ),
    XMLElement("ACTIVITY_LIST", activity_list.ACTIVITY_LIST )
    ) as OBJECTIVE_LIST
    FROM
    stu_TP_OBJECTIVE stu_tpo
    INNER JOIN
    stu_TRAINING_OBJECTIVE stu_to ON stu_tpo.T_OBJECTIVE_ID = stu_to.T_OBJECTIVE_ID
    INNER JOIN
    (SELECT *
    FROM
    (SELECT stu_toa.T_OBJECTIVE_ID AS ACTIVITY_TOBJ_ID, XMLAgg(
    XMLElement("ACTIVITY",
    XMLElement("ACTIVITY_ID",stu_toa.ACTIVITY_ID ),
    XMLElement("CATALOG_ID",COALESCE(stu_c.CATALOG_ID, COALESCE( stu_e.CATALOG_ID, stu_t.CATALOG_ID ) ) ),
    XMLElement("CATALOG_ITEM_ID",COALESCE(stu_c.CATALOG_ITEM_ID, COALESCE( stu_e.CATALOG_ITEM_ID, stu_t.CATALOG_ITEM_ID ) ) ),
    XMLElement("DELIVERY_METHOD",COALESCE(stu_c.DELIVERY_METHOD, COALESCE( stu_e.DELIVERY_METHOD, stu_t.DELIVERY_METHOD ) ) ),
    XMLElement("ACTIVITY_NAME",COALESCE(stu_c.COURSE_NAME, COALESCE( stu_e.EVENT_NAME, stu_t.TEST_NAME ) ) ),
    XMLElement("ACTIVITY_TYPE",initcap( stu_toa.ACTIVITY_TYPE ) ),
    XMLElement("IS_REQUIRED",stu_toa.IS_REQUIRED ),
    XMLElement("IS_PREFERRED",stu_toa.IS_PREFERRED ),
    XMLElement("NUMBER_OF_CREDITS",stu_lac.CREDIT_HOURS),
    XMLElement("ITEM_ORDER", stu_toa.ITEM_ORDER )
    )) as ACTIVITY_LIST
    FROM stu_TRAIN_OBJ_ACTIVITY stu_toa
    LEFT OUTER JOIN
    SELECT distinct lac.LEARNING_ACTIVITY_ID, lac.CREDIT_HOURS
    FROM student_training_catalog tp
    INNER JOIN stu_TP_OBJECTIVE tpo on tp.TPLAN_ID = tpo.TPLAN_ID
    INNER JOIN stu_TRAIN_OBJ_ACTIVITY toa on tpo.T_OBJECTIVE_ID = toa.T_OBJECTIVE_ID
    INNER JOIN stu_LEARNINGACTIVITY_CREDITS lac on lac.LEARNING_ACTIVITY_ID = toa.ACTIVITY_ID and tp.TPLAN_XML_DATA.extract                  ('//accreditingOrg/text()').getStringVal() = lac.ACC_ORG_ID
    where tp.tplan_id ='************'*
    ) stu_lac ON stu_lac.LEARNING_ACTIVITY_ID = stu_toa.ACTIVITY_ID        ------>This Select returns correct no. of rows
    This below SELECT inside the LEFT OUTER JOIN is the Problem.it returns too much because 3 tables are joined directly without any value qualification.
    LEFT OUTER JOIN
    ( SELECT ch.COURSE_HISTORY_ID, stu_c.COURSE_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method
    FROM stu_COURSE stu_c
    LEFT OUTER JOIN stu_course_history ch on stu_c.course_id = ch.ch_course_id -
    If i can qualify here with ch.ch_course_id = stu_toa.ACTIVITY_ID   (stu_toa.ACTIVITY_ID from the above select with correct no.  of   rows )
    Here,i get erros because i cant access outside values inside a left outer join
    LEFT OUTER JOIN student_master_catalog mca on ch.course_history_id = mca.catalog_item_id
    ) stu_c ON stu_c.COURSE_HISTORY_ID = stu_toa.ACTIVITY_ID
    LEFT OUTER JOIN
    (SELECT stu_e.EVENT_ID, stu_e.EVENT_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_EVENTS stu_e LEFT OUTER JOIN student_master_catalog mca on stu_e.event_Id = mca.catalog_item_id ) stu_e ON stu_e.EVENT_ID = stu_toa.ACTIVITY_ID
    LEFT OUTER JOIN
    (SELECT stu_t.TEST_HISTORY_ID, stu_t.TEST_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_TEST_HISTORY stu_t LEFT OUTER JOIN student_master_catalog mca on stu_t.test_history_id = mca.catalog_item_id) stu_t ON stu_t.test_history_id = stu_toa.ACTIVITY_ID
    GROUP BY stu_toa.T_OBJECTIVE_ID) ) activity_list ON activity_list.ACTIVITY_TOBJ_ID = stu_tpo.T_OBJECTIVE_ID
    GROUP BY stu_tpo.TPLAN_ID) ) objective_list ON objective_list.OBJECTIVE_TPLAN_ID = stu_tp.TPLAN_ID
    )TP ON TP.TPLAN_ID = mcat.CATALOG_ITEM_ID
    WHERE
    mcat.CATALOG_ITEM_ID = '*****************' and mcat.CATALOG_ORG_ID = '********')
    Edited by: user10817659 on Jan 16, 2009 12:49 PM
    Edited by: user10817659 on Jan 16, 2009 12:51 PM
    Edited by: user10817659 on Jan 16, 2009 12:52 PM
    Edited by: user10817659 on Jan 16, 2009 12:54 PM

    SELECT distinct lac.LEARNING_ACTIVITY_ID, lac.CREDIT_HOURS
    FROM student_training_catalog tp
    INNER JOIN stu_TP_OBJECTIVE tpo on tp.TPLAN_ID = tpo.TPLAN_ID
    INNER JOIN stu_TRAIN_OBJ_ACTIVITY toa on tpo.T_OBJECTIVE_ID = toa.T_OBJECTIVE_ID
    INNER JOIN stu_LEARNINGACTIVITY_CREDITS lac on lac.LEARNING_ACTIVITY_ID = toa.ACTIVITY_ID and tp.TPLAN_XML_DATA.extract ('//accreditingOrg/text()').getStringVal() = lac.ACC_ORG_ID
    where tp.tplan_id ='************'*
    *) stu_lac ON stu_lac.LEARNING_ACTIVITY_ID = stu_toa.ACTIVITY_ID ------>This Select returns 117 records which is correct no. of rows*
    This below SELECT inside the LEFT OUTER JOIN is the Problem.it returns too much because 3 tables are joined directly without any value qualification.
    LEFT OUTER JOIN
    ( SELECT ch.COURSE_HISTORY_ID, stu_c.COURSE_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method
    FROM stu_COURSE stu_c
    LEFT OUTER JOIN stu_course_history ch on stu_c.course_id = ch.ch_course_id -
    If i can qualify here with ch.ch_course_id = stu_toa.ACTIVITY_ID (stu_toa.ACTIVITY_ID from the above select with correct no. of rows )
    Here,i get erros because i cant access outside values inside a left outer join
    LEFT OUTER JOIN student_master_catalog mca on ch.course_history_id = mca.catalog_item_id
    **Here this query gives me huge 22k*
    *) stu_c ON stu_c.COURSE_HISTORY_ID = stu_toa.ACTIVITY_ID--->This join queriess 117 records from top with 22k records found by the nested selected and fails processing.*
    then here above
    LEFT OUTER JOIN
    (SELECT stu_e.EVENT_ID, stu_e.EVENT_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_EVENTS stu_e LEFT OUTER JOIN student_master_catalog mca on stu_e.event_Id = mca.catalog_item_id ) stu_e ON stu_e.EVENT_ID = stu_toa.ACTIVITY_ID
    LEFT OUTER JOIN
    (SELECT stu_t.TEST_HISTORY_ID, stu_t.TEST_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_TEST_HISTORY stu_t LEFT OUTER JOIN student_master_catalog mca on stu_t.test_history_id = mca.catalog_item_id) stu_t ON stu_t.test_history_id = stu_toa.ACTIVITY_ID
    GROUP BY stu_toa.T_OBJECTIVE_ID) ) activity_list ON activity_list.ACTIVITY_TOBJ_ID = stu_tpo.T_OBJECTIVE_ID
    GROUP BY stu_tpo.TPLAN_ID) ) objective_list ON objective_list.OBJECTIVE_TPLAN_ID = stu_tp.TPLAN_ID
    )TP ON TP.TPLAN_ID = mcat.CATALOG_ITEM_ID
    WHERE
    mcat.CATALOG_ITEM_ID = '*****************' and mcat.CATALOG_ORG_ID = '********')
    We’re getting the following error:*
    ORA-22813: operand value exceeds system limits*
    Cause: Object or Collection value was too large.*
    The size of the value might have exceeded 30k in a SORT context, or the size might be too big for available memory.*

  • Can you please help me in creating a stored procedure which can create a tablesapce in a specified location ?

    Hello ...
    Can you please help me in writing a procedure which can create tablespace. like i have a requirement that
    through sql query i need to get the location of where the data file of the newly created tablespace need to be stored.
    I need to store the location of the datafiles in a variable and i need to use that variable for specifying the location of the data file in newly created data file.
    please help me writing this procedure.....
    Regards vinay raj.
    Thanks in advance..

    select distinct substr(file_name,1,instr(file_name,'/',-1)) from dba_data_files;
    Run this in a few of your databases and see how often you ONLY get one row returned.
    Normally there is no "default" file system for data files (read about the DB_CREATE_FILE_DEST parameter and Oracle Managed Files for the exception to that).
    You could pick the same file system as an existing tablespace, but even then there is no guarantee that the file system has sufficient space for the new tablespace - you have to check that OUTSIDE the database.
    Given the query at the top it is pretty simple to create a SQL script that generates a SQL script.  This can be run in any database via sqlplus, and then the generated script can be edited as needed and run immediately, under human control, avoiding surprises.
    set echo off
    set feedback off
    set heading off
    set lines 100
    spool myts.sql
    select distinct 'create tablespace MYTS DATAFILE '''||substr(file_name,1,instr(file_name,'/',-1))||'myts01.dbf'' size 40M ONLINE;' stmt
    from dba_data_files;
    spool off
    For example, if you find there are multiple filesystems to choose from, run this then delete the filesystems you don't want from the generated script.  If you find there is only one file system but it is too full, work with your SA or storage to to add space or allocate a new file system, then modify the generated script accordingly.
    This example assumes a traditional file system, on a UNIX-style OS, not using Oracle-Managed files.  ASM or RAW will have a different format for the data file location, of course.

  • A complex join . Please help

    I have a complex join to perform.
    I need some help please.
    I have a table call Table A
    TableA
    id_entity    inst_type     inst_code  dt_trade
    AGL          SE              5660249    01 Feb '06
    AGL          SE              5660249    01 Feb '06
    AGL          SE              5660249    05 Feb '06
    TableB
    id_inst                 id_inst_xref
    0029010          SE     5660249
    0070789          SE     5660249
    0071190          SE     5660249
    0072385          SE     5660249
    0073215          SE     5660249
    0084797          SE     5660249
    0091375          SE     5660249
    Table C
    id_inst     id_isin
    0029010     FR0000120172
    0070789         FR0000120172
    0071190     FR0000120172
    *** All the id_inst in TableC have the same id_isinAll the 3 Tables now have to be linked to together such that
    Output
    id_entity    Inst_code   id_isin         dt_trade    count
    AGL          5660249     FR0000120172    01 Feb '06  2
    AGL          5660249     FR0000120172    02 Feb '06  1What I am doing is
    Select ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin,count(*)
    from  TableA ta,TableB tb,TableC tc
    where ta.id_entity = 'AGL'    and
          ta.inst_code       = (How do I get the id_inst from TableB)
                                and then use the id_inst from TableB
                                to get the id_isin from TableC)
    group by ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin
    Can I say :
    Select ta.id_entity,ta.id_inst_code,ta.dt_trade,tc.id_isin,count(*)
    from  TableA ta,TableB tb,TableC tc
    where ta.id_entity = 'AGL'    and
          ta.inst_code = (Select distinct tb.id_inst
                          from tableB tb
                          where tb.id_inst_xref = ta.id_inst_code
                          ) and then link the id_inst from here to TableC ang get the id_isin??Can someone please help.??

    I had a bit of a go at writing the query but I don't quite understand the data. Here is what I tried.
    jeff@ORA10GR2> create table tablea
    2 (id_entity varchar2(3)
    3 ,inst_type varchar2(3)
    4 ,inst_code number
    5 ,dt_trade date);
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060201','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060201','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2> insert into tablea values ('AGL', 'SE', 5660249, to_date('20060205','YYYYMMDD'));
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> create table tableb
    2 (id_inst number
    3 ,inst_type varchar2(3)
    4 ,id_inst_xref number);
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tableb values (0029010, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0070789, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0071190, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0072385, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0073215, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0084797, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2> insert into tableb values (0091375, 'SE', 5660249);
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> create table tablec
    2 (id_inst number
    3 ,id_isin varchar2(20)
    4 );
    Table created.
    jeff@ORA10GR2>
    jeff@ORA10GR2> insert into tablec values (0029010, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2> insert into tablec values (0070789, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2> insert into tablec values (0071190, 'FR0000120172');
    1 row created.
    jeff@ORA10GR2>
    jeff@ORA10GR2>      select tb.id_inst_xref, tc.id_isin
    2      from tableb tb, tablec tc
    3      where tb.id_inst = tc.id_inst;
    ID_INST_XREF ID_ISIN
    5660249 FR0000120172
    5660249 FR0000120172
    5660249 FR0000120172
    jeff@ORA10GR2>
    jeff@ORA10GR2> select ta.id_entity,ta.inst_code,ta.dt_trade,dt.id_isin,count(*)
    2 from tablea ta,
    3      (select tb.id_inst_xref, tc.id_isin
    4      from tableb tb, tablec tc
    5      where tb.id_inst = tc.id_inst) dt
    6 where ta.inst_code = dt.id_inst_xref
    7 group by ta.id_entity,ta.inst_code,ta.dt_trade,dt.id_isin;
    ID_ INST_CODE DT_TRADE ID_ISIN COUNT(*)
    AGL 5660249 05/FEB/06 FR0000120172 3
    AGL 5660249 01/FEB/06 FR0000120172 6
    jeff@ORA10GR2>
    jeff@ORA10GR2> drop table tablea;
    Table dropped.
    jeff@ORA10GR2> drop table tableb;
    Table dropped.
    jeff@ORA10GR2> drop table tablec;
    Table dropped.
    jeff@ORA10GR2>
    jeff@ORA10GR2> spool off

  • Oracle8i and Oas 4081 - PLSQL TOOLKIT - Urgent Please help.

    Hi ,
    I installed Oracle 8i and Oas4081 on different ORACLE_HOME on the Linux 6.1 . When I tried to install the PLSQL toolkit it giving me an Oracle Database error 63744.
    But I am enabled the sql_trace and I found OAS is successfully connecting to Oralce8i database, but it failing for some reason.
    Do we need to do anything special on Oracle 8i side to install the PLSQL toolkit ..??
    .Please help ...
    Thanks in advance ..
    kkumar

    Is this what you're looking for?
    Usage Notes
    If the input data or key given to the DES3DECRYPT procedure is empty, then the procedure raises the error ORA-28231 "Invalid input to Obfuscation toolkit."
    If the input data given to the DES3DECRYPT procedure is not a multiple of 8 bytes, the procedure raises the error ORA-28232 "Invalid input size for Obfuscation toolkit." ORA-28233 is NOT applicable for the DES3DECRYPT function.
    If the key length is missing or is less than 8 bytes, then the procedure raises the error ORA-28234 "Key length too short." Note that if larger keys are used, extra bytes are ignored. So a 9-byte key will not generate an exception.
    C.

  • Please help! I defragged my hard drive and now Illustrator CS6 is trying to open all of my complex Illustrator files with a "Text Import Options" box as if they are text files, and they are not opening!

    Please help! Illustrator CS6 started trying to open all of my complex.ai files with a "Text Import Options" box as if they were text files, and they are not opening!  Help!

    Hi Monika,
    I have spent the last two or three days trying to do what you suggested.  I uninstalled Adobe 6 from Windows.  Some files that CS6 placed on my system during installation remained, including fonts and .dll files.
    I had to abandon the Cleaner Tool you suggested because in one screen it allowed me to specify removing CS6 only, but on the following screen it only gave on option to remove ALL Adobe programs.  I could not do that because I didn't have the serial number handy for CS3 in case I want to reinstall it at some point.
    I tried to get technical help with the Cleaner Tool problem but no definitive help was available, so I reinstalled CS6 again without having the benefit of the Cleaner Tool.  I tried to get the serial number for CS3 so I could use the Cleaner Tool but spent 2 wasted hours in chat.  Even though I had a customer number, order number, order date, place of purchase, the email address used AND 16 digits of the serial number, in two hours the agent couldn't give me the serial number.  After two hours I had nothing but instructions to wait another 20 minutes for a case number.
    Illustrator CS6 is still trying to open some backups as Text and otherNone of the problems have been fixed.  I have tried to open/use the .ai files in CS6 installed on another system and am getting the same result, so I don't think the software was damaged by the cleaner.  The hard drive cleaner is well-known and I've run it many times without any problem to previous versions of Illustrator or any other programs.
    When I ordered, the sale rep promised good technical support and gave me an 800 number, but after I paid the $2000, I learned that the 800 number she gave me doesn't support CS6 and hangs up on me.  Adobe doesn't call it a current product even though they just sold it to me about 3 weeks ago.
    Would appreciate any help you experts can offer.  If I can't solve this, the last backup I can use was from June and I will have lost HUNDREDS of hours of work and assets that I cannot replace.
    Exhausted and still desperately in need of help...

  • HT2534 when i create the apple ID with the above procedure, i dont see "none" options under credit card selection, please help.

    When i create the apple ID with the above procedure, i dont see "none" options under credit card selection, please help.

    Apple needs people like you.

  • While opening the iTune Store i receive the following error, "The procedure entry point ADAdPolicyEngine_DidEnterSation could not be located in the dynamic link library iAdCore.dll" Please help me to clear this error.

    While opening the iTune Store i receive the following error, "The procedure entry point ADAdPolicyEngine_DidEnterSation could not be located in the dynamic link library iAdCore.dll" Please help me to clear this error.

    I faced the same issue. This solved it for me: Troubleshooting issues with iTunes for Windows updates
    Hope this helps.

  • The procedure is not running no compilatin error please help

    Dear Sir,
    I have this procedure, when I am trying to execute it, it shows me busy cursor nothing happens i was trying for 6 hours nothing happening.
    I am not able to trace out what is happening
    please help
    regards
    sanat
    CREATE OR REPLACE procedure rate_Calc is
    --declare
    sdate date := to_date('01-04-2004','dd-mm-yyyy');
    edate date := sysdate;
    p_amt number;
    d_amt number;
    i_qty number;
    r_qty number;
    d_qty number;
    d_rate number;
    aa number;
    begin
    delete from avg_rate;
    commit;
    insert into avg_rate(select to_date('31-03-2004','dd-mm-yyyy'), item_mast.item_code, item_mast.curr_rate from item_mast);
    for rec1 in (select item_code from item_mast
    ) loop
    sdate := to_date('01-04-2004','dd-mm-yyyy');
    while (sdate < edate ) loop
    begin
    select nvl(sum(qty_accepted),0) into r_qty from rece_mast a, rece_det b where a.tran_no = b.tran_no and
    a.tran_date < sdate and item_code = rec1.item_code;
    exception when no_data_found then r_qty := 0;
    when others then r_qty := 0;
    end;
    begin
    select nvl(sum(issue_qty),0) into i_qty
    from issu_mast a, issu_det b where a.tran_no = b.tran_no and
    a.tran_date < sdate and item_code = rec1.item_code;
    exception when no_data_found then i_qty := 0;
    when others then i_qty := 0;
    end;
    begin
    select nvl(item_rate * (r_qty - i_qty),0) into p_amt from avg_rate
    where item_code = rec1.item_code and avg_date = sdate -1 ;
    exception when no_data_found then p_amt := 0;
    when others then p_amt := 0;
    end;
    begin
    select nvl(sum(qty_accepted * item_rate),0), nvl(SUM(qty_accepted),0) into d_amt, d_qty
    from rece_mast a, rece_det b where a.tran_no = b.tran_no and
    a.tran_date = sdate and item_code = rec1.item_code;
    exception when no_data_found then d_amt := 0;d_qty:=0;
    when others then d_amt := 0;d_qty:=0;
    end;
    begin
    d_rate := (p_amt + d_amt) / (r_qty + d_qty - i_qty);
    exception when value_error then
    d_rate := 0;
    when others then
    d_rate:=0;
    end;
    insert into avg_rate (avg_date, item_code, item_rate) values (sdate, rec1.item_code,d_rate);
    sdate := sdate +1;
    end loop;
    end loop;
    commit;
    end;
    /

    Two possibilities:
    1. Some other process is using the avg_rate table and the delete statement is having to wait until that other process is finished.
    2. There is so much to do that it will take several hours to finish. How many rows are in item_mast? Because for every row in item_mast you are inserting over 2000 rows into avg_rate. Also do rece_mast and issu_mast have an index on item_code? If not you're doing a full table scan on those tables for every row you insert into avg_rate. Do rece_det and issu_det have indexes on tran_no? If not then you're doing a full table scan on those for every row you insert.
    So if there are 1 million rows in item_mast, you're inserting 2 billion rows into avg_rate. And if this is not the first time it's been run you're also deleting 2 billion rows. That could take a lot longer than 6 hours.

  • Please help me , my iPad is writing by itself , changing applications , I can't control it , what I'm supposed to do ??? Thanks

    Please help me , my iPad is writing by itself , changing applications , I can't control it . What I'm supposed to do ???? Thanks

    Settings>General>Accessibility>turn everything off

  • Some procedure can not run,Please help

    --Please Help me where is wrong
    --The Procedure can be compiler,but can not run
    --Maybe there has some wrong with Ref Cursor or dynamic SQL
    --Please,Thanks ver much
    --Follow is my full code
    Create or Replace package ref_types
    AS
    TYPE ref_cursor is REF CURSOR;
    End;
    Create or Replace package userinfo as
    procedure Get_usermenu (baduser out boolean,
    menu out ref_types.ref_cursor
    End;
    Create or Replace package body userinfo as
    procedure Get_usermenu (baduser out boolean,
    menu out ref_types.ref_cursor
    ) is
    v_sqltext varchar2(100);
    v_sql varchar2(300);
    begin
    baduser:=FALSE;
    v_sqltext:='''A001'',''A002'',''A003''';
    v_sql:='select MENUID,P_NAME from MENU_LIST
    where MENUID in (';
    v_sql:=v_sql||v_sqltext||) order by MENUID asc';
    --explain:Get v_sqktext values overpass some process
    open menu FOR v_sql;
    end;
    end;
    /

    thanks,
    error number is : Ora-01001
    I use it In Form:
    declare
    v_baduser boolean;
    v_menu ref_types.ref_cursor;
    v_menuid number;
    v_menuname varchar2(50);
    v_menucount number;
    begin
    v_menucount:=1;
    userinfo.Get_usermenu(v_baduser,v_menu);
    loop
    fetch v_menu into v_menuid,v_menuname;
    exit when v_menu%NOTFOUND;
    show_alert_info(v_menuid||';'||v_menucount||'、'||v_menuname);
    --show_alert_info,like Developer's Function "message",
    --It can show some text
    v_menucount:=v_menucount+1;
    end loop;
    Close v_menu;
    end;

  • 11.2 iTunes update has made me unable to open iTunes. It says "The procedure entry point ADiAdID_AquireMatchSlotIfNecessary could not be located in the dynamic link library iAdCore.dll" I have done everything imaginable! Please help?!

    I deleted, reinstalled, searched, enabled, disabled--EVERYTHING and yet iTunes will not open! This is exactly why I hate updates rom Apple because they do this time and time again. I deleted multiple .dll files and nothing has worked. This is a glitch from the newest update 11.2. It says: "The procedure entry point ADiAdID_AquireMatchSlotIfNecessary could not be located in the dynamic link library iAdCore.dll" and I have no idea what the heck that means!
    If there is anybody that is having similar issues and know of what the issue might be, please help =[
    Thanks.

    Hi, Did you strip out all components, delete the named folders and reboot as in the second box of  Troubleshooting issues with iTunes for Windows updates?
    Checking on my computer here (Windows XP SP3 32 bit) I have one copy of iAdCore.dll in the main \Program Files\iTunes folder with the following properties:
    Size 3,004  KB
    Created 8th May 2014
    Modified 8th May 2014
    File Version 1.0.0.1
    Product Version 1.0.0.1
    I'll try to get a look at 64-bit system later to confirm the correct path.
    tt2

Maybe you are looking for

  • Help needed for SCCM SQL query

    Hello. I have the below query to extract the workstations build date as well as the hardware info. This works fine.  Select distinct v_R_System.Name0, v_GS_COMPUTER_SYSTEM.Manufacturer0, v_GS_COMPUTER_SYSTEM.Model0, v_GS_COMPUTER_SYSTEM_PRODUCT.Versi

  • Can i set up a spare box in my bedroom?

    Im sorry if this has been asked a million times but ive had a look at a few posts but theyre not specific. Also, im not familiar with too much tech talk. The new house had already black box (which we watch freeview on now) and a hub but obviously the

  • Odi 11g release 2 documentation

    from where can i get odi11g release 2 developer's guide. Please give me the link to downloac documents on odi11g,release 2

  • I cannot upload internet Explorer 8 or 9

    My window update is asking me to download sp1 every time of the day,whats going on with Microsoft web site has it been hacked? Please help me I' loss with this problem, Thank you

  • SOA Suite version and jDevelopr version

    Hi, Do we have to match jDeveloper version and the SOA suite version on which we are working? I mean If my server is SOA suite 10.1.3.3, then do I have a restriction that I have to use jDeveloper 10.1.3.3 or I can use jDeveloper 10.1.3.4 also it does