SQL> set serveroutput on;
SQL> declare
2 e exception;
3 begin
4 null;
5 raise e;
6 exception when e then
7 dbms_output.put_line('error e raised');
8 end;
9 /
error e raisedPL/SQL 过程已成功完成。已用时间: 00: 00: 00.10
SQL>
SQL> declare
2 e exception;
3 begin
4 null;
5 raise e;
6 exception when e then
7 dbms_output.put_line('error e raised');
8 end;
9 /
error e raisedPL/SQL 过程已成功完成。已用时间: 00: 00: 00.10
SQL>
SQL> declare
2 e exception; --定义一个异常
3 begin
4 null; --不做任何操作
5 raise e; --手工发出异常
6 exception
when e then --异常处理
7 dbms_output.put_line('error e raised');
when others then --其它异常处理
...
8 end;
9 /
error e raisedPL/SQL 过程已成功完成。已用时间: 00: 00: 00.10
SQL>
分不是问题,我会另外开贴感谢大家的。
Create procedure P_GLBalanceWithOtherSys
@FEntityNo varchar(12),
@FYear int,
@FPeriod int
asdeclare @ret int,
@sret char(1)--跟现金系统对帐
if (select Fvalue from t_sysparam
where fentityno = @FEntityNo and FSysNo = 'Csh' and
FParamNo = 'CshStartFlag') = '1'
begin
create table #temp1 (famount decimal(18,2))
insert into #temp1
select abs(sum(a.FBeginAmountOrg)-sum(b.FBeginAmount)) +
abs(sum(a.FCreditAmountOrg)-sum(b.FCreditAmount)) +
abs(sum(a.FDebitAmountOrg)-sum(b.FDebitAmount)) +
abs(sum(a.FEndAmountOrg)-sum(b.FEndAmount))
from t_GLBal a,t_CshBal b
where a.fentityno = b.fentityno and a.FYear = b.FYear and
a.FPeriod = b.FPeriod and a.FAcctNo = b.FAcctNo and
a.FCurrency = b.FCurrency and a.FStatus = '0' and
a.fentityno = @FEntityNo
group by a.fentityno,a.FYear,a.FPeriod,a.FAcctNo,a.FCurrency if exists (select * from #temp1 where famount <> 0 )
begin
raiserror('跟现金系统对帐不平!',18,1)
return -1
end
drop table #temp1
end
对于MSSQL有大量数据的处理而又不需返回值的存储过程转换成ORACLE的过程
2、在T-SQL中,输入、输出参数定义部分在“CREATE…”和“AS”之间,前后
没有括号;而在PL/SQL中必须有“(”和“)”与其他语句隔开。
3、在T-SQL中,声明局部变量时,前面要有DECLARE关键字;
而在PL/SQL中不用DECLARE关键字。
4、在T-SQL中,参数名的第一个字符必须是“@”,并符合标识符的规定;
而在PL/SQL中,参数名除符合标识符的规定外没有特殊说明
oracle中的临时表与SQL SERVER中的有很大差异。oracle中的临时表可以理解为是数据是临时的,但表结构是在建立存储过程前就已建好了的。
if exists (select * from #temp1 where famount <> 0 )这样的语句在ORACLE中不支持,exists只能出现在where子句中。
oracle与SQL SERVER的存储过程语法差异比较大,如oracle中的if必须是
if <条件表达式> then
<PL/SQL块>
{elsif <条件表达式> then
<PL/SQL块>}
[else
<PL/SQL块>]
end if;
...
select count(*) into v_ct
from (select abs(sum(a.FBeginAmountOrg)-sum(b.FBeginAmount)) +
abs(sum(a.FCreditAmountOrg)-sum(b.FCreditAmount)) +
abs(sum(a.FDebitAmountOrg)-sum(b.FDebitAmount)) +
abs(sum(a.FEndAmountOrg)-sum(b.FEndAmount)) famount
from t_GLBal a,t_CshBal b
where a.fentityno = b.fentityno and a.FYear = b.FYear and
a.FPeriod = b.FPeriod and a.FAcctNo = b.FAcctNo and
a.FCurrency = b.FCurrency and a.FStatus = '0' and
a.fentityno = V_FEntityNo
group by a.fentityno,a.FYear,a.FPeriod,a.FAcctNo,a.FCurrency) t
where famount<>0
if v_ct<>0 then
raise_application_error(...);
end if;
...
FEntityNo in varchar2,
FYear in number,
FPeriod in number )
as ret number ;
sret char(1) ;
num char(1) ;begin
select Fvalue into num
from t_sysparam
where fentityno = FEntityNo and FSysNo = 'Csh' and FParamNo = 'CshStartFlag'
if num = '1' then
create table temp1 (famount decimal(18,2)) ;
insert into temp1
select abs(sum(a.FBeginAmountOrg)-sum(b.FBeginAmount)) +
abs(sum(a.FCreditAmountOrg)-sum(b.FCreditAmount)) +
abs(sum(a.FDebitAmountOrg)-sum(b.FDebitAmount)) +
abs(sum(a.FEndAmountOrg)-sum(b.FEndAmount))
from t_GLBal a,t_CshBal b
where a.fentityno = b.fentityno and a.FYear = b.FYear and
a.FPeriod = b.FPeriod and a.FAcctNo = b.FAcctNo and
a.FCurrency = b.FCurrency and a.FStatus = '0' and
a.fentityno = FEntityNo
group by a.fentityno,a.FYear,a.FPeriod,a.FAcctNo,a.FCurrency ;
select count(*) into num from temp1 where famount <> 0 ;
if num > 0 then
raiserror('aaaaa',18,1) ;
return -1 ;
end if ;
drop table temp1 ;
end if ;
end P_GLBalanceWithOtherSys ;
where fentityno = FEntityNo and FSysNo = 'Csh' and FParamNo = 'CshStartFlag'
后面加一个 ; 号 , 刚刚忘了 在oracle 中 sql 语句后面必须加 ; 号
在sql server中一般是隐式事务自动提交,但在oracle中缺省是需要显式提交。
在oracle中调用过程不需要加exec。
在oracle中不支持update ... from ...,也不支持delete ... from
在oracle中字符串自动转为日期所使用的格式是由参数NLS_DATE_FORMAT设定的,不如sql server那么灵活。
特别感谢bobfang(匆匆过客) 、 bzszp(SongZip) 、 leo_lesley(leo)。
我会单独开贴给你们加分。
请bobfang(匆匆过客) 、 bzszp(SongZip) 到下面的帖子取分。
http://community.csdn.net/Expert/topic/4176/4176616.xml?temp=.1996271