随笔分类 - Oracle.函数
摘要:1.空值处理函数 1.1 nvl 用途:将第一参数(可能的)空值转换为第二参数 典型应用场景:A表左联到B表,如果某字段可能为空时。 例: SQL> select emp.name,nvl(dept.name,'梁山') as DEPT from emp 2 left join dept 3 on
阅读全文
摘要:代码: SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; TO_CHAR(SYSDATE,'YY 2022-06-03 06:46:13 SQL> select to_date('2022-06-03','yyyy-mm-
阅读全文
摘要:取DB的毫秒时间可以这样做: select to_char(systimestamp,'hh24:mi:ss.ff') from dual; 如下便可放入varchar2/nvarhcar2字段: 表: create table tb13( id number(12), fd_from nvarch
阅读全文
摘要:本文简述了如何利用oracle的sys_guid()函数来生成主键。
阅读全文
摘要:SQL: select count(*) from emp4 where regexp_like(name,'^\d+′);关键函数:regexplike(columnname,′\d+')测试语句: create table emp4( name varchar2(10) not n
阅读全文
摘要:取整语句: select trunc(12345.678,2), trunc(12345.678,1), trunc(12345.678,0), trunc(12345.678,-1), trunc(12345.678,-2) from dual 执行效果: SQL> select 2 trunc(
阅读全文
摘要:SQL: select to_char((sysdate-interval'1'day),'yyyy-mm-dd') as yesterday, to_char((sysdate-interval'1'month),'yyyy-mm-dd') as oneMonthAgo, to_char((sys
阅读全文
摘要:Oracle的trunc函数意为保持精度,如精度说明符缺失则精度保证到日,小于日的时分秒都不要了。 比如现在是21年10月11日21时31分,trunc之后,就只剩21年10月11日0时0分0秒了。 看下面的例子就更明白了: SQL> select to_char(sysdate-1,'yyyy-M
阅读全文
摘要:实验表: create table tmp( id int, name nvarchar2(20), primary key(id)); 实验数据: insert into tmp(id,name) values(1,'an,dy'); insert into tmp(id,name) values
阅读全文
摘要:Oracle sql中,取余函数不是通过% 或是mod双目操作符实现的,而是通过mod函数,具体用法也简单,如下: SQL> select mod(132,60) from dual; MOD(132,60) 12 简单明了。 END
阅读全文
摘要:转载地址:https://bbs.csdn.net/topics/310021870 1. ASCII返回与指定的字符对应的十进制数;SQL> select ascii(A) A,ascii(a) a,ascii(0) zero,ascii( ) space from dual;A A ZERO S
阅读全文
摘要:我对技术一般抱有够用就好的态度,一般在网上或者书上找了贴合的解决方案,放到实际中发现好用就行了,不再深究,等出了问题再说。 因此,我对Oracle中中形成有效序列的方法集中在rownum,row_number和rank三种方式,其中rank以简短写法(相对于row_number)和不会加深层次(相对
阅读全文
摘要:Decode和case都可以实现SQL中的条件结构,下面为用法示例: select id,name,score,decode(floor(score/20),5,'A',4,'B',3,'C',2,'D','E') as grade from tb_score01 order by grade 运行
阅读全文
摘要:事先申明下,我的DB环境是Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production,不保证在其它版本下也是同样的结果。 正文: 为了验证dbms_random.value是否包括边界值,我特意给下表填充了
阅读全文
摘要:select to_char(created_datetime,'yyyy-MM') as month,count(*) from DELIVERY_HISTORY group by to_char(created_datetime,'yyyy-MM') order by month; SQL> s
阅读全文
摘要:比如下面的语句 select concat(name,'/',description) from table1 这样的语句在数据库访问工具中执行没问题,到java中就报错。 解决办法也很简单,用单引号 ' 进行转义就行,如下: select concat(name,''/'',description
阅读全文