如何在select语句中传递参数时使用动态值。
我有一个像下面这样的功能....
create or replace function get_old_GSL (p_vendor_site_id in varchar2) return varchar2
is
v_sup_gsl VARCHAR2(30);
v_ret_val VARCHAR2(30);
BEGIN
BEGIN
SELECT SUBSTR(ATTRIBUTE52,1,6)
INTO v_sup_gsl
FROM gecm_dff_ext
WHERE primary_table ='AP_SUPPLIER_SITES_ALL'
AND primary_key = p_vendor_site_id
and attribute52 is not null;
EXCEPTION
WHEN OTHERS THEN
v_sup_gsl := NULL;
END;
BEGIN
IF v_sup_gsl IS NOT NULL THEN
SELECT segment1
INTO v_ret_val
FROM ap_suppliers
WHERE segment1 = v_sup_gsl;
END IF;
EXCEPTION
WHEN OTHERS THEN
v_ret_val := NULL;
END;
return(v_ret_val);
END;
测试功能:
---------------------
--> select GET_OLD_GSL(22758460) as xyz from dual;
--> select GET_OLD_GSL(22758529) as xyz from dual;
--> select GET_OLD_GSL(22760317) as xyz from dual;
--> select GET_OLD_GSL(22758389) as xyz from dual;
--> select GET_OLD_GSL(22759519) as xyz from dual;
此处,iam使用“vendor_site_id
”表格的“ap_supplier_sites_all
”列。
我的要求是动态传递此参数,而不是每次通过时都对参数进行硬编码。