我有一段看似无害的代码,如下所示。
CREATE TYPE rec_type AS object (
storename VARCHAR2(50),
storecode VARCHAR2(50),
--enters number,
--exits number,
log_ts DATE,
opentime VARCHAR2(50),
closetime VARCHAR2(50),
ttotals VARCHAR2(50) );
/
CREATE TYPE t_tab
IS TABLE OF rec_type;
/
CREATE OR replace PROCEDURE Dx_proc_dly_charmingcharlie (
p_ce_id IN NUMBER,
p_strt_dt IN DATE,
p_end_dt IN DATE,
p_date_format IN VARCHAR2 DEFAULT 'mm/dd/yy',
p_time_format IN VARCHAR2 DEFAULT 'hh24miss',
p_store_format IN NUMBER DEFAULT 1,
p_file_sep IN VARCHAR2 DEFAULT ',',
p_total_type IN VARCHAR2 DEFAULT 'B',
p_act_imp_ind_reqd IN VARCHAR2 DEFAULT 'N')
AS
ltotals VARCHAR2(100);
lstr VARCHAR(500);
--type t_tab is table of rec_type;
tt_tab t_tab := T_tab();
CURSOR cce IS
SELECT ce_id,
url_adr user_store_code
FROM tce
WHERE ce_id = p_ce_id
AND hist_ctrl = 0
AND cmpl_ind = 'Y'
AND end_ind = 'N'
AND ce_fnct_typ_id IN ( 1, 2, 6 )
UNION
SELECT a.ce_id,
a.url_adr user_store_code
FROM tce a,
tce_rlt b
WHERE b.ce_prn_id = p_ce_id
AND b.ce_dpn_id = a.ce_id
AND b.hist_ctrl = 0
AND a.hist_ctrl = 0
AND a.cmpl_ind = 'Y'
AND a.end_ind = 'N'
AND a.ce_fnct_typ_id IN ( 1, 2, 6 )
AND b.cmpl_ind = 'Y'
AND b.end_ind = 'N';
CURSOR ctrf(
p_ce_id NUMBER) IS
SELECT a.url_adr StoreName,
Rfg_get_cust_id_gen(a.url_adr) Storecode,
SUM(b.total_enters) enters,
SUM(b.total_exits) exits,
b.log_ts log_ts,
To_char(b.day_strt_ts, 'hh24:mi') opentime,
To_char(b.day_end_ts, 'hh24:mi') closetime
FROM tce a,
mv_tmp_daily_traffic b,
v_ce_tmp c
WHERE c.ce_id = a.ce_id
AND b.tmp_id = c.tmp_id
AND a.ce_id = p_ce_id
AND b.log_ts >= p_strt_dt
AND b.log_ts <= p_end_dt
GROUP BY a.url_adr,
Rfg_get_cust_id_gen(a.url_adr),
To_char(b.log_ts, 'YYYY/MM/DD'),
b.log_ts,
To_char(b.day_strt_ts, 'hh24:mi'),
To_char(b.day_end_ts, 'hh24:mi')
ORDER BY 1,
2,
5;
BEGIN
FOR c IN cce LOOP
FOR t IN ctrf(c.ce_id) LOOP
lTotals := CASE p_total_type
WHEN 'B' THEN To_char(t.enters)
|| ','
|| To_char(t.exits)
WHEN 'E' THEN To_char(t.enters)
ELSE To_char(t.exits)
END;
tt_tab.extend;
Tt_tab(tt_tab.last) :=
Rec_type(t.storename, t.storecode, t.log_ts, t.opentime, t.closetime, lTotals);
lStr := CASE p_total_type
WHEN 'B' THEN
'Store ID|Store Name|Date|Open Time|Close Time|Traffic In|Traffic Out'
WHEN 'E' THEN
'Store ID|Store Name|Date|Open Time|Close Time|Traffic In'
ELSE 'Store ID|Store Name|Date|Open Time|Close Time|Traffic Out'
END;
dbms_output.Put_line(lStr);
--dbms_output.put_line(t.Storecode||p_file_sep||t.StoreName||p_file_sep||to_char(t.log_ts,p_date_format)||p_file_sep||t.opentime||p_file_sep||t.closetime||lTotals);
END LOOP;
END LOOP;
FOR rec IN 1..tt_tab.count LOOP
dbms_output.Put_line(Tt_tab(rec).Storecode
||p_file_sep
||Tt_tab(rec).StoreName
||p_file_sep
|| Tt_tab(rec).log_ts
||p_file_sep
||Tt_tab(rec).opentime
||p_file_sep
||Tt_tab(rec).closetime
||p_file_sep
|| Tt_tab(rec).lTotals);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
Raise_application_error(-20001, Substr(SQLERRM, 1, 100));
END;
/
这是错误
84/206 PLS-00302: component 'LTOTALS' must be declared
84/2 PL/SQL: Statement ignored
虽然我已将变量“LTOTALS”声明为全局..请帮忙。
答案 0 :(得分:3)
我在你的代码中看到了这一点:
tt_tab(rec).lTotals
但记录类型lTotals
中没有属性rec_type
,只有tTotals
。