Oracle sql 入门

1、创建数据库

     create database databasename

2、删除数据库

     drop database dbname

3、备份数据库

完全备份

    exp user_name/password@orcl  file=数据库存放路径 owner= user_name log=日志存放路径

导出指定的表

     exp demo/demo@orcl file=d:\backup2.dmp tables=(teachers,students)

按过滤条件,导出

     exp demo/demo@orcl file=d:\back.dmp tables=(table1) query=\" where filed1 like 'fg%'\"

     导出时可以进行压缩;命令后面 加上 compress=y

4、数据库还原

     打开cmd直接执行如下命令,不用再登陆sqlplus。

完整还原

   imp demo/demo@orcl file=d:\back.dmp full=y ignore=y log=D:\implog.txt  指定log很重要,便于分析错误进行补救。

导入指定表

     imp demo/demo@orcl file=d:\backup2.dmp tables=(teachers,students) full=y ignore=y log=D:\implog.txt

轻松解决oracle11g 空表不能exp导出的问题

oracle11g的新特性,数据条数是0时不分配segment,所以就不能被导出。

处理空表

select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0

然后将查询结果复制出来,然后执行,再exp;

Oracle数据库的SQL查询语句查询每个用户最近一次的登录记录并且只显示一条

create table oness(

      oids number(4) primary key,

      Names varchar2(10) not null,

      Email varchar2(20),

    LastLogin date

);


第一种:

select * from oness a

where not exists(select 1 from oness where Names = a.Names and LastLogin > a.LastLogin);

第二种:

select * from oness a where LastLogin=(select max(LastLogin) from oness where Names=a.Names);

双层 not exist 嵌套

参考https://blog.csdn.net/beiyetengqing/article/details/8763205 讲解非常深入

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容