我正在使用一个我需要动态SQL查询的顶级环境。 Apex在"经典报告(基于功能)"的帮助下提供此api。我希望你把注意力吸引到第8行。当我将它粘贴到stackoverflow中时,我的appoligies间距变得混乱。现在问题是我收到错误' ORA-01008:并非所有变量都绑定了#39;这很有趣,因为当我将第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;
答案 0 :(得分:0)
好的,所以我认为问题是基于函数的经典报告在主变量(TEAM_SELECTOR)能够被绑定之前执行,因此抛出错误。我的解决方案是将其更改为基于sql查询的正常经典报告,该查询在绑定主变量后运行,因为我需要一个单独的变量,我在该页面上使用相同的查询期望更改“v_location”创建一个P1_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