[This topic is migrated from our old forums. The original author name has been removed]
I'm familiar with substitution variables in DbVisualizer and have used them in my scripts. I'm not a fan, though, of having long variable definition statements embedded in my SQL statements, or of the way that variable definitions get scattered all over long SQL statements. I was wondering if it would be possible to have a new command for defining one or more variables? I could then define my substition variables at the top of the script and just reference the definitions within the script. For example:
+-- Variable definitions (comma-separated):+
+@definevars ${ myvar1 || var1default || String || }$,+
+${ myvar2 || 99 || Integer || noshow }$,+
+${ myvar3 || 1999-01-30 || Date || }$+
+;+
+SELECT *+
+FROM mytable t+
+WHERE t.char_field = ${myvar1}+
+AND t.number_field = ${myvar2}+
+AND t.date_field = ${myvar3}+
Ugh. Wish the forum had support for code blocks.
Hi Steve,
We may add a @define command at some point, but you can accomplish the same thing today with the @echo command. A variable is "defined" when it is first used, so replacing @definevars in your example with @echo should work fine.
Best Regards,
Hans
a
anonymous
said
about 11 years ago
[This reply is migrated from our old forums. The original author name has been removed]
Re: Command to define variables
> {quote:title=Hans Bergsten wrote:}{quote}
>We may add a @define command at some point, but you can accomplish the same thing today with the @echo command. A variable is "defined" when it is first used, so replacing @definevars in your example with @echo should work fine.
Not quite as elegant but yes, I imagine that should work.
Thanks Hans.
a
anonymous
said
about 11 years ago
[This reply is migrated from our old forums. The original author name has been removed]
Re: Command to define variables
I can't seem to make this work on the command line using Oracle. Here's the simple example that I tried:
@echo ${ ROWNUMS || 50 || Integer }$;
SELECT * from mytable where rownum
a
anonymous
said
about 11 years ago
[This reply is migrated from our old forums. The original author name has been removed]
Re: Command to define variables
> {quote:title=Andrew wrote:}{quote}
> I can't seem to make this work on the command line using Oracle. Here's the simple example that I tried:
>
> @echo ${ ROWNUMS || 50 || Integer }$;
>
> SELECT * from mytable where rownum
> Any help is appreciated.
You're missing a '$' at the end of your SELECT statement. It should be:
SELECT * from mytable where rownum
anonymous