我在Teradata - SQL Assistant
但是,我无法执行它。它有5个参数,我只需要传递3个参数作为输入。
REPLACE PROCEDURE proc_store_import
(
IN P1_PROC_TYPE VARCHAR(20),
IN P2_zone_name VARCHAR(20),
IN P3_Location_code INT,
IN P4_RolloutDate VARCHAR(20),
IN P5_Phase INT
)
BEGIN
declare O1_InsertStatus VARCHAR(250);
IF P1_PROC_TYPE = 'ADD-STORE' THEN
IF( ( SELECT Count(*) FROM dim_location WHERE location_code = P3_Location_code) >0 ) THEN
SET O1_InsertStatus = 'Requested Store is already a Store...!!!';
ELSE
INSERT INTO dim_location
(location_code, location_name, store_zone, region, area, opening_date, closing_date, isactive, dc_code,
city,dc_city,location_type,catchment,emailid,circle,business_zone,cluster_name,store_cluster,ofine_code,
region,new_date,rollout_Phase,createdDate,createdBy)
SELECT location_code, store_name, zone_name, region, area, opening_date, closing_date, isactive, dc_code,
city,dc_city,location_type,catchment,emailid,circle,business_zone,cluster_name,store_cluster,ofine_code,
region,P4_RolloutDate AS new_date,P5_Phase AS rollout_Phase,CURRENT_DATE AS createdDate,1 AS createdBy
FROM dim_location
WHERE location_code = P3_Location_code;
SET O1_InsertStatus = 'Store included to Store...!!!';
END IF;
END IF;
END;
答案 0 :(得分:2)
只需为缺少的参数传递NULL:
CALL proc_store_import( 'foo', 'bar', 42 , NULL ,NULL)
您也可以将其包装在宏中(使用可选的DEFAULT),然后您可以使用命名参数:
REPLACE MACRO mac_store_import
(
P1_PROC_TYPE VARCHAR(20),
P2_zone_name VARCHAR(20),
P3_Location_code INT,
P4_RolloutDate VARCHAR(20),
-- P4_RolloutDate VARCHAR(20) DEFAULT '',
P5_Phase INT
)
AS
(
CALL proc_store_import(
:P1_PROC_TYPE,
:P2_zone_name,
:P3_Location_code,
:P4_RolloutDate,
:P5_Phase);
);
EXEC mac_store_import
( P1_PROC_TYPE = 'foo',
P3_Location_code = 42,
P2_zone_name = 'bar'
);
顺便说一下,你当前的SQL也可以直接写成宏。