How to declare and use a variable in Aqua Data Studio querying an Oracle server

3.5k Views Asked by At

In Microsoft SQL Server

DECLARE @var INT
SET @var = 1
SELECT @var

What would the equivalent statement be in Aqua Data Studio when querying an Oracle server?

I've tried different variations of this (with GO or ; as statement separators, nothing has worked so far).

DECLARE var INTEGER 
SELECT var FROM DUAL
3

There are 3 best solutions below

1
On

I guess you can use variable binding, but it does have a different syntax. Try the below example query.

=== Query ===

.variable var1, VARCHAR, '10'
.variable var2, VARCHAR, '30'
.executeCallableQuery 'var1,var2',

select * from SCOTT.DEPT

More info here: https://www.aquaclusters.com/app/home/project/public/aquadatastudio/wikibook/Documentation14/page/196/Aqua-Commands

0
On

If you don't want to use Parameterized Scripts to declare a variable in Aqua Data Studio, try using the following:

declare var1 varchar(20) := 'Hello world!';
begin
    DBMS_OUTPUT.put_line(var1);
end;
0
On

use 'Parametrized Script' button in Query Analyzer. and var name with & in code:

select * from tabl where id = &id

More info: https://www.aquaclusters.com/app/home/project/public/aquadatastudio/wikibook/Documentation11/page/51/5-5-Parameterized-Scripts