我正在尝试使用绑定变量在Oracle中运行此查询。需要知道为什么会出现以下错误。我确实认为我的语法有问题,不能弄清楚它是什么?
variable start number;
variable end number;
exec :start := 1;
exec :end := 2;
select * from (
select
ob.offer_bank_id
, ob.promo_period_id
, ob.offer_bank_nm
, obst.offer_bank_status_type_dsc
, ob.effective_start_dt
, ob.effective_end_dt
, obt.offer_bank_type_dsc
, obt.offer_bank_type_cd
, pp.promo_period_nm
, SUM(CASE WHEN a.offer_id IS NOT NULL THEN 1 ELSE 0 END) as total_count
, SUM(CASE WHEN a.offer_status_type_cd = 'ED' THEN 1 ELSE 0 END) as editing_count
, SUM(CASE WHEN a.offer_status_type_cd = 'FD' THEN 1 ELSE 0 END) as failed_deactive_count
, SUM(CASE WHEN a.offer_status_type_cd in ('FP', 'FI') THEN 1 ELSE 0 END) as failed_production_co
, SUM(CASE WHEN a.offer_status_type_cd = 'FV' THEN 1 ELSE 0 END) as failed_preview_count
, SUM(CASE WHEN a.offer_status_type_cd = 'LD' THEN 1 ELSE 0 END) as loaded_count
, SUM(CASE WHEN a.offer_status_type_cd in ('PE', 'PS') THEN 1 ELSE 0 END) as pending_count
, SUM(CASE WHEN a.offer_status_type_cd = 'PK' THEN 1 ELSE 0 END) as parked_count
, SUM(CASE WHEN a.offer_status_type_cd = 'SD' THEN 1 ELSE 0 END) as successfully_deactivated_count
, SUM(CASE WHEN a.offer_status_type_cd in ('SP','PI') THEN 1 ELSE 0 END) as successfully_loaded_to_prod
, SUM(CASE WHEN a.offer_status_type_cd = 'SV' THEN 1 ELSE 0 END) as successfully_loaded_to_preview
, SUM(CASE WHEN a.offer_status_type_cd in ('LD','PE','PS') THEN 1 ELSE 0 END) as total_pending_count
, SUM(CASE WHEN a.offer_status_type_cd in ('FD','FP','FV','FR','FI') THEN 1 ELSE 0 END) as failed_count
, COUNT(1) OVER(PARTITION BY 1) as total_rows
, ROW_NUMBER() OVER (ORDER BY ob.effective_end_dt desc) as row_nbr
, MAX(a.offer_effective_end_dt) as max_offer_effective_end_dt
, MIN(a.offer_effective_start_dt) as min_offer_effective_start_dt
, SUM(CASE WHEN a.offer_status_type_cd in ('AR','SR','SD') THEN 1 ELSE 0 END) as ended_count
, SUM(CASE WHEN a.offer_status_type_cd in ('CD') THEN 1 ELSE 0 END) as copient_delay_count
, SUM(CASE WHEN a.offer_status_type_cd in ('SR') THEN 1 ELSE 0 END) as rejected_count
, SUM(CASE WHEN a.offer_status_type_cd in ('LV', 'GV', 'CD', 'GA', 'GC', 'GD', 'GI', 'GP', 'GR', 'LA', 'LI', 'LP', 'LR', 'LV', 'LE')
THEN 1 ELSE 0 END) as processing_count
, a.store_banner_cd
, a.banner_nm
from
offer_bank ob
INNER JOIN offer_bank_status obs
ON ob.offer_bank_id = obs.offer_bank_id
INNER JOIN offer_bank_status_type obst
ON obs.offer_bank_status_type_cd = obst.offer_bank_status_type_cd
INNER JOIN promo_period pp
ON ob.promo_period_id = pp.promo_period_id
INNER JOIN offer_bank_type obt
ON ob.offer_bank_type_cd = obt.offer_bank_type_cd
LEFT OUTER JOIN
(select
o.offer_id
, o.offer_bank_id
, sb.store_banner_cd
, sb.banner_nm
, ost.offer_status_type_cd
, o.offer_effective_end_dt
, o.offer_effective_start_dt
from
offer o
INNER JOIN offer_store_banner osb
ON o.offer_id = osb.offer_id
INNER JOIN store_banner sb
ON osb.store_banner_cd = sb.store_banner_cd
INNER JOIN offer_status os
ON o.offer_id = os.offer_id
INNER JOIN offer_status_type ost
ON os.offer_status_type_cd = ost.offer_status_type_cd
AND os.effective_end_dt is null
) a
ON ob.offer_bank_id = a.offer_bank_id
where
obs.effective_end_dt is null
group by
ob.offer_bank_id
, ob.promo_period_id
, ob.offer_bank_nm
, obst.offer_bank_status_type_dsc
, ob.effective_start_dt
, ob.effective_end_dt
, obt.offer_bank_type_dsc
, obt.offer_bank_type_cd
, pp.promo_period_nm,
a.store_banner_cd,
a.banner_nm
order by
ob.effective_end_dt desc
) a
where
a.row_nbr > start;
我的错误说明了这一点:
Error report:
SQL Error: ORA-01745: invalid host/bind variable name
01745. 00000 - "invalid host/bind variable name"
对此有所帮助。我是绑定变量的新手 提前致谢
答案 0 :(得分:3)
START
和END
是保留字。
SQL> variable start number;
SQL> exec :start := 1;
PL/SQL procedure successfully completed.
SQL> select :start from dual;
select :start from dual
*
ERROR at line 1:
ORA-01745: invalid host/bind variable name
使用其他名称,并记住使用:
引用SQL中的绑定变量:
SQL> variable asdf number;
SQL> exec :asdf := 1;
PL/SQL procedure successfully completed.
SQL> select :asdf from dual;
:ASDF
----------
1
将来,您可能希望最小化代码示例。问题相对简单,但是巨大的代码块隐藏了它。