Oracle详细基础1

这是一个Oracle基础教程,从第一天的乱码问题开始,逐步涵盖复习回顾、插入更新删除操作、序列生成、表的操作、查询语句、内连接和子查询,最后讲解了外连接及相关代码示例。
摘要由CSDN通过智能技术生成

第一天

在这里插入图片描述

--SQL: 结构化查询语言
/*
       DDL:数据定义语言:create 创建,drop  删除 ,alter  更改
       DML:数据操作语言: insert 增,delete 删 ,update 改,select 查
       TCL:事务控制  : commit  提交  ,rollback 回滚
       DCL: 数据控制: grant 授予,revoke 回收
*/
--创建表空间,指定数据文件位置,大小内存分配,自动扩容当下一次的内存分配,这样会无限大,还可以指定最大size
create  tablespace  test07
datafile 'D:\test07.dbf'
size  10M
autoextend  on next 10M  maxsize  unlimited;

--通过表,查询表空间
select * from user_tablespaces;

--删除表空间
drop tablespace  test07;
--删除表空间,包含正在里面的内容和数据文件们
drop tablespace test07 including  contents and datafiles;

--修改表空间读写,读仅仅即可只读
--更改表空间的状态  read  only  --只读
alter tablespace test07 read write; --可读可写

--创建用户
create user test07 identified by test07
default tablespace test07;

--给新创建的用户授权
grant create session to test07;

--更改用户默认的表空间
alter user test07 default tablespace test07;
--更改用户密码
alter user test07 identified by test_07;

--删除用户
drop user test07;

### 权限和角色

--把scott用户的emp表查询权限授予给test07
grant select on scott.emp  to test07;

--把dba角色权限授予给test07
grant dba to test07;

--创建表
create table student
(
      sno  number(6) not null,
      sname varchar2(30) not null,
      sex char(3),
      age number(2),
      sjointime date  default sysdate
);

--通过用户表格表,查看用户创建的表
select * from user_tables;

--给表添加列
alter table student add (stuaddr varchar2(100),scard char(18) );
--修改列的类型
alter table student modify (stuaddr varchar2(300));
--重名名列名,把旧的列名改为新的列名
alter table student rename column stuaddr to address;

--删除列
alter table student drop  (stuaddr);
alter table student drop column stuaddr;

--查询,用户表格字段表,来查询表中的列
select * from user_tab_columns where  table_name ='STUDENT' ;

--给表添加注释
comment on table student is '学生信息表';
--给表中的列添加注释
comment on column  student.sno is '学生编号';

乱码问题

中文乱码问题解决
1.查看服务器端编码
select userenv('language') from dual
我实际查到的结果为:AMERICAN_AMERICA.ZHS16GBK
2.执行语句 
select * from V$NLS_PARAMETERS
查看第一行中PARAMETER项中为NLS_LANGUAGE 对应的VALUE项中是否和第一步得到的值一样。
如果不是,需要设置环境变量.
否则PLSQL客户端使用的编码和服务器端编码不一致,插入中文时就会出现乱码.

3.设置环境变量
计算机->属性->高级系统设置->环境变量->新建
设置变量名:NLS_LANG,变量值:第1步查到的值, 我的是	AMERICAN_AMERICA.ZHS16GBK
4.重新启动PLSQL,插入数据正常

第二天

复习回顾

create tablespace db02
datafile 'd:\db02.dbf'
size 10m
autoextend
on next 10m
maxsize unlimited

select * from user_tablespaces

create user db02 identified by db02
default tablespace db02

grant dba to db02

create table student(id number(10),name varchar2(20),birthday date);

select * from user_tables
select * from student

alter table student add dizhi varchar2(20)
alter table student modify dizhi varchar2(200)
alter table student rename column dizhi to address
select * from user_tab_columns
select * from user_tab_cols

--alter table student drop address
alter table student drop (address)
alter table student drop column birthday

--注释在什么地方,告诉我是什么内容
comment on table student is '学生表'

--中文乱码问题
select userenv('language') from dual;--AMERICAN_AMERICA.ZHS16GBK,配置环境变量名字为NLS_LANG解决
select * from V$NLS_PARAMETERS

--comment on column name is '学生姓名'--要告诉我是哪张表里面的name
comment on column student.name is '学生姓名'

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

相关代码

select  * from student;

--添加主键约束:主键列值必须唯一,并且不能为空
alter table  student  add constraint  pk_sno  primary key (sno);

--唯一约束:唯一键列值必须唯一,允许为空
alter table student add constraint uq_scard  unique (scard);

--检查约束:
alter table student add constraint ck_sex  check (sex='男&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值