-----如果字段为日期格式的,那么在和日期比较时要转换成字符串格式,

因为单纯的日期是字符串格式(例:'2013/7/1')。

例:

(一个字段的选择。思路:先把字段转换成字符串格式,然后比较。)

select column

from table

where to_char(column,'yyyy/MM/dd')> '2013/7/1';

=========比较时日期格式要相同

select column

from table

where  to_char(column,'yyyy-MM-dd')>='2013-01-01' ;


(两个字段的选择。思路:和一个字段选择一样,加上‘and’就行。)

select column1,column2

from table

where to_char(column1,'yyyy-MM-dd')>='2013-01-01'

and to_char(column2,'yyyy-MM-dd')<= '2013-07-31';

-------如果字段是字符串格式,那么在和日期比较时可直接

        转换成相同的格式比较就好。

select * from table

where column>='20130101'

and column <= '20130731';



-------从表取column,

        当column为×××时置为1,为蓝色时置为2,其它为1

select decode(column,'×××','1','蓝色','2','1')

from table ;


select (case column when '×××' then '1' when '蓝色' then '2' else '1' end )

from table ;

------根据类型查出所有客户数量

select count(*), 'ky' as type (列别名,显示两列)

from table

where column like '%客运%'

union

select count(*),'wh' as type

from table

where column like '%危货%'


------------复制表结构

create table table_name_new as select * from table_name_old where 1=2 ;

或create table table_name_new like table_name_old ;

------------增加列alter table t add(new_column number(10));

------------删除列alter table t drop column new_column ;

-----------只复制表数据:

如果两个表结构一样:

insert into table_name_new select * from table_name_old

如果两个表结构不一样:

insert into table_name_new(column1,column2...)

select column1,column2... from table_name_old