+ -
当前位置:首页 → 问答吧 → 如何实现用表字段值作为调用函数的输入参数值

如何实现用表字段值作为调用函数的输入参数值

时间:2010-04-29

来源:互联网

如何实现用表字段值作为调用函数的输入参数值
谢谢!

作者: new123456789   发布时间: 2010-04-29

能否具體解釋一下你的需求?不太懂你要什麽?

作者: nGX20080110   发布时间: 2010-04-29

完全可以,
SQL code
SQL> select ename from emp;

ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

已选择14行。

SQL> select substr(ename,1,2) from emp;

SUBS
----
SM
AL
WA
JO
MA
BL
CL
SC
KI
TU
AD
JA
FO
MI

已选择14行。

SQL> 

作者: tangren   发布时间: 2010-04-29

最简单的例子
select lower(dummy) from dual;
lower是函数,dummy是dual表的字段

作者: wildwave   发布时间: 2010-04-29

我的意思是我调用带多个输入参数的函数时,我想用某个表里的字段值作为输入参数的值

作者: new123456789   发布时间: 2010-04-29

declare
  time_before number;
  time_after number;
  pv varchar2(20);
  ret varchar2(20);
  pv_1 pp.id%type;
begin
select id into pv_1 from pp;
 time_before := DBMS_UTILITY.GET_TIME;
   
  ret := func1(pv_1,pv);
  time_after := DBMS_UTILITY.GET_TIME;
  dbms_output.put_line(time_after - time_before);
  dbms_output.put_line(pv);
  dbms_output.put_line(ret);
end;

我想用pp表里的id字段值给变量pv_1赋值, 函数func1结构是func1(in,out)

作者: new123456789   发布时间: 2010-04-29

我上面写的代码报错了  
高手能否指点一下

作者: new123456789   发布时间: 2010-04-29

引用 6 楼 new123456789 的回复:
我上面写的代码报错了
高手能否指点一下

pp裏面不止一條記錄吧?

作者: nGX20080110   发布时间: 2010-04-29

报错要贴出错误信息
这里应该是错在pp表里没有记录或者有多条记录
你这里控制一下,使其能取到且只能取到1个值
要不就改成游标来处理

作者: wildwave   发布时间: 2010-04-29

好多条
你的意思是缺少一个where条件是吗
不过where条件怎么写呀 我只想把pp表里的id这一列值赋值给这个变量  

作者: new123456789   发布时间: 2010-04-29

declare
  time_before number;
  time_after number;
  pv varchar2(20);
  ret varchar2(20);
  pv_1 pp.id%type;
begin
for cur in (select id from pp)loop 
 pv_1:=cur.id;
 time_before := DBMS_UTILITY.GET_TIME;
   
  ret := func1(pv_1,pv);
  time_after := DBMS_UTILITY.GET_TIME;
  dbms_output.put_line(to_char(time_after - time_before)||' '||pv||' '||ret);
end loop;
end;

作者: wildwave   发布时间: 2010-04-29

一列值赋给一个变量?是不行的,可以使用游标吧

作者: tangren   发布时间: 2010-04-29

或者使用集合类型,索引表,嵌套表,变长数组...

作者: tangren   发布时间: 2010-04-29

declare
  time_before number;
  time_after number;
  pv number;
  ret varchar2(20);
  pv_1 pp.id%type;
  pv_2 pp.name%type;
  pv_3 pp.type%type;
  
cursor cu is select * from pp;
begin
open cu;
loop
fetch cu into pv_1,pv_2,pv_3;
exit when cu%notfound;
time_before := DBMS_UTILITY.GET_TIME;
ret := func1(pv_1,pv_2,pv_3,pv);
time_after := DBMS_UTILITY.GET_TIME;
dbms_output.put_line(time_after - time_before);
dbms_output.put_line(pv);
dbms_output.put_line(ret);
end loop;
close cu;
commit;
end;


报错了 func1函数结构 funcl(in,in,in,out)

作者: new123456789   发布时间: 2010-04-29

该回复于2010-04-30 16:05:13被版主删除

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
#15楼 得分:0回复于:2011-11-12 08:23:27
同关注中 抛个问题:写个函数和触发 批量更新采购单头外币的每月汇率

作者: togogo2   发布时间: 2010-04-30