将函数值插入存储过程参数

时间:2015-08-11 23:07:43

标签: mysql sql function

我无法调用函数并使用mySQL在我的存储过程中使用函数调用中的值。我的函数提取日期值。我正在尝试使用我的存储过程调用(参数 - data_transfer_id,mode)设置参数值。这可能吗?

感谢您的帮助。我下面的代码不正确但是我的开始。函数名称为kettle_data_transfer.f_DT_last_transfer(data_transfer_id,mode)。

CREATE PROCEDURE `sproc_DT_consumer_answer_data` 
(IN data_transfer_id bigint (20),
IN `mode` varchar(25)
)
BEGIN

DECLARE last_transfer date kettle_data_transfer.f_DT_last_transfer(data_transfer_id, mode);

SELECT 
  CEQ.consumer_ID
, EM.event_mapping_ID
, F.footprint_ID
, F.create_DTM as footprint_create_DTM
, EM.event_ID
, EL.brand_ID
, RELAT.activity_type_ID
, ED.event_ID as footprint_event_ID
FROM kettle_data_transfer.Event_Mappings EM
JOIN kettle_data_transfer.Consumer_Event_Queue CEQ ON CEQ.event_ID = EM.event_ID
JOIN efn.Footprints F ON F.consumer_ID = CEQ.consumer_ID
LEFT OUTER JOIN efn.Event_Days ED on ED.event_day_ID = F.event_day_ID
LEFT OUTER JOIN efn.R_Event_Location_Activity_Type RELAT ON RELAT.r_elat_ID = F.r_elat_ID
LEFT OUTER JOIN efn.Event_Locations EL on EL.event_location_ID = RELAT.event_location_ID
LEFT OUTER JOIN kettle_data_transfer.Records RR on RR.consumer_ID = CEQ.consumer_ID
WHERE EM.active_flag = 1
AND F.sample_flag = 0
AND RR.failure_code = 0
AND RR.`ignore` = 0
and (CEQ.modify_DTM > last_transfer OR EM.create_DTM > last_transfer)
and (RR.mode = `mode` OR EM.mode =  `mode`)
and (RR.data_transfer_ID  = data_transfer_id OR EM.data_transfer_ID = data_transfer_id )
and (RR.consumer_ID = CEQ.consumer_ID)
AND (ED.event_ID = CEQ.event_ID OR ED.event_ID is null)
GROUP BY CEQ.consumer_ID, EL.brand_ID

END

1 个答案:

答案 0 :(得分:0)

存储的程序变量声明的语法:

DECLARE var_name [, var_name] ... type [DEFAULT value]

DEFAULT value并没有说"默认值就在这里。"它是关键字DEFAULT,后跟一个包含变量初始值的表达式。

您正尝试设置变量的默认初始值,但在变量名后面省略了DEFAULT关键字。

添加它可以解决问题。

https://dev.mysql.com/doc/refman/5.6/en/declare-local-variable.html