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 perform arithmetic operations in Oracle database

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Today, I will talk to you about how to perform arithmetic operations in the Oracle database. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Oracle uses arithmetic expressions in SQL statements to perform arithmetic operations, including addition, subtraction, multiplication and division. An arithmetic expression consists of two operands (numbers or dates) and an operator. The four operators are as follows: + addition;-subtraction; * multiplication; / division.

Date operation:

You can add and subtract a date. For example, you can add a number (representing the number of days) to a date. For example, add 2 days on July 31, 2003, and the results are as follows:

SELECT TO_DATE ('31Mujulmi 2003') + 2

FROM dual

TO_DATE (

-

02-AUG-03

Note that TO_DATE () is a function that converts a string to a date. You can also subtract another date from one date, resulting in the number of days between the two dates. Here is an example of subtracting July 31, 2003 from August 2, 2003. The result is as follows:

SELECT TO_DATE ('02Mutual August 2003')-('31 murmur Julmi 2003')

FROM dual

TO_DATE ('02MAUGUGUGUMI 2003')-TO_DATE (' 31MUUGUMI 2003')

two

Column operation:

The Operand is not necessarily a number or date, but it can also be a column in a table. The following example will illustrate that both the name and price columns are queried from the products table: note that the expression formed by adding 2 to the value of the price column using the addition operator (+) is price+2:

SELECT name,price+2

FROM products

NAME PRICE + 2

--

Modern Science 21.95

Chemistry 32

Supernova 27.99

Tank War 15.95

Z Files 51.99

2412:The Return 16.95

Space Force 9 15.49

From Another Planet 14.99

Classical Music 12.99

Pop 3 17.99

Creative Yell 16.99

My Front Line 15.49

You can combine multiple operators in an expression. In the following example, price is first multiplied by 3 and then added by 1. The result is as follows:

SELECT name,price*3+1

FROM products

NAME PRICE*3+1

--

Modern Science 60.85

Chemistry 91

Supernova 78.97

Tank War 42.85

Z Files 150.97

2412:The Return 45.85

Space Force 9 41.47

From Another Planet 39.97

Classical Music 33.97

Pop 3 48.97

Creative Yell 45.97

My Front Line 41.47

The rules for arithmetic operators also apply in SQL: multiplication and division are limited, followed by addition and subtraction, and if the operators have the same priority, the order of operations is from left to right. Parentheses () can be used to specify the order in which operators are executed.

After reading the above, do you have any further understanding of how to perform arithmetic operations in the Oracle database? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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