Skip to content

Instantly share code, notes, and snippets.

@hyang0
Last active October 21, 2015 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyang0/2498e1494bf7af5503b9 to your computer and use it in GitHub Desktop.
Save hyang0/2498e1494bf7af5503b9 to your computer and use it in GitHub Desktop.
oracle sql functions
-- 取倒数第二位
select to_number(substr('12345', -2, 1)) from dual;
-- 正规匹配尾数为2,7的字符串
select example_str from example_table
where regexp_like(example_str, '.*[27]$');
-- 取日期(年-月-日)中的日
select to_number(to_char(sysdate, 'dd')) from dual;
-- 使用已有字段创建表,其中select子句可加where条件
create table t2 as select * from t1;
-- 向目标表中插入已知表数据,t2须存在且目标列与数据源类型要相同
insert into t2 select * from t1;
-- table rename
alter table mytable rename to othertable
-- In Oracle 10g also:
rename mytable to othertable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment