1、oracle
create or replace function setstate(oldvalue varchar2, pos number, svalue varchar2)
return varchar2
isreturn_value varchar2 (20);
len number(8);
i number(8);
temp_value varchar2(1);
begin
len := length(oldvalue);
if pos > len then
return '指定的索引大於字串的長度!';
end if;
i := 0;
return_value := '';
for i in 1..len loop
temp_value := substr(oldvalue, i, 1);
if i = pos then
temp_value := svalue;
end if;
return_value := return_value || temp_value;
end loop;
return return_value;
end;
2、mssql
if exists(select * from sysobjects where name = 'setstate')
drop function setstate
gocreate function setstate(@oldvalue nvarchar(20), @pos int, @svalue nvarchar(1))
returns nvarchar(20)
asbegin
declare @return_value nvarchar(20),
@length int,
@i int,
@temp_value nvarchar(1);
set @length = len(@oldvalue);
set @i = 1;
set @return_value = '';
if(@pos > @length)
set @return_value = @oldvalue;
else
begin
while(@i <= @length)
begin
set @temp_value = substring(@oldvalue, @i, 1);
if (@i = @pos)
set @temp_value = @svalue;
set @return_value = @return_value + @temp_value;
set @i = @i + 1;
endend
return @return_value;
endgo
Oracle和MSSQL中迴圈的使用
create or replace function setstate oldvalue varchar2,pos number,svalue varchar2 return varchar2 isreturn value varchar2 20 len number 8 i number 8 te...
Oracle和Mssql儲存過程區別
儲存過程 一 多表連線查詢,更新儲存過程 sql儲存過程 alter procedure dbo getevent scswid nvarchar 20 null todate datetime,fromdate datetime as select notes.note id,notes.note...
Oracle中的迴圈
主要有以下五種迴圈 exit when loop while for 普通迴圈 for 游標迴圈 下面舉例一一說明 均為儲存過程 1 exit when迴圈 create or replace procedure proc test exit when is i number begin i 0 l...