oracle基本语句

来源:互联网 发布:ubuntu 删除samba用户 编辑:程序博客网 时间:2024/05/02 07:17
select substr('Hellowepull',2,3) from a;--截取从第2个字符开始的长度为3个字符的字符串select substr('Hellowepull',2) from a;--截取从第2个字符开始的字符串select substr(t.title,2) from tf_cms_webpage t;--截取某个字段从第2个字符开始的字符串select chr(97) from a;--求一个与ASCII码值对应的字符select ascii('a') from a;--求一个字符的ASCII码值select to_char(2123,'L99,999.99') from a;--转换数字(to_char()用于将数字或日期转换成特定的字符串)select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from a;--转换时间(to_char()用于将数字或日期转换成特定的字符串)select * from tf_cms_webpage t where t.createdate > to_date('2012-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS');--to_date()是将特定的字符串转换成日期格式select * from (select c.*, rownum rn from tf_cms_webpage c) where rn between 21 and 40--分页查询(特定格式)--rownum只能使用<,<=,!=,<和!=结果是一样的--group by使用规律:出现在select列表中的字段如果没有出现在聚合函数中,则必须出现在group by子句中--复制表--1.只复制表结构create table b as select * from a where 1<>1;--2.既复制表结构又复制表的数据create table b as select * from a;--3.复制表的指定字段create table b as select n_id,n_name,n_age from a where 1<>1;--4.复制表的指定字段及数据create table b as select n_id,n_name,n_age from a;--视图--1.创建视图create view book_view asselect n_id,n_name,n_age from book join n_type on (book.n_name=n_type.name);--2.使用视图查询select * from book_view;--3.修改视图create or replace view booke_view asselect n_id,n_name,n_age from book join n_type on (book.n_name=n_type.name);--4.错误写法修改视图alter view booke_view asselect n_id,n_name,n_age from book join n_type on (book.n_name=n_type.name);--5.删除视图drop view book_view;--注意:对应的表的数据不会删除