Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate big data Collection in Database

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to manipulate the big data collection in the database. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Insert data by subquery

1. Grammar

INSERT INTO table [column (, column)] subquery

2. Description:

You can use the insert statement to add rows to a table with values from the query result set.

The number of columns and their data types in the column list that inserts the clause must match the values and data types in the subquery.

3. Example sentence:

INSERT INTO EMPL3

SELECT *

FROM employees

II. WITH CHECK OPTION

1. Grammar:

Insert into (WITH CHECK OPTION) values (...)

2. Description:

Insert goes into this table in subquery.

Insertion is not allowed if the where condition in subquery is not met.

If the inserted column is not in the where condition checked by subquery, then the insert will not be allowed.

If you do not add WITH CHECK OPTION, it will not be checked at insert time.

Note here that subquery is not actually implemented.

3. Example sentences

INSERT INTO

(SELECT EMPLOYEE_ID, LAST_NAME, EMAIL, HIRE_DATE, JOB_ID, SALARY

FROM EMPLOYEES

WHERE DEPARTMENT_ID = 50 WITH CHECK OPTION)

VALUES

(99998

'Smith'

'JSMITH'

TO_DATE ('1999-06-07,' yyyy-mm-dd')

'ST_CLERK'

5000)

III. INSERT ALL

1. Grammar:

A) unconditional

INSERT [ALL] [conditional_insert_clause]

[insert_into_clause values_clause] (subquery)

B) conditional

INSERT [ALL]

[WHEN condition THEN] [insert_into_clause values_clause]

[ELSE] [insert_into_clause values_clause]

2. Description

A) if there is no when condition, all tables will be inserted

B) if there is a when condition, each when condition is checked and the insert operation is performed if the condition is met.

3. Example sentence:

-- unconditional

INSERT ALL

INTO SAL_HISTORY

VALUES (EMPID, HIREDATE, SAL)

INTO MGR_HISTORY

VALUES (EMPID, MGR, SAL)

SELECT EMPLOYEE_ID EMPID, HIRE_DATE HIREDATE, SALARY SAL, MANAGER_ID MGR

FROM EMPLOYEES

WHERE EMPLOYEE_ID > 200

-- conditional

INSERT ALL

WHEN SAL > 10000

THEN INTO SAL_HISTORY

VALUES (EMPID, HIREDATE, SAL)

WHEN MGR > 200

THEN INTO MGR_HISTORY

VALUES (EMPID, MGR, SAL)

SELECT EMPLOYEE_ID EMPID, HIRE_DATE HIREDATE, SALARY SAL, MANAGER_ID MGR

FROM EMPLOYEES

WHERE EMPLOYEE_ID > 200

IV. INSERT FIRST

1. Grammar:

INSERT [FIRST]

[WHEN condition THEN] [insert_into_clause values_clause]

[ELSE] [insert_into_clause values_clause]

2. Description:

For each row of data, only the table where the first when condition holds is inserted, and no other conditions are checked.

3. Example sentence:

INSERT FIRST

WHEN SAL > 25000

THEN INTO SPECIAL_SAL

VALUES (DEPTID, SAL)

WHEN HIREDATE LIKE ('%')

THEN INTO HIREDATE_HISTORY_00

VALUES (DEPTID, HIREDATE)

WHEN HIREDATE LIKE ('% 99%')

THEN INTO HIREDATE_HISTORY_99

VALUES (DEPTID, HIREDATE)

ELSE INTO HIREDATE_HISTORY

VALUES (DEPTID, HIREDATE)

SELECT DEPARTMENT_ID DEPTID, SUM (SALARY) SAL, MAX (HIRE_DATE) HIREDATE

FROM EMPLOYEES

GROUP BY DEPARTMENT_ID

5. MERGE

1. Grammar:

MERGE INTO table_name table_alias

USING (table | view | sub_query) alias

ON (join condition)

WHEN MATCHED THEN

UPDATE SET

Col1 = col_val1

Col2 = col2_val

WHEN NOT MATCHED THEN

INSERT (column_list)

VALUES (column_values)

2. Description:

Merge is used to select data updates from one table or insert them into another table. In the end, whether to update or insert depends on the conditions in the statement.

3. Example sentence:

MERGE INTO empl3 c

USING employees e

ON (c.employee_id = e.employee_id)

WHEN MATCHED

THEN UPDATE SET

C.first_name = e.first_name

C.last_name = e.last_name

...

C.department_id = e.department_id

WHEN NOT MATCHED

THEN INSERT VALUES

(e.employee_id, e.first_name, e.last_name

E.email, e.phone_number, e.hire_date, e.job_id

E.salary, e.commission_pct, e.manager_id

E.department_id)

VI. Flashback Version Query

1. Grammar:

VERSIONS BETWEEN TIMESTAMP [lower bound] AND [upper bound]

VERSIONS BETWEEN SCN [lower bound] AND [upper bound]

2. Description:

Through versions between, you can view different versions of records in the undo table space within a specified period of time.

3. Example sentence:

SELECT SALARY

FROM EMPLOYEES3 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE

WHERE EMPLOYEE_ID = 107

Thank you for reading! This is the end of the article on "how to operate a large dataset in the database". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report