简体   繁体   中英

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

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

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

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM