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 December 2nd, 2004, 03:02 PM
paulh1983 paulh1983 is online now
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,241 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 13 h 3 m 39 sec
Reputation Power: 17
triggering/DATE, month question

my code is below, what i want to do is to change the year automatically after july each year. this gives me the error: inconsistent datatypes, expected UDT got Number

Code:
create or replace trigger change_Year
after update on student
for each row

Declare
	A	student_type;
	B	student_type;
Begin
	
	IF (SYSDATE > '1-JUL') THEN
		select s.YEAR into A from student s;
		IF (A = 1) then
		    B:=s.year+1;
		elsif (A = 2) then
		    B:=s.year+2; 
		else
			delete from student;
		end if;
	end if;
End;
/

Reply With Quote
  #2  
Old December 3rd, 2004, 10:45 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 2 m 57 sec
Reputation Power: 48
If you are working with fiscal years that end on June 30, you shoyuld be using Jun 30,
not Jul 01

This is how find out if you are past Jul 01 in a given year.

Code:
set serverout on size 1000000
DECLARE
    year   VARCHAR2(5):=NULL;
    mydate DATE:=NULL;
BEGIN
    DBMS_OUTPUT.enable(100000);
    year:=TO_CHAR(SYSDATE ,'YYYY');
    mydate:=TO_DATE('01-JUL-' || year);   
    IF TO_NUMBER(TO_CHAR(mydate,'J')) > TO_NUMBER(TO_CHAR(SYSDATE,'J'))
    THEN
       DBMS_OUTPUT.put_line('Today is before or equal to July 01');
    ELSE
       DBMS_OUTPUT.put_line('Today is after July 01');
    END IF;        
END;
/

You can also use the greatest() function to compare dates.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > triggering/DATE, month question


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 6 hosted by Hostway