简体   繁体   中英

what is the difference between the & and : in PL/SQL in oracle?

I am stuying PL/SQL & I am going through the bind variable . I understood that the bind variable we used to pass RUN-TIME values.

but what is the difference between & and :(colon) in PL/SQL? both are same or is their any difference between this two? when should I use & and : ?

The & is used in SQL*Plus only, it has no meaning outside of it.

While SQL*Plus "parses" the input buffer, it replaces &variables with what they were define d to. See also this link and this link . The technical term is substitution variable .

On the other hand :variable are real bind variables. They are used when Oracle's SQL engine "parses" and executes the SQL statement. See for example this link or this link .

So, in short, &variables are replaced by SQL*Plus and then passed to Oracle's SQL engine, while :variables are left untouched by SQL Plus and passed to Oracle's SQL engine as they appear. Outside fo SQL Plus, & makes no sense.

& has no meaning in PL/SQL, it is actually a SQL Plus feature (that has been copied in Toad, SQL Developer etc. for compatibility). In SQL Plus, & is used to define a substitution variable , which is replaced with specified replacement text by SQL Plus before the code is sent to the server to be processed.

The correct syntax for a SQL Plus substitution variable is &name. ie is begins with a & and ends with a . , but in most situations the . is optional. So when you run this code in SQL Plus:

select * from emp where ename = '&name.';

SQL Plus prompts the user for a value for name and substitues this into the query before it is run. So if the user enters KING then the SQL actually run is:

select * from emp where ename = 'KING';

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