内置函数----整理、例题 、xmin

-----------数值函数
---绝对值
select abs(-123) from dual;

--求模
select mod (12,5)  from dual;

--取整
--上限值
select  ceil(123.45) from  dual;

--下限值
select floor (123.45) from dual;

--四舍五入
select round(123.55) from dual;

select round(123.5267,2) from dual;--参数2表示小数点保留几位数

select round(126.5267,-1) from dual;--参数-1表示小数点向左移动1位

  

字符串函数、替换函数----------------------------------------------------------------------------

--截取,直接舍掉
select  trunc (123.52)  from  dual;
select trunc (126.5267,2) from dual;

select cno, round ( avg(degree) ,2) from score group by cno;

--计算字符串长度
select sname, length (sname)  from student;
select * from  student where length (sname)>2;

--去空格
select trim (‘    付 s十b 亮    ‘)  from dual;
select ltrim (‘    付 s十b 亮    ‘)  from dual;
select rtrim (‘    付s十b亮    ‘)  from dual;

--替换
select  replace(‘  abc   def   ‘,  ‘ ‘  ,  ‘#‘ )from dual;--把空格换成#

select  replace (sname, ‘王‘, ‘李‘) ,sname from  student where sname like ‘王%‘;

--更新姓王的学生名称为姓李的
update  student set sname = replace (sname, ‘王‘, ‘李‘)  where sname like ‘王%‘;

-- 查找字符串
 select instr (‘bac‘,  ‘a‘)  from  dual;  --数据库中索引和字符串位置从1开始

 --截取字符串
  select  substr(‘abdjhwkfjf‘, 2) from dual; --从第2位截取后面所有
 select  substr(‘abdjhwkfjf‘, 2,5) from dual;  --从第2个截取到第五位结束
  select  substr(‘abdjhwkfjf‘, -8,5) from dual;  --从右边向左数8位向右截取5位长度,长度不能是负数

select sname, substr(sname,1,1)  || ‘同学‘from  student ;

--成绩为空的替换成0
select t.*, nvl (degree ,0) from  score t;

select t.*, nvl (degree ,100,0) from  score t;--  100是不为空的替换成100,为空的默认为0

--替换
select t.* , decode (ssex,  ‘1‘ , ‘男‘ ,‘2‘,‘女‘ ,‘不知道‘)  from student t;

-- 返回当前用户
select user from dual ;

  

聚合函数------------------------------------------------------

--1.聚合函数   返回单个值
--记录条数
select count (sno)from student where sclass=95031;

--查平均成绩
select sum(degree)/count (1) from score;
select avg(degree) 平均值 from score;

--合计总成绩
select sum(degree) from score;

--最高成绩
select * from score order by degree desc;

select max (degree)最大值, min (degree)最小值,avg(degree) 平均值 from  score;

  

时间函数-------------------------------------------------------------------------

--字符串数字之间运算

select cast(‘123‘  as number ) +123 from dual;
----------------------时间函数
--查询系统时间
select sysdate from dual;

insert  into course values (‘8-123‘,‘设计素描‘,‘856‘,sysdate);

select sysdate +1  from  dual;
--增加系统月份
select add_months (sysdate,2) from  dual;
--查询系统本月最后一天
select last_day (sysdate) from  dual;

  

转换函数-----------------------------------------------------------------

--22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。

select t.sbirthday, to_char (t.sbirthday,‘yyyy-mm-dd hh24:mi:ss‘) from student t where sno=‘108‘

select sno,sname,sbirthday from student  where to_char (sbirthday,‘yyyy‘)=
(select  to_char (t.sbirthday,‘yyyy‘) from student t where sno=‘108‘);

select * from student where sbirthday >= to_date(‘1977-1-1‘,‘yyyy-mm-dd‘);

  

时间: 2024-08-10 19:17:42

内置函数----整理、例题 、xmin的相关文章

python3.7 内置函数整理

#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 内置函数整理 #abs(x) #返回数字的绝对值. 参数可以是整数或浮点数. 如果参数是复数,则返回其大小 # print(abs(1)) # print(abs(-1)) # print(abs(-1.234)) # 1 # 1 # 1.234 #all(iterable) #如果一个iterable(可迭代对象)的所有元素都为true(或者iterable为空),则返

部分内置函数整理

数学运算: abs :              取绝对值 round:            四舍五入取整 pow(2,3):       相当于2**3,pow(2,3,5)相当于2**3%5 divmod(9,2):    返回输出结果和余数 max([a,b]):     求最大最 min([a,b]):       求最小值 sum([a,b]):      求和 转换类型: eval:           将字符串str当成有效的表达式来求值并返回计算结果 int:        

pythonchallenge学到的python内置函数整理

第0关: 计算x的n次方: x**n 第一关: maketrans(from,to):建立一个翻译规则,将from翻译成to的翻译规则,因为要从from翻译成to,所以俩个参数的长度必须一致 translate(table[,deletechars]):使用上面的翻译规则对某一字符串进行翻译 example: 1 1 # -*- coding: utf-8 -*- 2 2 import string 3 3 table = string.maketrans('a', 'b') 4 4 print

Python常用内置函数整理(lambda,reduce,zip,filter,map)

匿名函数lambda lambda argument1,argument2,...argumentN :expression using arguments 1.lambda是一个表达式,而不是一个语句. 因为这一点,lambda可以出现在python语法不允许def出现的地方---例如,在一个列表常量中或者函数调用的参数中. 2.lambda 的主体是一个单个的表达式,而不是一个代码块. lambda是一个为编写简单的函数设计的,而def用来处理更大的任务. 例如: lambda表示式写法:f

python-面向对象速查表-内置方法-内置函数-内置属性(只整理了部分内容)

今日临时总结的内容,可能还有些不正确的地方,初步当做个速查表吧. 类的内置函数(继承object的,自己重写) 内置函数 执行时机 注意点 调用案例 __init__ 实例化对象时 不允许写返回值(return None和不返回没区别)子类重写了__init__()方法要在子类中的__init__()方法调用父类的__init__方法(super(当前类, self).__init__(参数)) stu = Student() __new__ 类实例化被调用时 stu = Studetn() _

Day10:内置函数、匿名函数、递归函数

一.内置函数 1.数学运算类 2.集合类操作 内置函数个别使用示例 1.any 集合中的元素有一个为真的时候为真, 特别的,若为空串返回为False 1 print(any([0,''])) 2 print(any([0,'',1])) 执行结果 1 False 2 True 2.divmod 取商得余数,用于做分页显示功能 1 print(divmod(10,3)) #取商得余数,用于做分页显示 执行结果 1 (3, 1) 3.eval  把字符串中的数据结构给提取出来 1 dic={'nam

Python内置函数详解

置顶   内置函数详解 https://docs.python.org/3/library/functions.html?highlight=built#ascii 此文参考了别人整理好的东西(地址:http://www.cnblogs.com/sesshoumaru/p/6140987.html#p1),然后结合自己的理解,写下来,一方面方便自己,让自己好好学习,顺便回忆回忆:另一方面,让喜欢的盆友也参考一下. 经查询,3.6版本总共有68个内置函数,主要分类如下: 数学运算(7个) 类型转换

python内置函数(1)

做了几道题,复习一下python的内置函数. python round() 函数 函数描述 round()函数返回浮点数x的四舍五入值 语法 round(x[, n]) 用法实例:浮点数x=3.1415926,用round()函数使x显示小数点后两位 print (round(x, 2)) 运行结果 3.14 多写一点 在使用round()函数的时候,有时候运行出的结果和自己想的不一样,比如: >>>round(2.25, 1) 2.2 >>>round(2.35, 1

Python自学之路——Python基础(四)内置函数

对上表一些比较重要常用的内置函数做一个整理 chr()与ord()     chr()是将ASCII中十进制编号转换成相应的字符,而ord()刚好相反 c = chr(49) o = ord('1') print(c) print(o) 输出结果: 1 49 知道了chr()的基本用法,可以利用它来生成一个字母验证码,因为验证码都是随机生成的,所以这里要涉及到random模块.在ASCII中,大写字母的十进制编号是从65到90. 小写字母是97到122 1 import random 2 li