PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Problem creating a Trigger
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Problem creating a Trigger

Réponse
 
LinkBack Outils de la discussion
Vieux 06/09/2007, 14h00   #1
anniyan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problem creating a Trigger


Hi all,

When I am trying to create a trigger I get an error message which I am
unable to comprehend.

create trigger updatepricech
after insert on tbl_prices for each row
BEGIN
DECLARE closep INTEGER;


select close into closep from temptable where Ticker = new.Ticker;
update tbl_prices set PriceCh = (Close - closep) where Ticker = new.Ticker
and Trade_date = new.Trade_date;
end;


I get the error :

#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ''
at line 4

Here line 4 is the declaration part.

Can you please let me know what could be wrong in this query?
--
View this message in context: http://www.nabble.com/Problem-creati...html#a12522149
Sent from the MySQL - General mailing list archive at Nabble.com.

  Réponse avec citation
Vieux 06/09/2007, 14h43   #2
Rolando Edwards \
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem creating a Trigger

Did you remember to switch your SQL delimiter ?

MySQL default delimter for SQL is the semicolon ( ; )
MySQL's stored procedure language also uses the semicolon to delimter statements.

These two rules cannot peacefully coexist.
You can get around this in three steps:

1) Change you default SQL limiter to $$
2) Create the Stored Procedure using END $$ instead of END;
3) Change you default SQL limiter back to ;

Like This:

DELIMITER $$
create trigger updatepricech
after insert on tbl_prices for each row
BEGIN
DECLARE closep INTEGER;
select close into closep from temptable where Ticker = new.Ticker;
update tbl_prices set PriceCh = (Close - closep) where Ticker = new.Ticker
and Trade_date = new.Trade_date;
END $$
DELIMITER ;

Hey, give it a try !!!

anniyan <sriram.s@hcl.in> wrote:

Hi all,

When I am trying to create a trigger I get an error message which I am
unable to comprehend.

create trigger updatepricech
after insert on tbl_prices for each row
BEGIN
DECLARE closep INTEGER;


select close into closep from temptable where Ticker = new.Ticker;
update tbl_prices set PriceCh = (Close - closep) where Ticker = new.Ticker
and Trade_date = new.Trade_date;
end;


I get the error :

#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ''
at line 4

Here line 4 is the declaration part.

Can you please let me know what could be wrong in this query?
--
View this message in context: http://www.nabble.com/Problem-creati...html#a12522149
Sent from the MySQL - General mailing list archive at Nabble.com.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=r..._dba@yahoo.com




---------------------------------
Building a website is a piece of cake.
Yahoo! Small Business gives you all the tools to get online.
  Réponse avec citation
Vieux 06/09/2007, 15h24   #3
anniyan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem creating a Trigger


Hi,
Thank you so much for the prompt response. Those comments were good to be
kept in mind always.
I actually realised the mistake I was making as soon as I posted the problem
here. So I managed the solve the problem.
However I have another problem which I need your ideas.
I have a table where prices for a few stock tickers are inserted. I have
another temp table which holds the prices for the max trade date. I have a
trigger which updates the temp table when there is a an insert into the main
prices table. This makes sure that I have the latest data for all the
tickers in the temp table.

Now I have a column called pricechange. I would like to calculate the
difference between pevious close price and today's close price in that
column. So theoretically speaking after the insert of new prices in the
prices table and I would like a trigger that will update the pricechange
with the price difference.
But I am unable to do it.

DBD::mysql::st execute failed: Can't update table 'tbl_prices' in stored
functio
n/trigger because it is already used by statement which invoked this stored
func

pls advice
--
View this message in context: http://www.nabble.com/Problem-creati...html#a12523666
Sent from the MySQL - General mailing list archive at Nabble.com.

  Réponse avec citation
Vieux 06/09/2007, 15h34   #4
Martijn Tonies
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem creating a Trigger

Hi,

> However I have another problem which I need your ideas.


It's better to create a new thread when you want to discuss a new
problem.

> I have a table where prices for a few stock tickers are inserted. I have
> another temp table which holds the prices for the max trade date. I have a
> trigger which updates the temp table when there is a an insert into the

main
> prices table. This makes sure that I have the latest data for all the
> tickers in the temp table.
>
> Now I have a column called pricechange. I would like to calculate the
> difference between pevious close price and today's close price in that
> column. So theoretically speaking after the insert of new prices in the
> prices table and I would like a trigger that will update the pricechange
> with the price difference.
> But I am unable to do it.
>
> DBD::mysql::st execute failed: Can't update table 'tbl_prices' in stored
> functio
> n/trigger because it is already used by statement which invoked this

stored
> func


Welcome to MySQLs half-assed trigger implementation ;-)

Can you do this from the first trigger that updates the temp table (inserts
the items?) instead?

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h41.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10409 seconds with 12 queries