oracle 使用sql 把字符串转换成yyyy-mm-dd 如题;有一个字段存储的是字符串 2015年04月 想转成 2015-04-01.谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select to_date(substr('2015年04月', 1, 4) || substr('2015年04月', -3, 2), 'yyyymm') from dual;这种情况下,数据库仍然保留date数据类型,日期输入年月日。显示的时候用to char函数,格式是只显示年月即可。 select replace(replace('2015年04月', '年', '-'),'月','-')+'01' from dual; -- 凑个人数select translate('2015年04月','#年月','#--') || '01' from dual select replace(replace('2015年04月', '年', '-'),'月','-')||'01' from dual; 根据楼主描述的“转换”有两种情况:①当你查询时,需要将已经插入的2015年04月 显示为2015-04-01,如下:SQL> select concat(replace(replace('2015年04月', '年', '-'), '月', '-'), '01') from dual;CONCAT(REPLACE(REPLACE('2015年------------------------------2015-04-01其中concat()函数相当于“||”连接符号,故可以使用如下方式:SQL> select replace(replace('2015年04月', '年', '-'), '月', '-') || '01' from dual;REPLACE(REPLACE('2015年04月','------------------------------2015-04-01②就是楼主如果希望改变原来插入值的格式为2015-04-01,则就需要使用修改的方式解决如下:SQL> update 表名 set 字段名 = to_date('2015-04-01', 'yyyy-mm-dd') where 更改条件;1 row updated select to_char( to_date( replace( replace('2015年04月','年',''),'月','') ,'yyyyMM' ),'yyyy-mm-dd' ) from dual oracle数据库存储过程调用问题 求一条SQL语句(万恶的字符串截取问题)++++++ sqlldr为何不好用啊? 在线给分就解: 无法为SQL*NET V2监听器创建NT服务 这个查询语句是什么意思? 求解一个触发器的相关问题 十万火急(50) 怎样进行全库导入 这种情况如何将列fetch出来? Oracle 行转列 --> linq 实现 用户权限 PL/SQL Developer 连接不上,求助
'yyyymm')
from dual;这种情况下,数据库仍然保留date数据类型,日期输入年月日。显示的时候用to char函数,格式是只显示年月即可。
select replace(replace('2015年04月', '年', '-'),'月','-')+'01'
from dual;
-- 凑个人数
select translate('2015年04月','#年月','#--') || '01' from dual
from dual;
①当你查询时,需要将已经插入的2015年04月 显示为2015-04-01,如下:
SQL> select concat(replace(replace('2015年04月', '年', '-'), '月', '-'), '01') from dual;
CONCAT(REPLACE(REPLACE('2015年
------------------------------
2015-04-01其中concat()函数相当于“||”连接符号,故可以使用如下方式:
SQL> select replace(replace('2015年04月', '年', '-'), '月', '-') || '01' from dual;
REPLACE(REPLACE('2015年04月','
------------------------------
2015-04-01②就是楼主如果希望改变原来插入值的格式为2015-04-01,则就需要使用修改的方式解决如下:
SQL> update 表名 set 字段名 = to_date('2015-04-01', 'yyyy-mm-dd') where 更改条件;
1 row updated
to_date(
replace( replace('2015年04月','年',''),'月','')
,'yyyyMM'
),'yyyy-mm-dd'
) from dual