当前位置:网站首页>Oracle insert data
Oracle insert data
2022-07-29 04:27:00 【zhiyou-rookie】
Oracle insert data
seeing the name of a thing one thinks of its function ,INSERT Used to insert ( add rows ).
The insert operation can be used in many ways :
- Insert a single complete line ;
- Insert a single partial line ;
- Insert multiple rows ;
- Insert the result of the query .
Tips :insert And system security
have access to Oracle Security is disabled on a per table or per user basis INSERT sentence .
1.1 Insert full row
Syntax example :
INSERT INTO Customers
VALUES(10006,
'Pep E. LaPew',
'100 Main Street',
'Los Angeles',
'CA',
'90046',
'USA',
NULL,
NULL);
Be careful : There is no output
INSERT Statements usually do not produce any output , But if Oracle SQL Developer Execute the above statement in , You should see “1 row inserted.” news .
stay VALUES Clause specifies the data to be stored in each table column , And you must provide a value for each column . If the column is not worth , You should use NULL value ( Assume that the table allows no value to be specified for this column ). Columns must be filled in the order in the table definition . Writing depends on a particular order SQL Statement is very unsafe .
More secure ( Unfortunately, it is also more troublesome ) The way of writing is as follows INSERT sentence :
INSERT INTO customers(cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
)
VALUES(10006,
'Pep E. LaPew',
'100 Main Street',
'Los Angeles',
'CA',
'90046',
'USA'
);
Tips : Automatic primary key
Every time a row is added , There is no need to manually assign unique values ( There is no need to record what value was last used ), majority DBMS Both provide a way of automatic allocation : Every time you add a row to a table , Will automatically assign the next available number , This function is called Auto increment .
Because the column name is provided ,VALUES The specified column names must be matched in the specified order , This order is not necessarily the order in which columns appear in the actual table .
Tips : Always use the list of columns
Usually , If you do not explicitly specify the list of columns , Then never use INSERT.
Warning : Omit column
If the table definition allows , It can be downloaded from INSERT Omit columns in operation . here , The following conditions must exist :
- Define the column to allow NULL value
- Specify the default value in the table definition . This means that if no value is specified , The default value will be used .
Tips : Insert multiple rows
Unlike most others DBMS Different ,Oracle Cannot insert multiple rows at the same time insert edition .
resolvent :
-- This grammar is an example of error , But in the other DBMS Can be used in
insert into table_name(colum1, colun2)
values(1,2),(3,4);
-- Proper use :
1、 use union all Splicing query method :
insert into CB_PRACTICE(id_, type_,remark)
select 5,' Physics ',' Buoyancy ' from dual
union all select 6,' Physics ',' resistance ' from dual;
2、 use insert all The way :
INSERT ALL
INTO CB_PRACTICE(id_, type_,remark) VALUES (7,' Chinese language and literature ',' Tang Poetry ')
INTO CB_PRACTICE(id_, type_,remark) VALUES (8,' Chinese language and literature ',' Song lyrics ')
SELECT * FROM DUAL;
2. Insert the retrieved data
INSERT There is another form , Can be used to INSERT The result of the statement is inserted into the table . This is called INSERT SELECT.
INSERT INTO customers(cust_id,
cust_contact,
cust_email,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country)
SELECT cust_id,
cust_contact,
cust_email,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
FROM custnew;
Tips :INSERT SELECT Column name in
For the sake of simplicity , This example is in INSERT and SELECT Use the same column name in the statement , But there is no need for column name matching .
边栏推荐
- Coding questions encountered in the interview
- [material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
- mpc5744p简介与OpenSDA固件更新
- Kotlin's list, map, set and other collection classes do not specify types
- post导出数据,返回
- 读懂 互联网巨头 【中台之战】 以及 中台 发展思维
- 9. Delay queue
- Differences and principles of bio, NiO and AIO
- C语言:typedef知识点总结
- 10.回退消息
猜你喜欢

不会就坚持61天吧 最短的单词编码

Beginner: array & String

不会就坚持63天吧 最大的异或

Machine vision series 3:vs2019 opencv environment configuration

Introduction and examples of parameters in Jenkins parametric construction

Compilation and linking

Hengxing Ketong invites you to the 24th China expressway informatization conference and technical product exhibition in Hunan

Make a virtual human with zego avatar | virtual anchor live broadcast solution

LeetCode_ Stack topics

Sequence list and linked list
随机推荐
Differences and principles of bio, NiO and AIO
15.federation
论pyscript使用感想(实现office预览)
你真的会写Restful API吗?
MySQL - clustered index and secondary index
14. Haproxy+kept load balancing and high availability
Labelme cannot open the picture
顺序表和链表
MySQL gets the maximum value record by field grouping
一个公司的面试笔记
Won't you just stick to 69 days? Merge range
C语言:浅谈各种复杂的声明
Pyscript cannot import package
mpc5744p简介与OpenSDA固件更新
Don't insist on 66 days. Weight generates random numbers
Update learning materials daily
C语言:typedef知识点总结
读懂 互联网巨头 【中台之战】 以及 中台 发展思维
Sequence list and linked list
Not for 60 days, magical dictionary