Oracle学习中的一些笔记

来源:互联网 发布:ip是网络层协议 编辑:程序博客网 时间:2024/05/18 23:53

1.对日期的比较大小时 :

都使用了一个转换,前面加了个date 如:

select months_between(date'2005-2-10',date'2007-3-10') from dual; =-25 差25个月 :前面必须加个date.不用函数时的比较也要加个date

select * from books where datetime<date'2001-01-15';

2.对日期的insert操作

若无法正常insert时,则考虑to_date('日期','格式')进行insert,如:

insert into books values(1,to_date(01-01-2001',dd-mm-yyyy'),1000);

3.在sql*plus工具下create table时 第一出现错误 使用ed命令进行编辑时 不要加最后的分号; 否则会提示:

create table b
( id number);

ORA-00911: 无效字符:提示的地方在;处 说明ed编辑时不能加;

 

Oracle中的反转:

declare
abc varchar2(10);
begin
--abc :=reverse('&gdg');这种方法不能在pl块中赋值,要用select
select reverse('&gfg') into abc from dual;
dbms_output.put_line (abc);
end;

自定义的游标 可以用做变量的类型 例:

declare
cursor c_emp is select empno,ename,sal from emp order by sal desc;
emp1 c_emp%rowtype;--emp1的类型就是游标的行记录,这样可以减少声明变量数
begin
open c_emp;
loop
fetch c_emp into emp1;
exit when c_emp%notfound;
dbms_output.put_line(emp1.empno||' '||emp1.ename||' '||emp1.sal);
end loop;
close c_emp;
end;

oracle 日期参数:

由于各个地区的日期格式不同,所以在定义数据库的时间列时建议使用varchar2类型,然后再用to_date进行转换.

错误提示:ORA-01840: 输入值对于日期格式不够长:

如输入的是1982-01-01时就会出现 解决:应该输入19820101