3410:
3411: /* ****************************************************************************
3412: * Procedure :update_tag_to_latest_tab *
3413: * Description :Update an existing the latest reading time and tag value *
3414: * for a tag if table MTH_TAG_READINGS_LATEST already *
3415: * has a entry for the tag. Otherwise, insert a new row *
3416: * File Name :MTHUTILB.PLS *
3417: * Visibility :Private *
3418: * Parameters :p_tag_code - tag code *
3419: * p_latest_reading_time - reading time of the latest *
3420: * p_latest_tag_value - latest tag reading *
3421: * p_lookup_entry_exist - whether the entry with the *
3422: * same tag code exists in the *
3423: * MTH_TAG_READINGS_LATEST or not *
3424: * Return Value :None *
3425: **************************************************************************** */
3426:
3427: PROCEDURE update_tag_to_latest_tab(p_tag_code IN VARCHAR2,
3431: IS
3432: BEGIN
3433: -- If the entry exists, do the update; otherwise, do the insert
3434: IF (p_lookup_entry_exist) THEN
3435: UPDATE MTH_TAG_READINGS_LATEST
3436: SET reading_time = p_latest_reading_time, tag_value = p_latest_tag_value
3437: WHERE tag_code = p_tag_code;
3438: ELSE
3439: INSERT INTO MTH_TAG_READINGS_LATEST
3435: UPDATE MTH_TAG_READINGS_LATEST
3436: SET reading_time = p_latest_reading_time, tag_value = p_latest_tag_value
3437: WHERE tag_code = p_tag_code;
3438: ELSE
3439: INSERT INTO MTH_TAG_READINGS_LATEST
3440: (TAG_CODE, READING_TIME, TAG_VALUE) VALUES
3441: (p_tag_code, p_latest_reading_time, p_latest_tag_value);
3442: END IF;
3443:
3571:
3572: -- Fetch the previous reading time for the given tag code
3573: CURSOR c_getPrevReadingTimeForTag (p_tag_code IN VARCHAR2) IS
3574: SELECT TAG_VALUE, READING_TIME
3575: FROM MTH_TAG_READINGS_LATEST
3576: WHERE TAG_CODE = p_tag_code;
3577:
3578: v_curr_partition NUMBER := p_curr_partition;
3579: v_curr_tag_code VARCHAR2(255) := NULL;
3638: v_prev_tag_value := NULL;
3639: v_prev_reading_time := NULL;
3640:
3641: -- 2.1.2 Find previous reading time and tag value for the currenttag
3642: -- in the lookup table MTH_TAG_READINGS_LATEST
3643: OPEN c_getPrevReadingTimeForTag(v_curr_tag_code);
3644: FETCH c_getPrevReadingTimeForTag INTO
3645: v_prev_tag_value, v_prev_reading_time;
3646: CLOSE c_getPrevReadingTimeForTag;
3706: v_last_tag_value := v_prev_tag_value;
3707: END IF;
3708: END LOOP;
3709:
3710: -- 2.6 Update/Create entry in MTH_TAG_READINGS_LATEST for the last tag
3711: -- Since we have kept the information for the last reading, just
3712: -- need to make sure that v_last_tag_code exists.
3713: IF (v_last_tag_code is not NULL) THEN
3714: update_tag_to_latest_tab(v_last_tag_code,