Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

V12 has introduced the possibility to initialize local variables within the DECLARE statement, such as

declare lCnt integer = 0;

Now it would be fine if one could declare constants, too, (like "const int" in C/C++ etc.). This would be handy for longer blocks of code, e.g. to name savepoints or name expressions that are used in several queries.

And it might make explicit that a variable like in this question cannot be changed unintentionally...

I don't know if constants are defined in the SQL standards, so I won't suggest a particular syntax.

asked 31 Oct '10, 21:08

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%


I like this idea and will discuss it with the SA development team for possible inclusion in a future release. Thanks for making the suggestion. As mentioned in Ivan's response to this question, the optimizer cannot use variable values when optimizing queries define within a stored procedure, but with the ability to mark a variable as constant (and if its value is, in fact, a constant) then there is the possibility that the optimizer could use the constant value at optimization time.

permanent link

answered 01 Nov '10, 21:08

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

Good news:) BTW, are named constants specified in the current SQL standards?

(01 Nov '10, 21:15) Volker Barth

I glanced through the SQL 2008 ANSI standard and could not see anything that allowed declaration of a variable as a constant.

(02 Nov '10, 15:08) Mark Culp
Comment Text Removed
Comment Text Removed

@Mark: As many PLs support the notion of a "constant" it's interesting that this seems uncommon w.r.t. SQL. – Well, that makes me consider this a "cutting-edge suggestion":)

(02 Nov '10, 15:59) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×113
×14
×3

question asked: 31 Oct '10, 21:08

question was seen: 2,859 times

last updated: 01 Nov '10, 21:08