0

I am just trying to simply declare a variable with a default value that I will then use elsewhere in my script. I have tried:

Declare @datasource varchar(10) default 'ABC';
Declare datasource varchar(10) default 'ABC';

I have even tried simply:

 Declare @datasource varchar(10);

It fails with a SQL Error [1064] every time. I'm using DBeaver. What am I missing?

Wrapped the declare in a procedure. Still get the syntax error.

delimiter //
create procedure CleanPCB()
   begin 
     declare @datasource varchar(10) default 'ABC';
   end //
delimiter ;
muncieharts
  • 13
  • 1
  • 5
  • you need a function or procedure to declare variables – nbk Mar 18 '22 at 17:53
  • I wrapped the same commands in a procedure. Same result. I'll add the completed code to the question. – muncieharts Mar 18 '22 at 18:10
  • Try: `set @datasource = 'ABC'; select @datasource;` as mentioned in [How to declare a variable in MySQL?](https://stackoverflow.com/questions/11754781/how-to-declare-a-variable-in-mysql) – Luuk Mar 18 '22 at 18:15
  • BTW: That is how it's used in the docs too, see: https://dev.mysql.com/doc/refman/8.0/en/set-variable.html – Luuk Mar 18 '22 at 18:16
  • @muncieharts remove the add variable, read the duplicate link it is very comprehensive – nbk Mar 18 '22 at 18:25
  • Three tips, please follow all three: You must not use `@` for variables when you use `DECLARE`. `DECLARE` can be used only within a `BEGIN...END` block. It must be the first statement after the first `BEGIN`. – Bill Karwin Mar 18 '22 at 20:16

0 Answers0