oracle课堂笔记

1、DOS登录
1.1、sqlplus 输入用户名、密码
1.2、sqlplus /nolog

conn 用户名/密码@ip地址/数据库名称 [如果是sys登录则必须加上as sysdba ,as sysoper]
conn system/orcl@orcl
conn system/orcl@192.168.0.1/orcl
conn sys/orcl@orcl as sysdba

1.3、sqlplus system/orcl

2、创建表空间
create tablespace ts_s3sn111ts --表空间名称
datafile 'E:NFOracle6.0chapter11S3SN111s3sn111.dbf'
size 10M;

3、删除表空间
drop tablespace ts_s3sn111ts

4、创建用户指定表空间
create user s3sn111 --创建用户
identified by orcl --指定密码
default tablespace ts_s3sn111ts --指定默认表空间

5、授权
grant connect to s3sn111 --将连接数据库的权限授予用户s3sn111
grant dba to s3sn111
--drop tablespace ts_s3sn111ts --权限不足
--select * from scott.emp; --权限不足

grant resource to s3sn111 --将访问数据库资源的权限授予用户s3sn111
create table test2(Id int primary key);
insert into test(Id) values(4);
select * from test;

6、回收权限
revoke resource from s3sn111 --将用户s3sn111的资源使用权限回收
--dba最高权限

7、使用图形界面创建对象

8、创建表
--产品类型表
create table productType
(
id number(10,0) primary key not null,--主键,不为空,整数位10位
typename nvarchar2(100) not null --产品类型名称,长100个unicode字符
)

--产品表
create table products
(
id number(15,0) primary key not null,
title nvarchar2(128) not null,
typeId number(10,0) references productType(id),
price number(10,2) check(price>=0),
picture varchar(100),
addDate date default(sysdate),
memo clob
)

select sysdate from dual;

9、添加数据
9.1、单条
insert into productType(id,Typename) values(1,'数码');

insert into products
(id, title, typeid, price, memo)
values
(1, 'iphone 8s', 1, 100, '好用,便宜');

insert into products
(id, title, typeid, price,addDate,memo)
values
(2, '格力冰箱', 2, 1000,to_date('2015-01-10 23:23:23','YYYY-MM-dd HH24:MI:SS'),'好用,便宜');

SELECT to_date('2015-01-10 23:23:23','YYYY-MM-dd HH24:MI:SS') FROM DUAL

9.2、多条
insert into productType(id,Typename)
select 2,'家电' from dual union
select 3,'食品' from dual union
select 4,'服饰' from dual

select 12345 from dual; --虚表


10、查询数据
select id,Typename from productType
select id, title, typeid, price, picture, adddate from products

11、修改表
alter table products
add title nvarchar2(128) not null;

12、删除表
drop table products

原文地址:https://www.cnblogs.com/liwp/p/5084879.html