当前位置:网站首页>不得不会的Oracle数据库知识点(二)
不得不会的Oracle数据库知识点(二)
2022-07-04 00:33:00 【zhulin1028】
SQL查询和SQL函数
1.SQl支持的命令:
数据定义语言(DDL):create,alter,drop
数据操纵语言(DML):insert,delete,update,select
数据控制语言(DCL):grant,revoke
事务控制语言(TCL):commit,savepoint,rollback
2.Oracle数据类型
字符,数值,日期,RAW,LOB
字符型
char:1-2000字节的定长字符
varchar2:1-4000字节的变长字符
long:2GB的变长字符
注意:一个表中最多可有一列为long型
Long列不能定义唯一约束或主键约束
long列上不能创建索引
过程或存储过程不能接受long类型的参数。
数值型
number:最高精度38位
日期时间型
date:精确到ss
timestamp:秒值精确到小数点后6位
函数sysdate,systimestamp返回系统当前日期,时间和时区。
更改时间的显示
alter session set nls_date_language=’american’;
alter session set nls_date_format=’yyyy-mm-dd’;
Oracle中的伪列,像一个表列,但没有存储在表中,伪列可以查询,但不能插入、更新和修改它们的值,常用的伪列:rowid和rownum。
rowid:表中行的存储地址,可唯一标示数据库中的某一行,可以使用该列快速定位表中的行。
rownum:查询返回结果集中的行的序号,可以使用它来限制查询返回的行数。
3.数据定义语言
用于操作表的命令
create table
alter table
truncate table
drop table
修改表的命令
alter table stu_table rename to stu_tbl;--修改表名
alter table stu_tbl rename column stu_sex to sex;--修改列名
alter table stu_tbl add (stu_age number);--添加新列
alter table stu_tbl drop(sex);--删除列
alter table stu_tbl modify(stu_sex varchar2(2));--更改列的数据类型
alter table stu_tbl add constraint pk_stu_tbl primary key(id);--添加约束
4.数据操纵语言
select,update,delete,insert
利用现有的表创建表
create table stu_tbl_log as select id,stu_name,stu_age from stu_tbl;--选择无重复的行
select distinct stu_name from stu_tbl;--插入来自其他表中的记录
insert into stu_tbl_log select id,stu_name,stu_age from stu_tbl;
5.数据控制语言
grant,revoke
6.事务控制语言
commit,savepoint,rollback
7.SQL操作符
算术操作符:+-*/
比较操作符:=,!=,<>,>,<,>=,<=,between-and,in,like,is null等
逻辑操作符:and,or,not
集合操作符:union,union all,intersect,minus
连接操作符:||
示例:
select (3+2)/2 from dual;--算术操作符,结果:2.5
select * from stu_tbl where stu_age>=20;--比较操作符
select * from stu_tbl where stu_name like '%a%';--比较操作符:like
select * from stu_tbl where stu_name like 'a___';--比较操作符:like
select * from stu_tbl where stu_age in(20,30);--比较操作符:in
select * from stu_tbl where stu_age between 20 and 30;--比较操作符:between
select stu_name from stu_tbl union all
select stu_name from stu_tbl_log;--集合操作符:union all
select stu_name from stu_tbl union
select stu_name from stu_tbl_log;--集合操作符:union
select stu_name from stu_tbl intersect
select stu_name from stu_tbl_log;--集合操作符:intersect
select stu_name from stu_tbl minus
select stu_name from stu_tbl_log;--集合操作符:minus
从中可以看出:
minus是获取第一张表独有的数据
intersect是获取两张表中都有的数据
union是整合两张表的数据,都有的只显示一次
union all是纯粹的两张表数据整合
select id,stu_name||' '||stu_sex as name_sex,stu_age
from stu_tbl;--连接操作符||
8.SQL函数
单行函数:从表中查询的每一行只返回一个值,可出现在select子句,where子句中
日期函数
数字函数
字符函数
转换函数:ToChar(),ToDate(),ToNumber()
其他函数:
Nvl(exp1,exp2):表达式一为null时,返回表达式二
Nvl2(exp1,exp2,exp3):表达式一为null时返回表达式三,否则返回表达式二
Nullif(exp1,exp2):两表达式相等时,返回null,否则返回表达式一
分组函数:基于一组行来返回
Avg,Min,Max,Sum,Count
Group by,having
分析函数
Row_number,rank,dense_rank
示例:
select u.user_name,sum(oi.order_num*oi.order_price) as total,row_number() over (order by sum(oi.order_num*oi.order_price) desc) as sort from order_item_tbl
oi,user_tbl u,order_tbl o where oi.order_id = o.id and o.user_id = u.id group by u.user_name;
边栏推荐
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Shell script three swordsman sed
- Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
- Sorry, Tencent I also refused
- MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
- [CSDN Q & A] experience and suggestions
- (Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
- P1629 postman delivering letter
- It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
- Smart fan system based on stm32f407
猜你喜欢
STM32 GPIO CSDN creative punch in
It is forbidden to splice SQL in code
BBS forum recommendation
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
NLP Chinese corpus project: large scale Chinese natural language processing corpus
2022 system integration project management engineer examination knowledge points: software development model
From functional testing to automated testing, how did I successfully transform my salary to 15K +?
Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
Sorry, Tencent I also refused
随机推荐
Idea set class header comments
Docking Alipay process [pay in person, QR code Payment]
Iclr2022: how does AI recognize "things I haven't seen"?
ISBN number
[leetcode] interview question 17.08 Circus tower
For loop
Gossip about redis source code 80
Selenium library 4.5.0 keyword explanation (II)
HR disgusted interview behavior
Makefile judge custom variables
Entropy and full connection layer
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
Generic tips
Social network analysis -social network analysis
P3371 [template] single source shortest path (weakened version)
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
Anomalies seen during the interview
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Briefly understand the operation mode of developing NFT platform
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders