oracle 是通过先创建一个实例 再创建一个数据库 - 一个实例智只能对应一个数据库。 -- 创建数据库 create database database_name --创建数据库 --- 备份数据库 USE master EXEC sp_addumpdevice 'disk', 'testBack', 'c:/mssql7backup/MyNwind_1.dat' BACKUP DATABASE pubs TO testBack ---删除数据库 drop database database_name ---创建表 create table tableName ( col1 type [not null], col2 type [not null] ) ------根据旧的表格创建新的表格 select * into nowtableName from oldtableName create table nowbavlename as select col1,col2,col3 from oldtablename definition only <只能在oracle中使用> -----删除表格 drop table tablename ----------添加列--删除列--------------------------------- alter table tablename add column colname type alter able tablename drop column colname -----------添加主键------------------------------ alter table tablename add primary key (columnName) alter table tablename drop primary key (columnNma) -----------创建视图------------------------------------- create view viewname as select *from tablenamej 。。。。 drop view viewname -------------简单增删修查------------------------------------------ 选择:select * from table1 where 条件 插入:insert into table1(field1,field2) values(value1,value2) 删除:delete from table1 where 范围 更新:update table1 set field1=value1 where 范围 查找:select * from table1 where field1 like %value1%’---like的语法很精妙, 排序:select * from table1 order by field1,field2 [desc] 总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:select min(field1) as minvalue from table1 ------------------------------- select * from v$sql t where t.LAST_ACTIVE_TIME>(sysdate - interval '1' MINUTE) --执行1分钟内的SQL语句 -- and t.PARSING_SCHEMA_NAME = 'ORCL' --数据库 and (t.MODULE is null or t.MODULE not like '%PL/SQL%') --不是在某些终端里的执行 -- and lower(t.SQL_TEXT) like '%select%' --查询某类SQL语句 order by t.LAST_ACTIVE_TIME desc
oracle 插入数据是判断ID是否存在 存在就不插入 不存在就插入
INSERT INTO DealerInfo (OrgId, DealerOrgId,DealerName,DealerNum,DealerRemarkName,AuditState,Address,Contact,ContactPhone,AuditResult ) SELECT'1100500001','1100802082','罗浮塔测试客户3','0111','罗浮塔测试客户3','1','','FK','16890008777','审核通过' FROM dual WHERE not exists (select * from DealerInfo where DealerOrgId = '1100802082');--判断条件
--oracle 的魂环语句
declare v_num number(2) := 0; begin while v_num < 10 loop v_num := v_num + 1; dbms_output.put_line(v_num); end loop; end;
Oracle獲取前100條數據
使用關鍵字 rownum <=100