日期:2014-05-17 浏览次数:20950 次
-- 帖个例子给你: create or replace FUNCTION fun_getemails(i_user_ids VARCHAR2, i_cdate VARCHAR2 DEFAULT TO_CHAR(SYSDATE,'D')) /*************************************************** ** 功能:根据输入的用户ID(S)及日期得到相应的用户邮箱(查询user_info表) ** 备注:工作日与非工作日区分对待:如果是工作日(周一到周五),则得到相关用户ID的workday_email字段内容; ** 如果是非工作日(周六、日)则得到相关用户ID的weekend_email字段的内容 ** 参数输入格式:'01636,00220' (表示获取用户ID为01636和00220的邮箱) ** 创建者:luoyoumou ** 创建时间:2012.05.22 ****************************************************/ RETURN varchar2 RESULT_CACHE IS l_sql VARCHAR2(1000); l_emails VARCHAR2(200); l_user_ids VARCHAR2(200); BEGIN l_user_ids := ''''||replace(i_user_ids,',',''',''')||''''; l_sql := 'SELECT LISTAGG(DECODE(:i_cdate,''1'',weekend_email,''7'',weekend_email,workday_email),'';'') WITHIN GROUP(ORDER BY userid) as emails FROM user_info '; l_sql := l_sql || 'WHERE u_status=1 ' || 'AND (userid in('||l_user_ids||')' || ' OR parent_userid in('||l_user_ids||'))'; EXECUTE IMMEDIATE l_sql INTO l_emails USING i_cdate; RETURN l_emails; EXCEPTION WHEN OTHERS THEN RETURN NULL; END;
------解决方案--------------------
考虑用数组 或者拆分传入的值
拆分值
cursor c is select * from lampalarm_his where lampid in ( select replace(regexp_substr(idstring,'[^,]+',1,level),',',' ') from dual connect by level<=length(idstring)-length(replace(idstring,',',''))+1 ) order by lampid;
我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html