Oracle行转列的函数

--行转列的函数--
CREATE OR REPLACE FUNCTION Calvin(
col IN VARCHAR2,dw IN VARCHAR2)
RETURN VARCHAR2
IS
   retval varchar2(32);
   Sel_sql  varchar2(2000); ---//SQL语句声明
BEGIN
   Sel_sql:='select '||col||' from TB5001 where dwdm='''|| dw||'''';
   execute immediate Sel_sql into retval ;--执行oracle 方法
 RETURN lower(retval);
END;
/

select calvin(zdm,'ftgm') as key,wbklx from JGTB5001;

 

posted @ 2014-11-26 10:01  韩梦芫  阅读(301)  评论(0编辑  收藏  举报