Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does this function follow ansi sql standard? 1

Status
Not open for further replies.

jm89

Programmer
Dec 20, 2012
2
0
0
GB
Hi,

I was wondering if anyone can tell me if this function follows ANSI SQL standard, and for future reference are there any resources that i can use to find if my SQL conforms to ANSI standards. And the DBMS i am using is MySQL.

CREATE FUNCTION INCREMENT()
RETURNS INT
BEGIN
DECLARE old INT;
DECLARE new INT;
SELECT current INTO old FROM table FOR UPDATE;
SET new=old +1;
UPDATE table SET current=new;
RETURN new;
END;

Thanks.

 
old, new and current are reserved words.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply PHV, i wont actually use those variable names, besides that does it conform to ANSI.

 
Does the table always contain exactly one row? If not, a cursor is needed! (Or a where clause that restricts the result set to one row...)

You may also have to specify access mode to allow the table update:

[tt]CREATE FUNCTION INCREMENT()
RETURNS INT
MODIFIES SQL DATA
BEGIN
...[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top