Oracle日期函数:
select sysdate from dual; 从伪表查系统时间,以默认格式输出。
sysdate+(5/24/60/60) 在系统时间基础上延迟5秒
sysdate+5/24/60 在系统时间基础上延迟5分钟
sysdate+5/24 在系统时间基础上延迟5小时
sysdate+5 在系统时间基础上延迟5天
所以日期计算默认单位是天
round (sysdate,’day’) 不是四除五入了,是过了中午留下,不过的略掉
格式转换函数:
to_char显示日期:
从数字转化为char to_char(date,'格式')
从日期转化为char to_char(date, 'fmt' )
select to_char(sysdate, 'yyyy mm dd hh24:mi:ss') from dual;
select to_char(sysdate, 'fmyyyy mm dd hh24:mi:ss') from dual;
查出三月分入职的员工:
select first_name,start_date from s_emp where to_char(start_date,'mm')='03';
to_date表达日期:
字符转日期
select to_date('2000 11 20', 'yyyy mm dd ') from dual;
select round(to_date('10-OCT-06' ,'dd-mon-RR') ) from dual;
to_number
字符转数字
select to_number('10') from dual ;
函数、表达式、隐式数据类型转换会导致索引用不上,where条件后面只能放单行函数,它起了一个过滤的的作用。
相关文档:
select trim(leading | trailing | both ' ' from ' abc d ') from dual;
去掉字符串 ' abc d ' 的前面/后面/前后的空格
类似函数:ltrim, ......
今天在一个帖子里看到shiyiwan的回帖中提及到了两个自己以前没见过的概念,save exception和dml error logging。上网搜了搜相关内容,看了看大概明白意思,不过在实际运用中还是没怎么用过。保存下来,以后用的到的话方便查阅。
这一篇是关于save exception的,另外一篇dml error logging的参见如下链接
http://blog.csdn ......
Oracle主键自动增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下:
create table simon_example
(
id number(4) not null primary key,
name varchar2(25)
)
-- 建立序列:
-- Create sequence
create sequence SIMON_SEQUENCE &nb ......
今天第一次知道ORACLE原来还可以这样INSERT的……长见识了
一、无条件 INSERT ALL
二、条件 INSERT ALL
三、条件 INSERT FIRST
Insert…Select
使用Insert Select实现同时向多个表插入记录
一、无条件 INSERT ALL
----------------------------------------------------------------------- ......
如何定义游标类型
TYPE ref_type_name IS REF CURSOR [RETURN return_type];
声明游标变量
cursor_name ref_type_name;
从技术底层看,两者是相同的。普通plsql cursor在定义时是“静态”的。而Ref cursors可以动态打开。
例如下面例子:
Declare
type rc is ref cursor;
cursor c is select * from dual ......