CREATE OR REPLACE FUNCTION make_primarykey(tableName in varchar2) RETURN integer is
num integer;
BEGIN
if not exists(select * from sys_manage_primarykey where upper(table_name)=upper(tableName)) then
insert into sys_manage_primarykey(table_name,current_key) values(tableName,1);
return 1;
end if;
update sys_manage_primarykey set num=current_key + 1,current_key = current_key + 1 where upper(table_name)=upper(tableName) ;
RETURN num;
END make_primarykey;
本人新手,仿MSSQL写的上面这个函数的问题,但不知错在哪儿,望Oracle高手帮一下忙,
顺便问一个问题,Oracle中自定义函数不能作为默认值吗?我测试是不行的.
------解决方案--------------------
CREATE OR REPLACE FUNCTION make_primarykey(tableName in varchar2) RETURN integer is
num integer;
BEGIN
update sys_manage_primarykey t set
t.current_key = t.current_key + 1 where table_name=tableName
returning t.current_key+1 into num;
if sql%notfound then
insert into sys_manage_primarykey(table_name,current_key) values(tableName,1);
num:=1;
end if;
return num;
END make_primarykey;