簡體   English   中英

從Oracle SQL中的DATE解析年份

[英]parsing year from DATE in Oracle SQL

我敢肯定,這是一個簡單的問題...但是我只是在如何從表中存儲的DATE的耳朵上畫一個空白。 我正在努力做的是生成一個查詢,該查詢返回標題,ID和所提供課程的年份....我知道我沒有在where子句中添加任何東西..這是到目前為止我所擁有的:

select title, id,  To_Char(c.START_DATE,'YYYY') AS year
 from (select c.COURSE_TITLE as title, g.STUDENT_ID as id, c.START_DATE
 from COURSES c, COURSE_INFO g) m;

我存儲了開始日期,但是我只想要年份部分

我對Date對象使用format()方法來拆分日期。 使用Dirk的日期文本,這是將日期分成其組成部分的方法:

datetxt <- c("2010-01-02", "2010-02-03", "2010-09-10") datetxt <- as.Date(datetxt) df <- data.frame(date = datetxt, year = as.numeric(format(datetxt, format = "%Y")), month = as.numeric(format(datetxt, format = "%m")), day = as.numeric(format(datetxt, format = "%d")))

這使:

> df date year month day 1 2010-01-02 2010 1 2 2 2010-02-03 2010 2 3 3 2010-09-10 2010 9 10

oracle中有Year函數

select title, id,  Year(START_DATE) AS year
 from (select c.COURSE_TITLE as title, g.STUDENT_ID as id, c.START_DATE
 from COURSES c, COURSE_INFO g) m;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM