I want to write a single string of multiple SQL statements, to be sent through ODBC, which has constants stated as 'variables' to improve legibility/maintenance. I believe I need to use the DECLARE block. I do not want to write a procedure or a function, it's an ad-hoc query.
The following test CTE works fine in isolation (without a begin/end block):
WITH X AS ( SELECT 'HELLO' from DUAL ) SELECT * FROM X;
But when I run this
declare
badgerId CHAR(32); /*todo, use me later, a few times within multiple CTEs*/
begin
WITH X AS ( SELECT 'HELLO' from DUAL ) SELECT * FROM X;
end;
I get the error:
Error starting at line 2 in command:
declare
badgerId CHAR(32); /*todo, use me later*/
begin
WITH X AS ( SELECT 'HELLO' from DUAL ) SELECT * FROM X;
end;
Error report:
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What is this gibberish? In SQL Server I can just type.
DECLARE @badgerId CHAR(32);
at any time in the SQL statement, which is awesome. What's the Oracle equivalent?
Cheers!