5.单行函数,多行函数,字符函数,数字函数,日期函数,数据类型
1 多行函数(理解:有多个输入,但只输出1个结果) SQLselect count(*) from emp; COUNT(*) ------------- 14 B 字符函数Lower select Lower(Hello) 转小写, upper(hello) 转大写, initcap(hello woRld) 首字母大写 from dual; 结果: 转小 转大 首字母大写
1 多行函数(理解:有多个输入,但只输出1个结果)
SQL>select count(*) from emp;
COUNT(*)
-------------
14
B 字符函数Lower
select Lower('Hello') 转小写,
upper('hello') 转大写,
initcap('hello woRld') 首字母大写
from dual;
结果:
转小 转大 首字母大写
---------- -----------
helloHELLO Hello World
C字符函数 concat:
select concat('hello','world') from dual
concat函数嵌套:
select concat (concat('hello', 'world'),'cccc') 函数嵌套 from dual;
函数嵌套
--------------
helloworldcccc
D字符函数 substr()
SUBSTR(a,b) --- 从a中第b位去字符串
substr(a, b, c) 从a中第b位, c个字符....
select substr('abcdefg1111', 2) 从第二位取子串,
substr('abcdefg1111', 2, 4) 取4个字符
from dual;
从第二位取取4
----------------- ------
bcdefg1111 bcde
E length字符数 lengthb字节数
注意:一个中文字符,两个字节
select length('中国abc') 字符数,
lengthb('中国abc') 字节数
from dual;
运行结果:
字符数 字节数
---------- ----------
5
F instr(),lpad(),rpad(),trim()函数
select instr('abcdefg', 'efg') 求子串位置 from dual;
求子串位置
----------------
5
selectlpad('abcd', 10, '*') lpad, rpad('abcd', 10, '*') rpad from dual;
LPAD RPAD
---------- ----------
******abcd abcd******
--trim 去掉前后指定的字符,字符可以是空格,也可以不是空格 .
selecttrim('A' from 'ABCDEFg') from dual;
TRIM('
------
BCDEFg
2 数字函数
第二个参数 |
含义 |
2> 0 |
保留2位 |
= 0 |
保留到个位 |
-1 |
保留到10位 |
-2 |
保留到百位(要看十位四舍五入) |
selectround(45.926, 2) AA,
round(45.926, 1) BB,
round(45.926, 0) CC,
round(45.926) DD,
round(45.926, -1) EE,
round(45.926, -2) FF
from dual;
结果:
AA BB CC DD EE FF
---------- ---------- ---------- ---------- ---------- ----------
45.93 45.9 46 46 50 0
3 日期函数
时间的计算.......
oracle数据库中 date包含日期和时间
mysql 3中数据类型 date 、time 、times.
A selectto_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') from dual ;
TO_CHAR(SYSDATE,'YY
-------------------
2014-10-0716:34:17
B ----昨天今天明天
select sysdate-1 昨天,
sysdate 今天,
sysdate+1 明天
from dual;
selectto_char(sysdate-1, 'yyyy-mm-dd hh24:mi:ss') 昨天,
sysdate 今天,
sysdate+1 明天
from dual;
C ----查询员工的入职时间,按照周 月 年方式显示.....
select(sysdate-hiredate)/7 周,
(sysdate-hiredate)/30 月,
(sysdate-hiredate)/365 年
from emp;
select (sysdate-hiredate)/7 周,
(sysdate-hiredate)/30 月,
(sysdate-hiredate)/365
from emp;
周 月 年
---------- ---------- ----------
1763.95625 411.589791 33.8292979
1754.67053 409.423125 33.6512157
1754.38482 409.356458 33.6457363
D 查询员工的入职时间, 入职月数
selectename,
(sysdate-hiredate)/30 估计月,
MONTHS_BETWEEN(sysdate, hiredate) 函数计算月
from emp
select ename,
(sysdate-hiredate)/30 估计月,
MONTHS_BETWEEN(sysdate, hiredate) 函数计算月
from emp;
ENAME 估计月函数计算月
---------- ---------- ----------
SMITH 411.589872 405.699876
ALLEN 409.423205 403.603102
WARD 409.356539 403.538586
JONES 408.056539 402.183747
MARTIN 402.089872 396.345037
selectnext_day(sysdate, '星期六') from dual ;
NEXT_DAY(SYSDA
--------------
11-10月-14
4 数据类型转换
select * from emp where hiredate >'01-1月 -81'
A 日期相关类型转换
比这个日期都要大的08-9月 -81 所有员工信息按照三种方式实现
(1):隐式类型转换
select*
from emp
where hiredate > '01-1月 -81';
(2):字符串转成日期..显示类型转换
select*
from emp
where hiredate > to_date('1981-01-0102:03:04', 'yyyy-mm-dd hh24:mi:ss');
(3):日期转换成为日期类型的字符串:
select*
from emp
where to_char(hiredate, 'yyyy-mm-ddhh24:mi:ss') > '1981-01-01 02:03:04'
5 数字和字符串转换
A --查询员工的薪水:两位小数本地货币代码千位符
Y1,250.00
select empno, ename, to_char(sal, 'L9,999.99')
fromemp
结果:
EMPNO ENAME TO_CHAR(SAL,'L9,999
---------- ---------- -------------------
7369SMITH ¥800.00
7499ALLEN ¥1,600.00
7521WARD ¥1,250.00
7566JONES ¥2,975.00
7654MARTIN ¥1,250.00
7698BLAKE ¥2,850.00
7782CLARK ¥2,450.00
B 把这个字符¥1,250.00,转成数字.....
select to_number('¥1,250.00','L9,999.99') from dual ;
TO_NUMBER('¥1,250.00','L9,999.99')
-----------------------------------
1250
6 通用函数
A 给员工涨工资:总裁 1000 经理:800 其他涨500,
===============================================
分析:前后工资给列出来
if (job == 'PRESIDENT')
SAL+1000
else if (job == 'MANAGER')
SAL+800
else
SAL+500
================================================
使用的知识点:
CASE expr WHEN comparison_expr1 THEN return_expr1
[WHEN comparison_expr2 THENreturn_expr2
WHEN comparison_exprn THEN return_exprn
ELSE else_expr]
END
===============================================
转化:
CASE job when 'PRESIDENT' then sal+1000
when'MANAGER' then sal+800
elsesal + 500
END
=============================================
select ename, job, sal 涨前工资,
(
CASE job when 'PRESIDENT' then sal+1000
when'MANAGER' then sal+800
elsesal + 500
END
)
涨后工资
from emp
-----------------------------------------------------------------------------------------------------
结果:
ENAME JOB 涨前工资 涨后工资
------------------- ---------- ----------
SMITH CLERK 800 1300
ALLEN SALESMAN 1600 2100
WARD SALESMAN 1250 1750
JONES MANAGER 2975 3775
MARTIN SALESMAN 1250 1750
BLAKE MANAGER 2850 3650
CLARK MANAGER 2450 3250
SCOTT ANALYST 3000 3500
KING PRESIDENT 5000 6000
TURNER SALESMAN 1500 2000
ADAMS CLERK 1100 1600
JAMES CLERK 950 1450
FORD ANALYST 3000 3500
MILLER CLERK 1300 1800
已选择14行。
B 第二种方法
===================================================
语法:
DECODE(col|expression, search1, result1
[, search2, result2,...,]
[, default])
==================================================
转化:
decode(job, 'PRESIDENT', sal+10000, 'MANAGER', sal+800, sal+500)
===================================================
select ename, job, sal 涨前工资,
(
decode(job, 'PRESIDENT', sal+10000,'MANAGER', sal+800, sal+500)
)
涨后工资
from emp;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

FP8 and lower floating point quantification precision are no longer the "patent" of H100! Lao Huang wanted everyone to use INT8/INT4, and the Microsoft DeepSpeed team started running FP6 on A100 without official support from NVIDIA. Test results show that the new method TC-FPx's FP6 quantization on A100 is close to or occasionally faster than INT4, and has higher accuracy than the latter. On top of this, there is also end-to-end large model support, which has been open sourced and integrated into deep learning inference frameworks such as DeepSpeed. This result also has an immediate effect on accelerating large models - under this framework, using a single card to run Llama, the throughput is 2.65 times higher than that of dual cards. one

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.
