当前位置:网站首页>不得不会的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;边栏推荐
- Selenium library 4.5.0 keyword explanation (III)
- I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
- Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools
- Gossip about redis source code 82
- The difference between objects and objects
- [CSDN Q & A] experience and suggestions
- [error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
- How will the complete NFT platform work in 2022? How about its core functions and online time?
- What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
- Makefile judge custom variables
猜你喜欢

The difference between objects and objects

What is the Valentine's Day gift given by the operator to the product?

From functional testing to automated testing, how did I successfully transform my salary to 15K +?
![[GNN] hard core! This paper combs the classical graph network model](/img/a7/2140744ebad9f1dc0a609254cc618e.jpg)
[GNN] hard core! This paper combs the classical graph network model
![[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)](/img/44/aa4963d07d046deb2bc76eb59f8ff7.jpg)
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)

Test the influence of influent swacth on the electromagnetic coil of quartz meter

2022 system integration project management engineer examination knowledge points: software development model

STM32 GPIO CSDN creative punch in
![[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!](/img/3f/75b3125f8779e6cf9467a30fd7eeb4.jpg)
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!

Tencent interview: can you pour water?
随机推荐
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
Several ways to set up a blog locally [attach relevant software download links]
How will the complete NFT platform work in 2022? How about its core functions and online time?
JDBC Technology
Global and Chinese markets for coronary artery disease treatment devices 2022-2028: Research Report on technology, participants, trends, market size and share
[source code] VB6 chat robot
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
MySQL is installed as a Windows Service
Is the account opening of Guoyuan securities really safe and reliable
URL (data:image/png; Base64, ivborw0k... Use case
Gossip about redis source code 83
Gossip about redis source code 81
Regular expressions and text processors for shell programming
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
What are the application fields of digital twins in industry?
NLP Chinese corpus project: large scale Chinese natural language processing corpus
1214 print diamond
挖财帮个人开的证券账户安全吗?是不是有套路
Is the securities account opened by Caicai for individuals safe? Is there a routine
Selenium library 4.5.0 keyword explanation (III)