Oracle 数据库与 MSSQL 语言比较

Oracle MS sql
赋值 select col1 into v_name from employee select @name= name from employee
申明 Declare v_user varchar2; Declare @user varchar(200);
用现有表创建表 create table newTable as select * from oldTable; select * into newTable from oldTable
选择前N行

select *  from (select * from table order by Id) a where rownum<=N;

select top N * from table
自动增加Id



create trigger on table
before insert
for each row
is
begin
select squence.nextval into v_newId from dual;
:new.Id := v_newId;
end;

需要建立一个序列

设置一个列为自动增长即可
连接表更新

update table1 a set a.col1 = (select col2 from table2 b where a.col1= b.col2);

update a set a.col1 =b.col2
from table1 a join table2 b
on a.cola = b.colb

使用游标

declare v_name varchar2(20);
cursor myCursor is select name from employee;
begin
open myCursor;
loop
fetch myCursor into v_name;
--do somethings;
exit when myCursor%NotFound;
end loop;
close myCursor;


原文地址:https://www.cnblogs.com/king_astar/p/724376.html