oracle笔记一

一.Oracle简介

1.Oracle属于关系型数据库,是一款可以在Client/Server模式下运行的RDBMS产品。2009年,Oracle公司收购SUN。

2.Oracle是对象关系型数据库管理系统(ORDBMS)。

3.Oracle数据库的主要特点。

支持多用户,大事务量的事务处理。

支持分布式事务处理。

可移植性好。

4.由一个Oracle数据库和多个实例组成。

Oracle数据库:位于硬盘上实际存放数据的文件,这些文件组合在一起成为一个逻辑整体。

Oracle实例:位于物理内存里的数据结构,由一个共享的内存池和多个后台进程所组成。用户如果需要存取数据库里的数据,必须要通过实例才能实现。

区别:实例可以操作数据库,任何时候一个实例只能与一个数据库关联。大多数情况下,一个数据库上只有一个实例对其进行操作。

5.

sys最大,下来是system,scott权限最小。

二.sqlplus命令。

 cmd>sqlplus scott/scott@192.168.1.131:1521/orcl

 192.168.1.131:1521为服务器主机ip地址。orcl为数据库名。

 select * from tab;         查看用户下的表。

 desc student;              查看表结构。

ed      打出sql语句,便于修改语句。  改完后 /+回车执行。

修改一个单词:

create tablespace ma 

datafile 'E:aaa.DBF'

size 50M

autoextend on next 50M maxsize 2048M;                    创建表空间语法。

alter database datafile 'E:/app/Ser/oradata/orcl/java4/yxn.dbf' resize 10m                           修改表空间。

drop tablespace ma including contents and datafiles;        删除表空间。

create temporary tablespace ma_temp                            创建临时表空间。

tempfile 'E:aaa.DBF'

size 5M

autoextend on next 5M maxsize 10M;

drop tablespace yxn_temp including contents and datafiles;           删除临时表空间。

create user yxn identified by yxn                                   创建用户

default tablespace ma

temporary tablespace ma_temp;

grant connect,resource,dba to yxn;                                授权用户

grant connect to yxn;                                                    允许用户连接数据库,并创建数据库对象

grant resource to yxn;                                                   允许用户使用数据库中的存储空间

grant create sequence to yxn;                                        允许用户在当前模式下创建序列

grant select on scott.student to yxn;                              允许用户查询student表的记录

grant update on scott.student to yxn;                             允许用户修改student表的记录

grant all on scott.student to yxn;                                   允许用户增删改查student表的记录

revoke connect from yxn;                                             回收用户连接数据库的权限

revoke select on scott.student from yxn;                      收回用户查询student表的记录

alter user yxn identified by aaa;                                      修改yxn用户的密码

drop user yxn cascade;                                                   删除yxn用户

create table student(                                                       创建表
id number primary key not null,
name varchar2(20) not null,
age number null,
sex char(2) null

)

insert into student values(1,'张三',23,'男');       commit   提交  插入记录。

select * from student;                                         查看表中的数据。

show linesize          显示表宽度。

set linesize 150       设置表宽度。

spool e:aaa.txt       将spool之间的内容写到aaa.txt

spool off;

list                         查看缓冲区。

exit;                      退出用户。

col mname for a20;                修改列的宽度。                      

 三.Oracle数据类型

varchar和varchar2的区别?

存null的时候,vachar会自动转换为" ",而varchar2还是存null。

原文地址:https://www.cnblogs.com/yuxiaona/p/5864135.html