반응형
/********************************************************************************************
-- Title : [10g] 동적 쿼리 리턴 함수
-- Reference : asktom.oracle.com
-- Key word : 동적 쿼리 동적쿼리 stored function 함수
********************************************************************************************/
-- 함수 생성
create or replace function fn_query_create
( vfield in varchar2
, vtable in varchar2
, vwhere in varchar2 default null
)
return varchar2
authid current_user
as
vquery varchar2(4000);
begin
--execute immediate 'alter session set cursor_sharing=force';
vquery := 'select '||vfield||' from '||vtable;
if (vwhere is not null) then
vquery := vquery ||' where '||vwhere;
end if;
return vquery;
exception when others then
return null;
end;
-- 함수 실행
select sys.fn_query_create('empno, ename','emp2','empno=7900')
from dual;
-- Title : [10g] 동적 쿼리 리턴 함수
-- Reference : asktom.oracle.com
-- Key word : 동적 쿼리 동적쿼리 stored function 함수
********************************************************************************************/
-- 함수 생성
create or replace function fn_query_create
( vfield in varchar2
, vtable in varchar2
, vwhere in varchar2 default null
)
return varchar2
authid current_user
as
vquery varchar2(4000);
begin
--execute immediate 'alter session set cursor_sharing=force';
vquery := 'select '||vfield||' from '||vtable;
if (vwhere is not null) then
vquery := vquery ||' where '||vwhere;
end if;
return vquery;
exception when others then
return null;
end;
-- 함수 실행
select sys.fn_query_create('empno, ename','emp2','empno=7900')
from dual;
반응형