当前位置:网站首页>Oracle-数据库对象的使用
Oracle-数据库对象的使用
2022-07-01 13:49:00 【旷世奇才李先生】
工欲善其事必先利其器
文章持续更新,可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。
一、序列
序列可以使用在数据库表的自动增长列中来用,假如我们的学生表的id想从1开始,然后自动增长,每次增加2,也就是学生id是1、3、5、7、9这种的,我们就可以配合序列来使用
序列有以下属性
sequence_name:序列名称
min_value:当前序列的最小值
max_value:当前序列的最大值
increment_by:每次序列增长的步长
cy:是否为循环序列
or:是否需要排序
cache_size:缓存个数,默认为20个
last_number:最后的数值
nextval:取得序列下一个内容,每调用一次序列的值都会增长
currval:表示取得序列的当前内容,每一次调用序列不会增长
1、创建一个序列
create sequence myseq;
2、向学生表插入一条数据,学生id使用myseq序列
insert into student(id,name) values (myseq.nextval;'张三');
3、改变myseq序列的步长,每步增加2
create sequence myseq increment by 2;
4、改变myseq序列的开始值为10000
create sequence myseq increment by 2 start with 10000;
5、创建一个循环序列,并且不使用缓存
如果我们希望某一列的数据只是1到9的数据,那么我们可以使用循环序列来操作
create sequence myseq
minvalue 1 maxvalue 9
cycle nocache;
二、同义词的作用
同义词可以将一个模式的表给另一个模式来访问。
1、将scott用户下的student表同义给sys用户使用
create sysnoym student for scott.emp;
2、将scott用户下的student表同义给所有用户使用
create public sysnoym student for scott.emp;
三、视图的定义及使用
视图是为了简化复杂查询的,视图是一张虚拟表,并不存储数据,但是数据都来源于真实表中
1、创建一个视图,从学生表中名字为‘张三’的学生中取
create view studentview as select * from student where name = '张三';
2、查询学生视图
select * from studentview;
3、更新学生视图,将name为‘张三’的年龄更新为20
update studentview set age = 20 where name = '张三';
这个时候我们发现真实表student中张三的年龄也被修改了,所以这样修改视图会影响真实表的数据,那么我们接下来创建一个视图让他修改后不影响真实表。
4、创建一个视图,从学生表中名字为‘张三’的学生中取,并且修改视图不能影响原来真实表的数据
create or replace view studentview as
select * from student where name = '张三'
with check option;
5、创建一个视图,从学生表中名字为‘张三’的学生中取,并且视图设置为只读
create or replace view studentview as
select * from student where name = '张三'
with read only;
四、索引的定义及使用
1、创建一个学生表,并给name建立索引
create index name_index on student (name);
五、总结
这里的相关内容还没有整理完毕,文章后面持续更新,建议收藏。
文章中涉及到的命令大家一定要像我一样每个都敲几遍,只有在敲的过程中才能发现自己对命令是否真正的掌握了。
可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。
边栏推荐
- Solution to 0xc000007b error when running the game [easy to understand]
- JVM有哪些类加载机制?
- App自动化测试开元平台Appium-runner
- AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
- spark源码阅读总纲
- [Jianzhi offer] 55 - ii balanced binary tree
- 网络中的listen
- Summary of interview questions (1) HTTPS man in the middle attack, the principle of concurrenthashmap, serialVersionUID constant, redis single thread,
- Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
- 奔涌而来的数字化浪潮,将怎样颠覆未来?
猜你喜欢
开源者的自我修养|为 ShardingSphere 贡献了千万行代码的程序员,后来当了 CEO
French Data Protection Agency: using Google Analytics or violating gdpr
使用CMD修复和恢复病毒感染文件
[anwangbei 2021] Rev WP
App automation testing Kaiyuan platform appium runner
Interpretation of R & D effectiveness measurement framework
Six years of technology iteration, challenges and exploration of Alibaba's globalization and compliance
SAP 智能机器人流程自动化(iRPA)解决方案分享
What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
【NLP】预训练模型——GPT1
随机推荐
运行游戏时出现0xc000007b错误的解决方法[通俗易懂]
3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
【修复版】仿我爱看电影网站模板/海洋CMS影视系统模板
Learning to use livedata and ViewModel will make it easier for you to write business
This paper introduces an implementation scheme to enhance the favorite transaction code management tool in SAP GUI
C语言订餐管理系统
【剑指Offer】54. 二叉搜索树的第k大节点
Detailed explanation of leetcode reconstruction binary tree [easy to understand]
Listen in the network
我们该如何保护自己的密码?
“国防七子”经费暴增,清华足足362亿元,甩第二名101亿 |全国高校2022预算大公开...
[Jianzhi offer] 54 The k-th node of binary search tree
玩转gRPC—不同编程语言间通信
Benefiting from the Internet, the scientific and technological performance of overseas exchange volume has returned to high growth
Liu Dui (fire line safety) - risk discovery in cloudy environment
2022年PMP项目管理考试敏捷知识点(6)
Use lambda function URL + cloudfront to realize S3 image back to source
QT学习管理系统
玩转MongoDB—搭建MongoDB集群
[flask] flask starts and implements a minimal application based on flask