Oracle 11g
APex 4.2.6.00.03
我有15个视图,每个视图持有1个月的数据。从-3个月到12个月。我设置了一个动态操作,它从LOV下拉列表中设置一个val:P_Matrix_Var给出视图名称。
下面的代码获取所有数据,但需要使用动态表名:P_Matrix_Var。但我所有回来的都是
无法解析查询,请检查查询的语法。 (ORA-00903:表名无效)。
这是可能的。
然而,如果我手动设置页面名称,它可以正常工作
SELECT DISTINCT MD.eng_id,
E."name" AS f_name,
E.surname AS l_name,
E.post_code
|| ' '
|| E.tel_number Eng_d,
R.role,
RE.shortn AS Reg,
md."1" AS "1d",
l1.matrix_data AS "1",
md."2" AS "2d",
l2.matrix_data AS "2",
md."3" AS "3d",
l3.matrix_data AS "3",
md."4" AS "4d",
l4.matrix_data AS "4",
md."5" AS "5d",
l5.matrix_data AS "5",
md."6" AS "6d",
l6.matrix_data AS "6",
md."7" AS "7d",
l7.matrix_data AS "7",
md."8" AS "8d",
l8.matrix_data AS "8",
md."9" AS "9d",
l9.matrix_data AS "9",
md."10" AS "10d",
l10.matrix_data AS "10",
md."11" AS "11d",
l11.matrix_data AS "11",
md."12" AS "12d",
l12.matrix_data AS "12",
md."13" AS "13d",
l13.matrix_data AS "13",
md."14" AS "14d",
l14.matrix_data AS "14",
md."15" AS "15d",
l15.matrix_data AS "15",
md."16" AS "16d",
l16.matrix_data AS "16",
md."17" AS "17d",
l17.matrix_data AS "17",
md."18" AS "18d",
l18.matrix_data AS "18",
md."19" AS "19d",
l19.matrix_data AS "19",
md."20" AS "20d",
l20.matrix_data AS "20",
md."21" AS "21d",
l21.matrix_data AS "21",
md."22" AS "22d",
l22.matrix_data AS "22",
md."23" AS "23d",
l23.matrix_data AS "23",
md."24" AS "24d",
l24.matrix_data AS "24",
md."25" AS "25d",
l25.matrix_data AS "25",
md."26" AS "26d",
l26.matrix_data AS "26",
md."27" AS "27d",
l27.matrix_data AS "27",
md."28" AS "28d",
l28.matrix_data AS "28",
md."29" AS "29d",
l29.matrix_data AS "29",
md."30" AS "30d",
l30.matrix_data AS "30",
md."31" AS "31d",
l31.matrix_data AS "31"
FROM :P_Matrix_Var MD
LEFT JOIN man_engineers E
ON E.eng_id = MD.eng_id
LEFT JOIN role_lookup R
ON R.role_id = md."roles"
LEFT JOIN md_region_area re
ON RE.id = MD."region"
LEFT JOIN matrix_trip_lov l1
ON l1.md_id = md."1"
LEFT JOIN matrix_trip_lov l2
ON l2.md_id = md."2"
LEFT JOIN matrix_trip_lov l3
ON l3.md_id = md."3"
LEFT JOIN matrix_trip_lov l4
ON l4.md_id = md."4"
LEFT JOIN matrix_trip_lov l5
ON l5.md_id = md."5"
LEFT JOIN matrix_trip_lov l6
ON l6.md_id = md."6"
LEFT JOIN matrix_trip_lov l7
ON l7.md_id = md."7"
LEFT JOIN matrix_trip_lov l8
ON l8.md_id = md."8"
LEFT JOIN matrix_trip_lov l9
ON l9.md_id = md."9"
LEFT JOIN matrix_trip_lov l10
ON l10.md_id = md."10"
LEFT JOIN matrix_trip_lov l11
ON l11.md_id = md."11"
LEFT JOIN matrix_trip_lov l12
ON l12.md_id = md."12"
LEFT JOIN matrix_trip_lov l13
ON l13.md_id = md."13"
LEFT JOIN matrix_trip_lov l14
ON l14.md_id = md."14"
LEFT JOIN matrix_trip_lov l15
ON l15.md_id = md."15"
LEFT JOIN matrix_trip_lov l16
ON l16.md_id = md."16"
LEFT JOIN matrix_trip_lov l17
ON l17.md_id = md."17"
LEFT JOIN matrix_trip_lov l18
ON l18.md_id = md."18"
LEFT JOIN matrix_trip_lov l19
ON l19.md_id = md."19"
LEFT JOIN matrix_trip_lov l20
ON l20.md_id = md."20"
LEFT JOIN matrix_trip_lov l21
ON l21.md_id = md."21"
LEFT JOIN matrix_trip_lov l22
ON l22.md_id = md."22"
LEFT JOIN matrix_trip_lov l23
ON l23.md_id = md."23"
LEFT JOIN matrix_trip_lov l24
ON l24.md_id = md."24"
LEFT JOIN matrix_trip_lov l25
ON l25.md_id = md."25"
LEFT JOIN matrix_trip_lov l26
ON l26.md_id = md."26"
LEFT JOIN matrix_trip_lov l27
ON l27.md_id = md."27"
LEFT JOIN matrix_trip_lov l28
ON l28.md_id = md."28"
LEFT JOIN matrix_trip_lov l29
ON l29.md_id = md."29"
LEFT JOIN matrix_trip_lov l30
ON l30.md_id = md."30"
LEFT JOIN matrix_trip_lov l31
ON l31.md_id = md."31"
WHERE E.active = 1;
答案 0 :(得分:0)
如果您尝试将其置于动态报告中,那么它就无法工作。
但是对于常规报告,您可以使用动态生成报告SQL查询的过程。
此外,我不认为oracle允许在引用的表名中使用绑定变量。
答案 1 :(得分:0)
Oracle不允许您使用绑定变量在SQL查询中动态设置表名。如果您要创建经典报告,可以将源设置为以下内容:
begin
return 'select col1, col2 etc from '||:P_Matrix_Var||' joins, where etc';
end;
如果必须是交互式报告,则不能使用PL / SQL作为源。你真的需要使用这些观点吗?如果它们没有实现,则它们不会带来性能优势,因此您也可以在查询中包含基表,并使用页面项来设置日期范围。如果它们具体化并且您想要使用它们,您可能不得不让自己有15个报告,页面编号而不是视图名称取决于页面项目。