0

我正在使用需要动态 sql 查询的 apex 环境。Apex 在“经典报告(基于函数)”的帮助下提供了这个 api。我希望您注意第 8 行。当我将间距粘贴到 stackoverflow 时,我的应用会弄乱间距。现在的问题是我收到错误“ORA-01008: not all variables bound”这很有趣,因为当我将第 8 行中的 :TEAM_SELECTOR 更改为“MYSQL”(这是一个团队名称)行时此代码可以正常工作。请注意,在返回的查询中也使用 :TEAM_SELECTOR 没有问题。我也在使用 APEX 5。

    DECLARE
        v_time INT;
        v_start_time int;
        v_end_time int;
        v_rownum int := 1;
        v_max_shifts int;
        v_location INT;
        v_P4_team_selector varchar2(30) := :TEAM_SELECTOR;
BEGIN

    select extract(hour from CAST(sysdate AS TIMESTAMP)) into v_time from dual;

    select count(*) into v_max_shifts from oncall_shift
        where team = v_P4_team_selector;

    FOR i IN 0..v_max_shifts
    LOOP

            select start_time into v_start_time from (select * from oncall_shift where team =v_P4_team_selector)
        where rownum = v_rownum;
            select end_time into v_end_time from (select * from oncall_shift where team =v_P4_team_selector)
        where rownum = v_rownum;
        v_rownum := v_rownum + 1;   

        if v_time >= v_start_time and v_time <= v_end_time
        then

                select location into v_location from oncall_shift
            where team = v_P4_team_selector
            and start_time = v_start_time
            and end_time = v_end_time;

            return '
                    SELECT E.FNAME "First Name",E.LNAME "Last Name",E.OFFICE_NUM "Office Number", E.MOBILE_NUM "Mobile Number",L.NAME Location, o.position "Primary/Secondary"
                FROM EMPLOYEE E, LOCATION L, ON_CALL O
                WHERE E.ID = O.EMP_ID
                AND L.ID = O.LOC_ID
                AND O.ONCALL_DATE=TRUNC(SYSDATE)
                AND O.TEAM=:TEAM_SELECTOR
                AND L.ID = ' || v_location ||
                ' ORDER BY l.name asc
                ';  
            EXIT;

        END IF;

    END LOOP;
END;
4

1 回答 1

0

好的,所以我认为问题在于基于函数的经典报告在主机变量(TEAM_SELECTOR)能够被绑定之前执行,因此引发错误。我对此的解决方案是将其更改为基于在绑定主机变量后运行的 sql 查询的普通经典报告,因为我需要一个单独的变量我在该页面上创建了一个 P1_LOCATION 项目,使用相同的查询期望更改“v_location”到 P1_LOCATION。现在在 P1_LOCATION 页面项目中,我放置了获取位置的过程。

P1_LOCATION 代码:

    DECLARE
        v_time INT;
        v_start_time int;
        v_end_time int;
        v_rownum int := 1;
        v_max_shifts int;
        v_location INT;
        v_P4_team_selector varchar2(30) := :TEAM_SELECTOR;
BEGIN

    select extract(hour from CAST(sysdate AS TIMESTAMP)) into v_time from dual;

    select count(*) into v_max_shifts from oncall_shift
        where team = v_P4_team_selector;

    FOR i IN 0..v_max_shifts
    LOOP

            select start_time into v_start_time from (select * from oncall_shift where team =v_P4_team_selector)
        where rownum = v_rownum;
            select end_time into v_end_time from (select * from oncall_shift where team =v_P4_team_selector)
        where rownum = v_rownum;
        v_rownum := v_rownum + 1;   

        if v_time >= v_start_time and v_time <= v_end_time
        then

                select location into v_location from oncall_shift
            where team = v_P4_team_selector
            and start_time = v_start_time
            and end_time = v_end_time;

            APEX_UTIL.set_session_state('P1_LOCATION',v_location);

            EXIT;

        END IF;

    END LOOP;
END;

经典报表(sql查询):

SELECT E.FNAME "First Name",E.LNAME "Last Name",E.OFFICE_NUM "Office Number", E.MOBILE_NUM "Mobile Number",L.NAME Location, o.position "Primary/Secondary"
                FROM EMPLOYEE E, LOCATION L, ON_CALL O
                WHERE E.ID = O.EMP_ID
                AND L.ID = O.LOC_ID
                AND O.ONCALL_DATE=TRUNC(SYSDATE)
                AND O.TEAM=:TEAM_SELECTOR
                AND L.ID = :P1_LOCATION
                 ORDER BY l.name asc
于 2016-02-22T17:51:12.570 回答