PLSQL函数有帮助

时间:2009-05-30 08:27:53

标签: sql plsql

我在下面有这个SELECT,我必须在LOOP中为从连接中获得的每个activity_id(记录)运行它。

此外,此SELECT必须在过程中的多个位置运行以获取详细信息和记录 - >我运行assign_ course或assign_test,如下所示。

任何人都可以帮我写一个可以选择的功能。

输入是strtplanid,strPersonid,p_ objective_id

FOR activity_id 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 = strtplanid
                   AND tp_obj.t_objective_id = p_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 =
                                               strtplanid
                             AND lr.lr_person_id = strPersonid
                             AND lr1.lr_person_id = 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 =
                                               strtplanid
                             --AND toa.is_required = 1
                             AND toa.t_objective_id = obj.t_objective_id
                             AND tplr.lr_person_id = strPersonid
                             AND lr1.lr_person_id = strPersonid
                             AND lr1.status IN
                                           ('PASSED', 'WAIVED', 'TESTED_OUT')))

            LOOP

               IF (activity.activity_type = 'Course')
               THEN

                   ASSIGN_COURSETP(strPersonid,activity.activity_id,strPersonid,activity.activity_type,
                  activity.IS_REQUIRED,strtplanid,v_straccreditingorg); 

                ELSif (activity.activity_type ='Test')
                THEN
                  ASSIGN_TESTTP(strPersonid,activity.activity_id,strPersonid,activity.activity_type,
                  activity.IS_REQUIRED,strtplanid,v_straccreditingorg); 

                END IF;

1 个答案:

答案 0 :(得分:2)

这需要返回任何内容吗?

为什么不能将代码包装在样板函数代码中?

CREATE OR REPLACE Function ACTIVITY_ASSIGN_TESTTP
(
  strtplanid IN number
, strPersonid IN number
, p_objective_id IN number
)
RETURN number
IS
  retVal number;
BEGIN

  -- YOUR CODE

  RETURN retVal
END ACTIVITY_ASSIGN_TESTTP;