从char更改日期格式

时间:2018-09-05 14:37:16

标签: sql oracle

我在public partial class TabBarController : UITabBarController { public TabBarController(IntPtr handle) : base(handle) { //this does the trick! TabBar.Translucent = false; } } 字段中具有以下格式。 The following classes could not be instantiated: - android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache) - android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache) - android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener Copy stack to clipboard 字段是char数据类型。查询该列时,是否可以用indicator_date格式标准化显示它们?允许用户手动输入日期,但是他们选择了日期,但我无法更改。谢谢。

日期显示方式示例:

indicator_date

我尝试过mm/dd/yyyy,但返回错误。

  

ORA-01830:日期格式图片在转换整个输入之前结束   字符串

2 个答案:

答案 0 :(得分:0)

您要寻找to_char()to_date()吗?

select to_char(to_date('5/2/2018', 'MM/DD/YYYY'), 'MM/DD/YYYY')
from dual

答案 1 :(得分:0)

对于无效的日期(20118年),不可能编写一个良好的转换表达式...但是对于其他日期,方法可能是:

  with dats as (
             select '5/2/2018' dt from dual
  union all select '5/21/2018' dt from dual
  union all select '01/29/2018' dt from dual
  union all select '2018-01-13' dt from dual
  union all select '8/17/20118' dt from dual
  union all select '23018' dt from dual
  )
  select dt
  , to_char(
     case when regexp_like(dt,'(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[0-2])/([12][0-9]{3,3})$') then to_date(dt,'DD/MM/YYYY') 
         when regexp_like(dt,'((0?[1-9]|1[0-2])/0?[1-9]|[12][0-9]|3[01])/([12][0-9]{3,3})$') then to_date(dt,'MM/DD/YYYY') 
         when regexp_like(dt,'([12][0-9]{3,3})-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])$') then to_date(dt,'YYYY-MM-DD') 
  --       when regexp_like(dt,'^(0?[1-9]|1[0-2])(0?[1-9]|[12][0-9]|3[01])(([12][0-9])?[0-9]{2,2})$') then to_date(regexp_replace(dt,'^(0?[1-9]|1[0-2])(0?[1-9]|[12][0-9]|3[01])(([12][0-9])?[0-9]{2,2})$','\1/\2/\3') ,'MM/DD/YYYY') 
  else null end   
   , 'MM/DD/YYYY' ) dtconv 
  from dats
  ;

23018的问题是22818可以工作,但是2018年2月30日不存在。