在数据库中自定义了一个Function,
假设function名字是getCount通过查询语句来调用
select getCount as iCount fromDual;这个getCount是否可以同时做写数据库的操作呢?
假设function名字是getCount通过查询语句来调用
select getCount as iCount fromDual;这个getCount是否可以同时做写数据库的操作呢?
解决方案 »
- sysdba用户远程登录问题
- oracle10如何结束sql运行的语句?
- oracle逗号分隔的问题
- 那位有Oracle Installation guide for unix
- 关于表关联批量更新。
- 关于创建索引后效率未得到提升的问题
- 严重错误,为什么用where条件查询,在数据库后台进行查询,和在.net下用datagrid现出来的纪录不同
- Windows下怎么访问ORACLE 最快,ADO? ODBC? ProC??
- 在线等----表中一个字段oderflag可能取值0,1,2,如何判断符合某一条件(肯定不是一条)的记录的oderflag全不为0?
- 使用备份向导备份数据库出现问题
- 暂时没思路
- 菜鸟求教!!!
--insert into table(col_1,col_2) values(value_1,value_2)之类的cml语句--如果你的自定义函数里面没有写数据库的dml语句,那么这个自定义函数就不会做写数据库的操作
*/
Wrote file afiedt.buf 1 create or replace function test_fun
2 return varchar2
3 as
4 begin
5 insert into dept(deptno) values(55);
6 return 'T';
7* end;
scott@YPCOST> /Function created.scott@YPCOST> select test_fun from dual;
select test_fun from dual
*
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "SCOTT.TEST_FUN", line 5--看看错误提示
无法执行插入操作么?
--也可以,要使用自治事务
--不过有dml语句的还是使用存储过程吧 不要使用函数了
Wrote file afiedt.buf 1 create or replace function test_fun
2 return varchar2
3 as
4 PRAGMA AUTONOMOUS_TRANSACTION;--自治事务
5 begin
6 insert into dept(deptno) values(55);
7 commit;--提交
8 return 'T';
9* end;
scott@YPCOST> /Function created.scott@YPCOST> select test_fun from dual;TEST_FUN
--------------------------------------------------
Tscott@YPCOST> select * from dept; DEPTNO DNAME LOC
---------- -------------- -------------
55
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
谢谢啦,
现在可以Select查询Function的同时,来写数据库啦
但在命令行中调用时可以的
exec C:=fun