当前位置:网站首页>Oracle, SQL Foundation
Oracle, SQL Foundation
2022-07-28 21:56:00 【Xiao Lei y】
Oracle、Sql Basics
Because use Oracle Will use SQL Statement all first look SQL sentence
1. basic SQL sentence
- Inquire about
- select * from+ Table name ( Query the data of all columns in the table )
demonstration :Select * from tb_stu - select Name , Name from + Table name ( Query the contents of a column , Be careful : Query multiple columns , Column names are separated by commas )
demonstration :select sno,sname from tb_stu - Select * from Table name where Name + Operator / Logical expression + value ( Query... According to the conditions )
demonstration :Select * from tb_stu where age>20
demonstration :Select * from tb_stu where age=20
demonstration :Select * from tb_stu where age>20 and age<30
demonstration :Select * from tb_stu where between 20 and 30 and sex=‘ male ’
- Fuzzy query
- select * from Table name where Query criteria
demonstration :select * from tb_stu where name like ‘% silly %’
- increase
- Insert multiple data at a time :
insert into Table name ( Name 1, Name 2, Name 3……)
values ( value 1, value 2, value 3.….),
( value 1, value 2, value 3.….),
( value 1, value 2, value 3.….)
demonstration :insert into Students (tid,name,sex,age)
values(1,‘ Mei Chaofeng ’,‘ Woman ’,22) - select( value 1, value 2, value 3) union,
- select( value 1, value 2, value 3),
- Delete
delete from Table name ( Delete all data in the table )
delete from Table name Where Delete the condition ( Delete data according to conditions )
demonstration :delete from tb_stu where name=‘ Zhang San ’
modify
update Table name set Field 1= value 1, Field 2= value 2 where sid=1;Create table :
create table Table name ( Field 1 data type , Field 2 data type );Delete table
drop table Table name ;
2.SQL Language introduction
2.1 SQL Language
sql(Structured Query Language) : Structured query language . It's a special programming language , Is a database query and programming language , For data access and query 、 Update and manage relational databases .
2.2 SQL The composition of language
- Structured query language includes the following 6 Parts of :
- Data query language (DQL): Also known as " Data element checking statement ". Common keywords : select, where,order by, group by #I having,
- Data operation language (DML): This statement includes verbs iinsert、update and delete. They are used to add 、 Modification and deletion .
- Transaction control language (TCL): This statement ensures that DML All rows of the table affected by the statement are updated in time . Include commit Submit ) command 、save point( Save it ) command 、rollback( Roll back ) command
- Data control language (DCL): Its sentences are passed through grant or revoke Realize the authority control , Determine the access of individual users and user groups to database objects .
- Data definition language (DDL): Its sentences include verbs cteate alert and drop. Create a new table or modify it in the database 、 Delete table (create table or droptable)
- Pointer control language (CCL): Its statement , image declare cursor, fetch into #I update where For actions that are unique to one or more forms .
3.Oracle data type
Create table time , You must specify a data type for each column
3.1 Character data type :
- char: Solid transformation , Length range :1-2000 byte ; When a fixed length string is required , all char data type ,char The alphanumeric data type stores alphanumeric values
- varchar2: variable , Length range :1-4000 byte ;VARCHAR2 The alphanumeric data type stores alphanumeric values
- long: variable : Length range :2GB;LONG Data types store variable length character data ,LONG Data types can store up to 2GB
3.2 Numerical data type .
number: Integer and non integer are number, Use number You can specify number The accuracy of , The highest accuracy is 38 position .
- Integer representation :sid number(5)/ digit
- Non integer representation :sid number(5,3);5 For integers
The total length of bits and decimal places is 5,3 Representing decimal places
The maximum length is 3, The maximum length of integer bits is :5-
3=2.
99.999
3.3 Date data type .
- date: It can be accurate to seconds , such as :1 Hours 1 branch 1 second .
- timestamp: The second value can be accurate to the decimal point 6 position , such as :1 Hours 1 branch 1.111111 second
4.Oracle Supported by SQL The operator
4.1 arithmetic operator
- Arithmetic operators are used to perform numerical calculations
- Can be in SQL Use arithmetic expressions in statements , Arithmetic expressions consist of column names of numeric data types 、 Numeric constants and arithmetic operators that connect them
- Arithmetic operators include addition (+)、 reduce (-)、 ride (*)、 except (/)
Case study
SQL> SELECT itemdesc, max_level - qty_hand avble_limit
FROM itemfile WHERE p_category='spares';
SQL > SELECT itemdesc, itemrate*(max_level - qty_hand)
FROM itemfile
WHERE p_category='spares';
4.2 Comparison operator
- The comparison operator is used to compare the values of two expressions
- The comparison operators include =、!=、<、>、<=、>=、BETWEEN…AND、IN、LIKE and IS NULL etc.
is null The role of : - effect :is null Use to determine whether a column is empty
Case study
SQL> SELECT itemdesc, re_level
FROM itemfile
WHERE qty_hand < max_level/2;
SQL> SELECT orderno FROM order_master
WHERE del_date IN (‘06-1 month -05’,‘05-2 month -05');
4.3 Logical operators
- Logical operators are used to combine the results of multiple calculation operations to generate one true or false result .
- Logical operators include and (AND)、 or (OR) He Fei (NOT).
Case study
SQL> SELECT * FROM order_master
WHERE odate > ‘10-5 month -05'
AND del_date < ‘26-5 month -05’;
-- Show 2005-5 month -10 to 2005-5 month -26 Order information for
4.4 Set operators
- The set operator combines the results of two queries into one result .
- Set operators have :union、union all;
- union: If the query results to be combined are the same , Only -
One ; - union all: Display all the query results to be composed .
--union
select 'a' from dual
union
select 'b' from dual;
--union all
select 'a' from dual
union all
select 'b' from dual;
4.5 Join operators
- Join operators are used to combine multiple strings or data values into one string
Case study
-- And merge the employee number and name into the same column , Work and salary are merged into the same column
select empno || ename Number and name ,job ||sal from emp;
5. Pseudo column
5.1 Pseudo column overview
- Pseudo column : seeing the name of a thing one thinks of its function , Disguised column , Hidden columns . Implicit existence , Can be explicitly called .
- oracle Pseudo columns in are like columns in a table , But it didn't
There are stored in the table ; - Pseudo columns can be queried from the table , But you can't insert 、 Update and delete
Divide by their values . - Common pseudo columns are rowid and rowunm.
5.2 Pseudo column -rowid.
oracle Every row of data in the database table has a unique -
Identifier , Otherwise known as rowid, stay oracle Inside usually
It is used to access data .
rowid need 10 Bytes of storage space , And use 18 Characters
To display . This value indicates that the data in this row is oracle In the database
Specific physical location of .
Show pseudo columns rowid:rowid
-- Pseudo column rowid
select a.rowid,a.* from emp a;
5.3 Pseudo column -rownum.
- stay Oracle It's executed inside insert During operation ,oracle According to insert The order of priority , take rownum Assign to each row of data , And it is fixed .
- oracle The pseudo column inside rownum and sqlserver The identification column inside is a little similar .
- Pseudo column rownum It can only act on less than and equal signs and less than and equal signs , Cannot act on the greater than sign .
- Show pseudo columns rownum、rownum
-- Pseudo column rownum
select b.*,rownum from(
select a.*,rownum from emp a
) b order by empno desc;
6. Pagination *
stay Oracle It uses pseudo columns rownum Achieve the effect of paging 
--( The first page is displayed by default , Number of pieces 5)
select b.* from (
select a.*,rownum as rid from emp a
)b where b.rid between 6 and 10;
7. False watch .
- False watch : seeing the name of a thing one thinks of its function . Camouflaged watch . Implicit existence , Sure
Explicit call . - Oracle The pseudo table in is :dual;
- Because in Oracle Inside select It must be followed by from keyword , When select and from Syntax errors will be reported when it exists alone , Pseudo table can solve this problem .
-- seek 1+1 And .
select 1+1 from dual;
select 'a'
--dual False watch
select 'abc' from dual
8. constraint .
- constraint : Primary key 、 Check 、 only 、 Non empty 、 The default value is 、 Outside
key .
create table tb_01(
sid number primary key,-- Primary key constraint
sname varchar2(10) unique,-- Unique constraint
sex varchar2(10) check(sex=' male ’ or sex=' Woman "),-- Check constraint
age number(2) check(age>=18 and age<=100) not null,-- Non empty constraint
address varchar2(10) default ' Changsha '-- Default constraint
)
边栏推荐
- 怎样巧用断言+异常处理类,使代码更简洁!(荣耀典藏版)
- How Oracle exports data (how Oracle backs up databases)
- The general strike of three factories in St France may make the shortage of chips more serious!
- openEuler Embedded SIG | 分布式软总线
- Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
- 瑞典法院取消对华为和中兴的5G频谱拍卖禁令
- 酷派主动终止针对小米公司的专利侵权诉讼
- kingbase中指定用户默认查找schema,或曰用户无法使用public schema下函数问题
- 开放式耳机哪个品牌好、性价比最高的开放式耳机排名
- Mesh data generation function meshgrid
猜你喜欢

基于多模态融合的非遗图片分类研究

Miscellaneous records of powersploit, evaluation, weevery and other tools in Kali

节省70%的显存,训练速度提高2倍!浙大&阿里提出在线卷积重新参数化OREPA,代码已开源!(CVPR 2022 )

基于知识元的外文专利文献知识描述框架

Cross domain transfer learning of professional skill word extraction in Chinese recruitment documents

入行4年,跳槽2次,我摸透了软件测试这一行~

蚂蚁集团境外站点 Seata 实践与探索

39. 组合总和

网格数据生成函数meshgrid

系统分析师
随机推荐
Openeuler embedded sig | distributed soft bus
JVM 内存布局详解(荣耀典藏版)
Meta opens the project aria pilot dataset and will develop real-time 3D maps in the future
节省70%的显存,训练速度提高2倍!浙大&阿里提出在线卷积重新参数化OREPA,代码已开源!(CVPR 2022 )
[Bluetooth Bluetooth development] VIII. Transmission layer of ble protocol
中国农业工程学会农业水土工程专业委员会-第十二届-笔记
[geek challenge 2019] secret file & file contains common pseudo protocols and gestures
Save 70% of the video memory and increase the training speed by 2 times! Zheda & Ali proposed online convolution re parameterization orepa, and the code has been open source! (CVPR 2022 )
顺序表的实现
瑞典法院取消对华为和中兴的5G频谱拍卖禁令
Professional Committee of agricultural water and soil engineering of China Association of Agricultural Engineering - 12th session - Notes
fluke dtx-1800测试精度有必要进行原厂校准吗?
Huawei releases the first electric drive system driveone: charging for 10 minutes, endurance of 200km
Standard C language learning summary 10
开放式耳机哪个音质好、公认音质好的气传导耳机推荐
Edited by vimtutor
Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
The University was abandoned for three years, the senior taught himself for seven months, and found a 12K job
I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~