0

I have defined a variable in sql script as below:

DEFINE USER_NAME="TEST_DB";
DEFINE PASSWORD="abc";

Now in my script I have few sql statement where I can use above variable with &USER_NAME and it's serve my purpose. Now I have PL SQL block also:

DECLARE
BEGIN
CONST_MASTER_USER varchar2(100) := 'TEST_DB';
-- FEW CODE
END

Now I want to use USER_NAME variable in this PL/SQL Block, but when I replace 'TEST_DB' with &USER_NAME, SQL Developer gives me following error:

PLS-00201: identifier 'TEST_DB' must be declared

As I am not expert in SQL, do we have any solution where we can define a variable once and use it in SQL as well as PLSQL statements?

1 Answer 1

3

It sounds like you removed the quotes, which are still needed with substitution variables:

DECLARE
   CONST_MASTER_USER varchar2(100) := '&USER_NAME.';
BEGIN
-- FEW CODE
END
2
  • Thanks @tony...! Can you please tell me why we need to put . (dot) after the variable name? Commented Aug 7, 2019 at 4:29
  • It is optional here but I always do it as it is sometimes necessary to avoid ambiguity e.g. '&VAR.XXX' versus &VARX.XX' Commented Aug 7, 2019 at 10:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.