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, 10:27 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,255 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 15 h 14 m
Reputation Power: 17
Trigger help!

the table:
Code:
 create Table students (
student_no	NUMBER(8) CONSTRAINT pk_student_no Primary Key,
firstname     	Varchar2(15),
lastname	Varchar(20),
streetno	Varchar2(30),
city		varchar2(20),
postcode        varchar2(9),
phone		varchar2(15),
userid		char(5),
enrolment_date	date,
enrolment_year  number(4))
partition by range (enrolment_year)
(partition S1 values less than (2001) tablespace comp3_5 Storage (initial 1K Next 1K),
partition S2 values less than (2002) tablespace comp3_5 Storage (initial 1K Next 1K),

trigger
Code:
create or replace trigger calculateYearColumn 
after insert on Students

declare
	Y	varchar2(4);
	Y1	number(4);
begin
	select to_char(to_date(enrolment_date, 'YYYY-MM-DD'), 'YYYY') into Y from students;
	Y1:= to_number(Y);
        update students set enrolment_year = Y1;
end;
/


insert statement
Code:
Insert into students (student_no, firstname, lastname, streetno, city,postcode,phone,userid,enrolment_date)values(00022501,'S','A', '21 whatever','London','se118gf',02086545676,'as234','23-feb-2001')


trigger is created fine, but after i insert valuesit gives me the error:
Code:
ERROR at line 1:
ORA-14402: updating partition key column would cause a partition change
ORA-06512: at "AS234.CALCULATEYEARCOLUMN", line 7
ORA-04088: error during execution of trigger 'AS234.CALCULATEYEARCOLUMN' 

Last edited by paulh1983 : March 3rd, 2005 at 10:35 AM.

Reply With Quote
  #2  
Old March 3rd, 2005, 10:43 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,932 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 4 Days 1 h 3 m 50 sec
Reputation Power: 279
Are you writing this trigger just to automatically add a value for enrolment_year when the only (user) inputed value is enrolment_date?
Are you aware that a view is enough? And that it does put less strain on database?
And also, why did you partition the table just to put every partition on the same tablespace?

More questions to you:
Are you aware that you can partition this way (just an example):
partition p_1 values less than to_char(to_date(enrolment_date, 'YYYY-MM-DD'), 'YYYY') tablespace tblspace?
Are you aware that moving rows between partitions must be enabled? (I bet no on this one )
Code:
alter table tablename enable row movement;

Last edited by pabloj : March 3rd, 2005 at 10:49 AM.

Reply With Quote
  #3  
Old March 3rd, 2005, 11:21 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,255 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 15 h 14 m
Reputation Power: 17
trigger yeah i want to get the year from the enrolment date!

thanks, lol! erm i dunno i am just following (or trying to) follow a tutorial given to us by our teacher!

as for the tablespace, yeah you are right i am allowed access to TWO tablespaces and i should have put some partitions in one and some in other!

actually i was a little bit too excited, it doesnt work! i get the trigger is mutating!

is update and insert basically the same thing or different?

Last edited by paulh1983 : March 3rd, 2005 at 02:35 PM.

Reply With Quote
  #4  
Old March 4th, 2005, 03:27 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,932 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 4 Days 1 h 3 m 50 sec
Reputation Power: 279
For the mutate error read this
Insert adds a new row, update modifies an existing row or set of rows, you should really read some generic paper about relational databases if you have doubts of this kind.
If you can change your insert statement you don't need the trigger at all, just etxract the year as a number from the user input and put it in the appropriate column.
Code:
select to_number(to_char(to_date('1999-01-01', 'YYYY-MM-DD'), 'YYYY')) from dual

Reply With Quote
  #5  
Old March 6th, 2005, 10:18 AM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,255 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 15 h 14 m
Reputation Power: 17
u know what it is! it worked for the first row ie when i inserted the very first row, after that i got the "returns more row than expected"

and i have also tried the first solution on that link u gave me, i put everything the same except for table name and the actual trigger but it still aint working

Last edited by paulh1983 : March 6th, 2005 at 10:56 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Trigger help!


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
Stay green...Green IT