oracle与sqlserver比较

一:Oracle与Sql Server的访问上有很大不同:
         1、字段类型不同
         2、存储过程有很大差异,Oracle不能直接返回记录集,需要通过一个 out 参数达到目的。在OracleType中有一个OracleType.Cursor 类型与之对应。 Oracle中的存储过程大部分都定义成Funcion,  有返回值。   在定义Command的参数集合时,需要增加一个"ReturnValue"的参数。
        3、Oracle中的参数无需"@"符号
        4、Oracle的Sql 语句中 在参数前面加冒号":", 而Sql Server 的Sql 在前面加"@"            
--Sql Server的Sql 语句
insert into Table (Column1,Column2) values (@Value1,@Value2


--Oracel中的Sql 语句
 Insert Into Table (Column1,Column2) values
(:Value1,:Value2)

二:存储过程例子
    1.
 1包的定义: 
 2create or replace package myTest 
 3is 
 4type out_cur is ref cursor
 5procedure writeCount(codeid in nvarchar2); 
 6procedure testSandyInSert(codeid in nvarchar2,counts out number); 
 7end myTest; 
 8
 9存储过程的定义: 
10create or replace package body myTest 
11is 
12procedure writeCount(codeid in nvarchar2) 
13is 
14m_count number
15begin m_count:=0
16select count(1into m_count from code where code_id = codeid; 
17dbms_output.put_line('输入参数是'||codeid); 
18dbms_output.put_line('查询结果是'||m_count); 
19end
20procedure testSandyInSert(codeid in nvarchar2,counts out number
21is 
22m_cur out_cur; 
23m_code_sn nvarchar2(50); 
24m_code_id nvarchar2(50); 
25m_code_name nvarchar2(50); 
26m_insertstr nvarchar2(50); 
27m_for number:=0
28begin counts:=0
29open m_cur for select code_sn,code_id,code_name from code where code_id= codeid; 
30loop fetch m_cur into m_code_sn,m_code_id,m_code_name; 
31exit when m_cur %notfound; 
32case UPPER(m_code_sn) when 'SP_CTRL_L' then m_code_sn:='0'
33when 'dld' then m_code_sn:='1'
34else m_code_sn:='3'
35end case
36if UPPER(m_code_sn) ='SP_CTRL_L' then dbms_output.put_line('条件成立执行,测试if语句的使用'); 
37else dbms_output.put_line('条件不成立执行,测试if语句的使用'); 
38end if
39m_insertstr:=''''||m_code_sn||''','''||m_code_id||''','''||m_code_name||''''
40begin execute immediate 'insert into sandytest(col1,col2,col3) values('||m_insertstr||')'
41dbms_output.put_line('插入表成功!'); 
42counts:=1
43exception when others then dbms_output.put_line('插入表失败!'); 
44end
45end loop; 
46for m_for in 1..10 loop dbms_output.put_line('循环测试:'||m_for); 
47end loop; 
48close m_cur; 
49end
50end myTest; 

posted on 2007-11-08 15:22  leup  阅读(776)  评论(1编辑  收藏  举报

导航