Help With Creating a Trigger

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

42 Replies - 1739 Views - Last Post: 10 September 2009 - 09:08 PM Rate Topic: -----

#16 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:07 PM

View PostMartyr2, on 10 Sep, 2009 - 08:00 PM, said:

Well do a process of elimination here. Take out the whole if else statement and see if the trigger still compiles with errors. If it does, then you have an error that isn't that whole big if statement. I would first remove the if else statement and insert the variable v_AdjGrossIncome straight into TaxReturns. See if that goes through smoothly first and then you can tackle the if else statement.

:)


Giving it a try now :) Thank you so much Martyr2!
Was This Post Helpful? 0
  • +
  • -

#17 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:15 PM

I think it may be copying and pasting from Notepad...getting an error on the simplest form of the trigger now. Let me try inputting it
Was This Post Helpful? 0
  • +
  • -

#18 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:33 PM

i've never heard of anyone using pl sql before anywayz..mysql ftw
Was This Post Helpful? 0
  • +
  • -

#19 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:34 PM

:( My fingers hurt now and the stupid Compile Error is still there...

I know! It sucks too, teacher just said "We're using PL/Sql" No one in class had used it at all...

This post has been edited by absynthe: 10 September 2009 - 07:35 PM

Was This Post Helpful? 0
  • +
  • -

#20 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:35 PM

Ok, now show us the simplified version you are using.
Was This Post Helpful? 0
  • +
  • -

#21 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:36 PM

Is the logic wrong? Is the if statement wrong you think?

CREATE OR REPLACE TRIGGER Tax_Return_Trigger
BEFORE UPDATE OF AdjGrossIncome
ON TaxReturns
FOR EACH ROW
DECLARE
v_TaxRate1 FLOAT := 0.00;
v_TaxRate2 FLOAT := 0.20;
v_TaxRate3 FLOAT := 0.30;
v_TaxRate4 FLOAT := 0.40;
v_TaxRate5 FLOAT := 0.50;
v_AdjGrossIncome NUMBER;
v_NewRate NUMBER;
BEGIN
SELECT AdjGrossIncome INTO v_AdjGrossIncome FROM TaxReturns;

END;
SHOW ERRORS
 /

This post has been edited by absynthe: 10 September 2009 - 07:38 PM

Was This Post Helpful? 0
  • +
  • -

#22 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:42 PM

Try now running a more simplified version....

CREATE OR REPLACE TRIGGER Tax_Return_Trigger
BEFORE UPDATE OF AdjGrossIncome
ON TaxReturns
FOR EACH ROW
DECLARE
v_AdjGrossIncome NUMBER;

BEGIN
SELECT AdjGrossIncome INTO v_AdjGrossIncome FROM TaxReturns;

END;



Does this compile without problem?
Was This Post Helpful? 1
  • +
  • -

#23 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:45 PM

View PostMartyr2, on 10 Sep, 2009 - 08:42 PM, said:

Try now running a more simplified version....

CREATE OR REPLACE TRIGGER Tax_Return_Trigger
BEFORE UPDATE OF AdjGrossIncome
ON TaxReturns
FOR EACH ROW
DECLARE
v_AdjGrossIncome NUMBER;

BEGIN
SELECT AdjGrossIncome INTO v_AdjGrossIncome FROM TaxReturns;

END;



Does this compile without problem?


Yes, that compliled perfectly :) Awesome! The first trigger I've seen done without errors.

Ill add some chunks to it to see where it breaks :)
Was This Post Helpful? 0
  • +
  • -

#24 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:46 PM

Ok, now step two is to add in your variables only. If it errors out it is because your variables are in the incorrect format. I suggest adding one tax rate variable first.
Was This Post Helpful? 1
  • +
  • -

#25 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:49 PM

Shit the first chunk I put in had errors? Even with FLOAT

CREATE OR REPLACE TRIGGER Tax_Return_Trigger
BEFORE UPDATE OF AdjGrossIncome
ON TaxReturns
FOR EACH ROW
DECLARE
v_AdjGrossIncome NUMBER;
v_TaxRate1 := 0.00;
v_TaxRate2 := 0.20;
v_TaxRate3 := 0.30;
v_TaxRate4 := 0.40;
v_TaxRate5 := 0.50;

BEGIN
SELECT AdjGrossIncome INTO v_AdjGrossIncome FROM TaxReturns;

END;
/


OOOPS let me try one at a time
Was This Post Helpful? 0
  • +
  • -

#26 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:51 PM

View Postabsynthe, on 10 Sep, 2009 - 06:34 PM, said:

:( My fingers hurt now and the stupid Compile Error is still there...

I know! It sucks too, teacher just said "We're using PL/Sql" No one in class had used it at all...


aww, lemme kiss that for ya :)..mwah, there better now ??
Was This Post Helpful? 1
  • +
  • -

#27 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:51 PM

What the hell? It immediately went into an error with the first Tax1 added.

From the looks of it here im right on with syntax:

http://www.java2s.co...talogPL-SQL.htm
Was This Post Helpful? 0
  • +
  • -

#28 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:52 PM

am pretty sure though that you need to declare the data types you are using
Was This Post Helpful? 0
  • +
  • -

#29 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:57 PM

It doesnt show it here though:

http://www.java2s.co...rmineagrade.htm
Was This Post Helpful? 0
  • +
  • -

#30 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Help With Creating a Trigger

Posted 10 September 2009 - 07:58 PM

mostyfriedman is right with the data type. Try using... v_TaxRate1 CONSTANT NUMBER(2,2) := 0.00;

Here we are defining a constant tax rate value of 0.00
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3