Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 3rd, 2005, 08:39 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,239 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 12 h 25 m 28 sec
Reputation Power: 17
help with TO_CHAR function or similar

ok is there a function that would extract the year from a date?

how does to_char work, and how would i use that to extract the year?
ok i have found one: EXTRACT(YEAR FROM DATE '1998-03-07')

but is that date written in the normal oracle way or .... as in my case i will use the function in a trigger and instead of the date i will reference a field in the table....

here is a trigger that i created but i get errors!
Code:
create or replace trigger calculateYearColumn 
After insert on Students
for each row
declare
	Y	number(4);
begin
	select EXTRACT(YEAR FROM DATE 'enrolment_date') into Y from  
        students;
        insert into students (enrolment_year) values (Y);
end;
/


errors:
Code:
4/2 	PL/SQL: SQL Statement ignored
4/32 	PL/SQL: ORA-01841: (full) year must be between -4713 and +9999, a nd not be 0

Last edited by paulh1983 : March 3rd, 2005 at 08:53 AM.

Reply With Quote
  #2  
Old March 3rd, 2005, 09:22 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,808 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 21 h 29 m 33 sec
Reputation Power: 278
Quote:
how does to_char work?

See this

This example should also help:
Code:
select to_char(to_date('1998-03-07', 'YYYY-MM-DD'), 'YYYY') from dual;

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > help with TO_CHAR function or similar


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway