日期:2014-05-16 浏览次数:20958 次
create or replace function f_test(type_in in varchar2,startdate_in in varchar2) return int is i_num int; begin execute immediate 'select sum(total) from table where type='''||type_in|| ''' and '||startdate_in into i_num; return i_num; end;
------解决方案--------------------
type这列的值是什么?
下面这句:select sum(total) from 表 where type=type_in || startdate_in
应该是这样的吧:
select sum(total) from 表 where type=type_in and startdate_in
对吧?
------解决方案--------------------
2楼的动态SQL很好用:
CREATE OR REPLACE FUNCTION get_sql(type_in VARCHAR2,startdate_in VARCHAR2) RETURN NUMBER IS res NUMBER(10,2); BEGIN out_sql:='select sum(total) from tab where type ='||type_in||' and '|| startdate_in; EXECUTE IMMEDIATE out_sql INTO res; RETURN res; END