2011年2月26日
摘要: 1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table table_name_new as select * from table_name_old where 1=2; 或者: create table table_name_new like table_name_old 3. 只复制表数据: 如果两个表结构一样: insert into table_name_newselect * fromtable_name_old 如果两个表结构不一样: inse 阅读全文
posted @ 2011-02-26 23:23 玲珑少年 阅读(91125) 评论(0) 推荐(4) 编辑
摘要: 对于外连接,Oracle中可以使用“(+)”来表示,9i可以使用LEFT/RIGHT/FULL OUTER JOIN,下面将配合实例一一介绍。1. LEFT OUTER JOIN:左外关联 SELECTe.last_name,e.department_id,d.department_nameFROMemployeeseLEFTOUTERJOINdepartmentsdON(e.department_id=d.department_id);等价于 SELECTe.last_name,e.department_id,d.department_nameFROMemployeese,departmen 阅读全文
posted @ 2011-02-26 23:06 玲珑少年 阅读(767) 评论(0) 推荐(0) 编辑
摘要: -- 表 create table test (names varchar2(12), dates date, num int, dou double); -- 视图 create or replace view vi_test as select * from test; -- 同义词 create or replace synonym aa for dbusrcard001.aa; -- 存储过程 create or replace produce dd(v_id in employee.empoy_id%type) as begin end dd; -- 函数 create or rep 阅读全文
posted @ 2011-02-26 19:29 玲珑少年 阅读(387) 评论(0) 推荐(0) 编辑
摘要: SELECT col1, col2, CASE WHEN col3 > 1 AND col3 <2 THEN '1' WHEN col3 > 2 AND col3 <3 THEN '2' WHEN col3 > 3 AND col3 <4 THEN '3' ELSE '4' END mylevel FROM table1 SELECT CASE SIGN(5 - 5) WHEN 1 THEN 'Is Positive' WHEN -1 THEN 'Is Negative& 阅读全文
posted @ 2011-02-26 19:21 玲珑少年 阅读(467) 评论(0) 推荐(0) 编辑
摘要: Postgres 格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,int,float,numeric)转换成格式化的字符串以及反过来从格式化的字符串转换成原始的数据类型。 注意:所有格式化函数的第二个参数是用于转换的模板。 表 5-7. 格式化函数 函数 返回 描述 例子 to_char(timestamp, text) text 把 timestamp 转换成 string to_char(timestamp 'now','HH12:MI:SS') to_char(int, text) text 把 int4/int8 转换成 string to_ 阅读全文
posted @ 2011-02-26 19:09 玲珑少年 阅读(273) 评论(0) 推荐(0) 编辑