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 October 28th, 2009, 02:33 PM
RyanS1 RyanS1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 2 RyanS1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
Help needed in creating trigger

I have couple of questions. I need to create 3 triggers in all.

First trigger works. i've created this trigger under TABLE_1. variables, OUTDATE, INDATE, COUNT_1 already exist. The code is as follows:
--------------------------------------------------------
TRIGGER EMP."CASE1" BEFORE
INSERT
OR UPDATE ON "EMP"."TABLE_1" FOR EACH ROW
DECLARE
C NUMBER;
BEGIN
C:= EMP.case_1 (:OLD.OUTDATE, :OLD.INDATE);
if
((:old.INDATE is not null) and
(:old.OUTDATE is null)) or
(C<0)
then
:new.COUNT_1:=0;
else

:new.COUNT_1:=C;
end if;
end;
--------------------------------------------------------

As for the second trigger, i want to be able to do something very similar, except the 2 dates in the function case_2 will be coming from a TABLE_2 such as RET1, RET2, but COUNT_2 is on TABLE_1. I'm not sure how to call a function with variables from a different table.

--------------------------------------------------------
TRIGGER EMP."CASE1" BEFORE
INSERT
OR UPDATE ON "EMP"."TABLE_1" FOR EACH ROW
DECLARE
C NUMBER;
BEGIN
C:= EMP.case_2 (:OLD.RET1, :OLD.RET2); //RET1 & RET2 ARE IN TABLE_2.
if
((:old.RET1 is not null) and
(:old.RET2 is null)) or
(C<0)
then
:new.COUNT_2:=0; //COUNT_2 IS IN TABLE_1
else

:new.COUNT_2:=C;
end if;
end;
--------------------------------------------------------

As for case 3, i've created a function and called that function into a view. I would like to know if it is possible to call a view into a trigger.

Any help is appreciated.

Thank you.

Last edited by pabloj : October 29th, 2009 at 01:00 PM.

Reply With Quote
  #2  
Old October 30th, 2009, 06:34 AM
debasisdas's Avatar
debasisdas debasisdas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Bangalore, India
Posts: 153 debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level)debasisdas User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 23 h 25 m 22 sec
Reputation Power: 115
Send a message via ICQ to debasisdas Send a message via AIM to debasisdas Send a message via MSN to debasisdas Send a message via Yahoo to debasisdas Send a message via Google Talk to debasisdas Send a message via Skype to debasisdas
Bebo Facebook MySpace Orkut
When the trigger fires on the base table it will automatically affect the data in the dependent tables. If you want specifically for a view define a instead of trigger.

Reply With Quote
  #3  
Old October 30th, 2009, 11:13 PM
clivew clivew is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 1,170 clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 6 Days 8 h 3 m 20 sec
Reputation Power: 272
First get rid of all those quotes round names. They force Oracle to treat them as case sensitive and are a real "honey trap" for bugs.

Quote:
C:= EMP.case_2 (:OLD.RET1, :OLD.RET2); //RET1 & RET2 ARE IN TABLE_2.


You have not retrieved RET1 & RET2 form anywhere.
You will, I presume, need a select query to fetch them.

Clive

Reply With Quote
  #4  
Old November 3rd, 2009, 11:29 AM
RyanS1 RyanS1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 2 RyanS1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 40 sec
Reputation Power: 0
Question i've explained it better here

Hi all,
In order to create this trigger, i've created a function to calculate and return business days.
---------------------------------------------------------------------------
FUNCTION CME.CASE_1 (start_date IN CME_ROUT.BFDATE%TYPE, end_date IN CME_ROUT.RETDATE%TYPE)
---------------------------------------------------------------------------

then, i've created a view that calls the above function as follows
---------------------------------------------------------------------------
VIEW CME.TESTCASE_1 (DOC, BUS) AS
SELECT a.docket, SUM(CME.CASE_1(b.BFDATE, b.RETDATE)) AS BUS
from CME.CME_MASTER a, CME.CME_ROUT b
where a.masid = b.masid and
a.closed is not null and
bfdate is not null and
b.retdate > b.bfdate
group by a.docket
---------------------------------------------------------------------------

Since i can't call the above view into a trigger, i'll need to create a procedure and in turn call that procedure into the trigger.

This is what i need to do.
i will need to compare if DOC from the view is equal to the DOC from CME_MASTER table, then if so i would need to put the BUS from the view into field5 in the CME_MASTER table.

this is what i have for procedure, i'm not sure if this is correct nor how to call this procedure into the trigger and make it work.
-------------------------------
procedure CME.CREATE_PROC
AS bus1 number;
begin
select b.bus
into bus1 from CME.CME_MASTER a, CME.TESTCASE_1 b
where a.doc = b.doc;
end;
------------------------------

Please help.
Thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Help needed in creating trigger


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek