当前位置:网站首页>Oracle database knowledge points that cannot be learned (II)
Oracle database knowledge points that cannot be learned (II)
2022-07-04 00:41:00 【zhulin1028】
SQL Query and SQL function
1.SQl Supported commands :
Data definition language (DDL):create,alter,drop
Data manipulation language (DML):insert,delete,update,select
Data control language (DCL):grant,revoke
Transaction control language (TCL):commit,savepoint,rollback
2.Oracle data type
character , The number , date ,RAW,LOB
Character
char:1-2000 Fixed length characters of bytes
varchar2:1-4000 Variable length characters of bytes
long:2GB Variable length character of
Be careful : At most one column in a table can be long type
Long Columns cannot define unique constraints or primary key constraints
long Cannot create index on column
Procedures or stored procedures are not acceptable long Parameters of type .
Numerical type
number: Highest accuracy 38 position
Date time type
date: Accurate to ss
timestamp: The second value is accurate to the decimal point 6 position
function sysdate,systimestamp Return the current system date , Time and time zone .
Change the display of time
alter session set nls_date_language=’american’;
alter session set nls_date_format=’yyyy-mm-dd’;
Oracle Pseudo columns in , Like a table column , But it is not stored in the table , Pseudo columns can be queried , But you can't insert 、 Update and modify their values , Common pseudo columns :rowid and rownum.
rowid: The storage address of the row in the table , It can uniquely identify a row in the database , You can use this column to quickly locate rows in the table .
rownum: The query returns the sequence number of the row in the result set , You can use it to limit the number of rows returned by the query .
3. Data definition language
Commands for manipulating tables
create table
alter table
truncate table
drop table
The command to modify the table
alter table stu_table rename to stu_tbl;-- Modify the name of the table
alter table stu_tbl rename column stu_sex to sex;-- Change column names
alter table stu_tbl add (stu_age number);-- Add new column
alter table stu_tbl drop(sex);-- Delete column
alter table stu_tbl modify(stu_sex varchar2(2));-- Change the data type of the column
alter table stu_tbl add constraint pk_stu_tbl primary key(id);-- Adding constraints
4. Data manipulation language
select,update,delete,insert
Create a table from an existing table
create table stu_tbl_log as select id,stu_name,stu_age from stu_tbl;-- Select a row without repetition
select distinct stu_name from stu_tbl;-- Insert records from other tables
insert into stu_tbl_log select id,stu_name,stu_age from stu_tbl;
5. Data control language
grant,revoke
6. Transaction control language
commit,savepoint,rollback
7.SQL The operator
arithmetic operator :+-*/
Comparison operator :=,!=,<>,>,<,>=,<=,between-and,in,like,is null etc.
Logical operators :and,or,not
Set operators :union,union all,intersect,minus
Join operators :||
Example :
select (3+2)/2 from dual;-- arithmetic operator , result :2.5
select * from stu_tbl where stu_age>=20;-- Comparison operator
select * from stu_tbl where stu_name like '%a%';-- Comparison operator :like
select * from stu_tbl where stu_name like 'a___';-- Comparison operator :like
select * from stu_tbl where stu_age in(20,30);-- Comparison operator :in
select * from stu_tbl where stu_age between 20 and 30;-- Comparison operator :between
select stu_name from stu_tbl union all
select stu_name from stu_tbl_log;-- Set operators :union all
select stu_name from stu_tbl union
select stu_name from stu_tbl_log;-- Set operators :union
select stu_name from stu_tbl intersect
select stu_name from stu_tbl_log;-- Set operators :intersect
select stu_name from stu_tbl minus
select stu_name from stu_tbl_log;-- Set operators :minus
It can be seen from it that :
minus Is to get the data unique to the first table
intersect It is to obtain the data in both tables
union Is to integrate the data of two tables , All of them are displayed only once
union all It is pure data integration of two tables
select id,stu_name||' '||stu_sex as name_sex,stu_age
from stu_tbl;-- Join operators ||
8.SQL function
One line function : Only one value is returned for each row queried from the table , Can appear in select Clause ,where clause
Date function
Number function
Character functions
Conversion function :ToChar(),ToDate(),ToNumber()
Other functions :
Nvl(exp1,exp2): Expression 1 is null when , Return expression two
Nvl2(exp1,exp2,exp3): Expression 1 is null Returns expression three , Otherwise, it returns expression two
Nullif(exp1,exp2): When two expressions are equal , return null, Otherwise, return the expression one
Group function : Return based on a set of rows
Avg,Min,Max,Sum,Count
Group by,having
Analysis function
Row_number,rank,dense_rank
Example :
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;
边栏推荐
- Global and Chinese market of melting furnaces 2022-2028: Research Report on technology, participants, trends, market size and share
- Qtcharts notes (V) scatter diagram qscatterseries
- A dichotomy of Valentine's Day
- Design of database table foreign key
- Entropy and full connection layer
- Introduction to thread pool
- Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
- 不得不会的Oracle数据库知识点(四)
- MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
- [complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
猜你喜欢
A method to solve Bert long text matching
Gauss elimination method and template code
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
[PHP basics] cookie basics, application case code and attack and defense
[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)
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
Unity Shader入门精要读书笔记 第三章 Unity Shader基础
Qtcharts notes (V) scatter diagram qscatterseries
Test the influence of influent swacth on the electromagnetic coil of quartz meter
随机推荐
1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
AI Challenger 2018 text mining competition related solutions and code summary
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
[error record] configure NDK header file path in Visual Studio
STM32 GPIO CSDN creative punch in
Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
A dichotomy of Valentine's Day
2-Redis架构设计到使用场景-四种部署运行模式(下)
ITK learning notes (VII) the position of ITK rotation direction remains unchanged
The super fully automated test learning materials sorted out after a long talk with a Tencent eight year old test all night! (full of dry goods
@EnableAsync @Async
It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
What insurance products should be bought for the elderly?
How to be a professional software testing engineer? Listen to the byte five year old test
The first training of wechat applet
老姜的特点
Entropy and full connection layer
Pair