mysql存储过程定义⽇期类型_数据库存储过程基本库函数:字符串类型,数值类型,⽇期类型...
附:函数库
mysql存储过程基本函数包括:字符串类型,数值类型,⽇期类型
⼀、字符串类
|| //字符串连接
CHARSET(str) //返回字串字符集
CONCAT (string2 [,… ]) //连接字串
INSTR (string ,substring ) //返回substring⾸次在string中出现的位置,不存在返回0
LCASE (string2 ) //转换成⼩写
LEFT (string2 ,length ) //从string2中的左边起取length个字符
LENGTH (string ) //string长度
LOAD_FILE (file_name ) //从⽂件读取内容
LOCATE (substring , string [,start_position ] ) 同INSTR,但可指定开始位置
LPAD (string2 ,length ,pad ) //重复⽤pad加在string开头,直到字串长度为length
LTRIM (string2 ) //去除前端空格
REPEAT (string2 ,count ) //重复count次
REPLACE (str ,search_str ,replace_str ) //在str中⽤replace_str替换search_str
RPAD (string2 ,length ,pad) //在str后⽤pad补充,直到长度为length
RTRIM (string2 ) //去除后端空格
STRCMP (string1 ,string2 ) //逐字符⽐较两字串⼤⼩,
SUBSTRING (str , position [,length ]) //从str的position开始,取length个字符,
注:mysql中处理字符串时,默认第⼀个字符下标为1,即参数position必须⼤于等于1
mysql菜鸟教程字符串型
mysql> select substring(’abcd’,0,2);
+———————–+
| substring(’abcd’,0,2) |
+———————–+
| |
+———————–+
1 row in set (0.00 sec)
mysql> select substring(’abcd’,1,2);
+———————–+
| substring(’abcd’,1,2) |
+———————–+
| ab |
+———————–+
1 row in set (0.0
2 sec)
TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2) //去除指定位置的指定字符UCASE (string2 ) //转换成⼤写
RIGHT(string2,length) //取string2最后length个字符
SPACE(count) //⽣成count个空格
⼆、数值类型
ABS (number2 ) //绝对值
BIN (decimal_number ) //⼗进制转⼆进制
CEILING (number2 ) //向上取整
CONV(number2,from_base,to_base) //进制转换
FLOOR (number2 ) //向下取整
FORMAT (number,decimal_places ) //保留⼩数位数
HEX (DecimalNumber ) //转⼗六进制
注:HEX()中可传⼊字符串,则返回其ASC-11码,如HEX(’DEF’)返回4142143
也可以传⼊⼗进制整数,返回其⼗六进制编码,如HEX(25)返回19jsp现在还流行吗>商城系统需求分析
LEAST (number , number2 [,..]) //求最⼩值
MOD (numerator ,denominator ) //求余
POWER (number ,power ) //求指数
RAND([seed]) //随机数
ROUND (number [,decimals ]) //四舍五⼊,decimals为⼩数位数]
注:返回类型并⾮均为整数,如:
(1)默认变为整形值
mysql> select round(1.23);
+————-+
| round(1.23) |
+————-+
| 1 |
+————-+
1 row in set (0.00 sec)
mysql> select round(1.56);
+————-+
| round(1.56) |
+————-+
| 2 |
+————-+
1 row in set (0.00 sec)
(2)可以设定⼩数位数,返回浮点型数据
mysql> select round(1.567,2);
+—————-+
| round(1.567,2) |
+—————-+
| 1.57 |
+—————-+
1 row in set (0.00 sec)
SIGN (number2 ) //返回符号,正负或0
SQRT(number2) //开平⽅
三、⽇期类型
ADDTIME (date2 ,time_interval ) //将time_interval加到date2
CONVERT_TZ (datetime2 ,fromTZ ,toTZ ) //转换时区
CURRENT_DATE ( ) //当前⽇期
CURRENT_TIME ( ) //当前时间
CURRENT_TIMESTAMP ( ) //当前时间戳
DATE (datetime ) //返回datetime的⽇期部分
DATE_ADD (date2 , INTERVAL d_value d_type ) //在date2中加上⽇期或时间DATE_FORMAT (datetime ,FormatCodes ) //使⽤formatcodes格式显⽰datetime DATE_SUB (date2 , INTERVAL d_value d_type ) //在date2上减去⼀个时间DATEDIFF (date1 ,date2 ) //两个⽇期差
DAY (date ) //返回⽇期的天
DAYNAME (date ) //英⽂星期
DAYOFWEEK (date ) //星期(1-7) ,1为星期天
DAYOFYEAR (date ) //⼀年中的第⼏天
EXTRACT (interval_name FROM date ) //从date中提取⽇期的指定部分MAKEDATE (year ,day ) //给出年及年中的第⼏天,⽣成⽇期串
MAKETIME (hour ,minute ,second ) //⽣成时间串
MONTHNAME (date ) //英⽂⽉份名
NOW ( ) //当前时间
SEC_TO_TIME (seconds ) //秒数转成时间
STR_TO_DATE (string ,format ) //字串转成时间,以format格式显⽰
TIMEDIFF (datetime1 ,datetime2 ) //两个时间差
TIME_TO_SEC (time ) //时间转秒数]
WEEK (date_time [,start_of_week ]) //第⼏周
YEAR (datetime ) //年份
DAYOFMONTH(datetime) //⽉的第⼏天
HOUR(datetime) //⼩时
LAST_DAY(date) //date的⽉的最后⽇期
MICROSECOND(datetime) //微秒
MONTH(datetime) //⽉
MINUTE(datetime) //分
注:可⽤在INTERVAL中的类型:DAY ,DAY_HOUR ,DAY_MINUTE ,DAY_SECOND ,HOUR ,HOUR_MINUTE ,HOUR_SECOND
,MINUTE ,MINUTE_SECOND,MONTH ,SECOND ,YEAR
DECLARE variable_name [,] datatype [DEFAULT value];
其中,datatype为mysql的数据类型,如:INT, FLOAT, DATE, VARCHAR(length)
例:
DECLARE l_int INT unsigned default 4000000;
DECLARE l_numeric NUMERIC(8,2) DEFAULT 9.95;
DECLARE l_date DATE DEFAULT '1999-12-31';
DECLARE l_datetime DATETIME DEFAULT '1999-12-31 23:59:59';
DECLARE l_varchar VARCHAR(255) DEFAULT 'This will not be padded';
例:
create or replace procedure DS16_1FB_QUERY(ls_bbrq IN VARCHAR2,os OUT INTEGER,flag OUT INTEGER) AS
--报表管理DS16_l电⽣16-1附表的查询和编辑; --输⼊报表⽇期ls_bbrq,输出os和flag, os=0即没有需要统计的数据!os=1统计结束! yf DATE;
ls_pzbm VARCHAR2(12);
ll_pzbm Number(12);
ld_dlby Number(10,2);
ld_dlbj Number(10,2);
ld_dllj Number(10,2);
ld_mlby Number(10,2);
ld_mlbj Number(10,2);
ld_mllj Number(10,2);
ld_mhby Number(10,2);
ld_mhbj Number(10,2);
ld_mhlj Number(10,2);
快递补码是什么意思ld_frlby Number(10,2);
springboot实战视频免费百度网盘ld_frlbj Number(10,2);
ld_frllj Number(10,2);
li_count INTEGER;
BEGIN
select count(*) into li_count from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm like '1';如何御载ora11g
if li_count=0 then
os:=0;--没有需要统计的数据! flag:=1;
else
delete hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm like '1';
commit;
select sum(dlby) into ld_dlby from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(dlbj) into ld_dlbj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(dllj) into ld_dllj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlby) into ld_mlby from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlbj) into ld_mlbj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mllj) into ld_mllj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlby*1000)/sum(dlby) into ld_mhby from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlbj*1000)/sum(dlbj) into ld_mhbj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mllj*1000)/sum(dllj) into ld_mhlj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlby*frlby)/sum(mlby) into ld_frlby from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
select sum(mlbj*frlbj)/sum(mlbj) into ld_frlbj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like
'1';
select sum(mllj*frllj)/sum(mllj) into ld_frllj from hc_d16fbbb where to_char(bbrq,'yyyymm')=ls_bbrq and rllbdm not like '1';
ld_mhby:=round(ld_mhby,0);--四舍五⼊ ld_mhbj:=round(ld_mhbj,0);
ld_mhlj:=round(ld_mhlj,0);
select max(pzbm) into ls_pzbm from hc_d16fbbb where substr(pzbm,1,4)='0400';
ll_pzbm:=100000000+to_number(ls_pzbm)+1;--字符串转化为数字 ls_pzbm:=substr(to_char(ll_pzbm),5,12); --数字转化为字符串ls_pzbm:='0400' || ls_pzbm; --字符串连接
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论