2

How do I enter a substitution variable such that it can be used multiple times throughout a SQL statement?

For example

SELECT '&X','&X',A       <--SEES X AS TWO DIFFERENT VARIABLES
FROM T; 

Sees each X as a different variable. How can I make it such that X is only one variable?

2
  • 1
    Alternatively, you can use a CTE or subquery so that only one reference is used, e.g. select x, x, a from t, (select '&X' as x from dual) Commented Aug 19, 2016 at 10:00
  • @JeffreyKemp thanks, helped me a lot! Commented Oct 4, 2017 at 11:44

1 Answer 1

5

If you mean you are prompted twice for a value for the same variable, use 2 ampersands instead of one for a permanent substitution variable instead of a temporary substitution variable. Here's an explanation of the difference: What is the difference between & and &&?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.