Help wanted with SQL syntax
<div class="IPBDescription">In stored procedures specifically</div>So me and my teammates are doing an assignment, but have run into a little problem with the syntax. Semicolons have to be put in strange places and linebreaks (without semicolons) actually make a difference. We're forced to guess our way through the construction of the procedures, which is obviously not good. The following bit actually works, but it looks like hell and doesn't help us with the later questions in the assignment:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->create procedure
Deposit(in aamount integer, anumber integer)
modifies sql data
BEGIN
if( aamount >= 0) then
update account
set balance = balance+aamount
where number = anumber
else
; end if
; END;<!--c2--></div><!--ec2-->
Moving the semicolons so they appear in more reasonable places breaks the code. Same with removing the else, but that might be normal for SQL.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->create procedure
Deposit(in aamount integer, anumber integer)
modifies sql data
BEGIN
if( aamount >= 0) then
update account
set balance = balance+aamount
where number = anumber
else
; end if
; END;<!--c2--></div><!--ec2-->
Moving the semicolons so they appear in more reasonable places breaks the code. Same with removing the else, but that might be normal for SQL.
Comments
Edit: What type of database, that is.
I have to ask... does the whitespace matter for the semicolon under else (<img src="style_emoticons/<#EMO_DIR#>/wink-fix.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink-fix.gif" /> end if?
Does it matter if it's something like
else
;
end if
That looks very reasonable to me, considering that the semi-colon could be used to indicate that it is at the end of the else statement. Dunno... maybe the if statement needs one too?
I'll expect something like...
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if( aamount >= 0) then
update account;
set balance = balance+aamount
where number = anumber;
else
;
end if<!--c2--></div><!--ec2-->
But that's just the theory of languages... we do really need to know what kind of database this is.
Edit: What type of database, that is.<!--QuoteEnd--></div><!--QuoteEEnd-->
Damn, I knew I forgot something.
Mimer.
update account
set balance = balance+aamount
where number = anumber;
else
;
end if<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd-->I can't say for 100% sure without trying it in the lab room but I don't think that would work. Linebreaks weren't accepted without a semicolon at the end.
EDIT: Nope. Semicolon after anumber:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->MIMER/DB error -12740 in function PREPARE
Syntax error, <end> assumed to mean; END IF; END <end><!--c2--></div><!--ec2-->
Even removing the linebreaks leaves error:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->create procedure
Deposit(in aamount integer, anumber integer)
modifies sql data
BEGIN
if( aamount >= 0) then
update account
set balance = balance+aamount
where number = anumber; else end if; END;
8: 1
MIMER/DB error -12740 in function PREPARE
Syntax error, end assumed to mean CALL <identifier> ( ); end
SQL><!--c2--></div><!--ec2-->