0

The table I am trying to use is

create type Rehearsal_ty as object
(RehID char(4),
RLocation add_ty,
Attendance varchar2 (100),
RDate date)

create table Rehearsal_tbl of Rehearsal_ty

The select statement I am trying to use can't get it to work

SELECT rehid, DATEPART(wk,rdate)
from Rehearsal_tbl

SELECT DATEPART (ww,rdate())
FROM Rehearsal_tbl;

please help really stuck

RThomas
  • 10,702
  • 2
  • 48
  • 61
TomC
  • 1
  • 1
  • 1
  • What database are you using? For MS SQL Server the following code works: `select DATEPART(WW,GETUTCDATE())`. As you're looking at a table in a column I wouldn't expect you to need the brackets - but that may be different in your case depending on DB. `SELECT DATEPART(WW,rdate) FROM Rehearsal_tbl;`. Also, when you say it's not working, are you getting a syntax error, or is the result different to what you were expecting? – JohnLBevan Dec 08 '12 at 00:26
  • I have tried both but just keep getting errors the error I recieved is: ORA-00904: "DATEPART": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Error at Line: 753 Column: 7 – TomC Dec 08 '12 at 00:57

1 Answers1

0

(UPDATED) Looks like the Oracle documentation was incorrect - here's a version which works. You can test it out here: http://sqlfiddle.com/#!4/77080/7

select RehID, to_char(rdate, 'IW') as IsoWeekChar
from Rehearsal_tbl;

.

select RehID, to_char(rdate, 'WW') as IsoWeekChar
from Rehearsal_tbl;

.

select RehID, to_number(to_char(rdate, 'IW')) as IsoWeekNumeric
from Rehearsal_tbl;

.

select RehID, to_number(to_char(rdate, 'WW')) as OraWeekNumeric
from Rehearsal_tbl;
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
  • I have tried both select statements but no joy getting an error message ORA-00904: "DATEPART": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Error at Line: 230 Column: 14 – TomC Dec 08 '12 at 10:02