Escape Character for &

I am writing following Program to Access HTTP url

DECLARE
  req   utl_http.req;
  resp  utl_http.resp;
  value VARCHAR2(1024);
  URL VARCHAR2(1024);
BEGIN
  url := 'http://10.202.12.17:8080/login.asp?user=XYZ&pass=yzx123';
  req := utl_http.begin_request(url);
  utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
  resp := utl_http.get_response(req);
  LOOP
    utl_http.read_line(resp, value, TRUE);
    dbms_output.put_line(value);
  END LOOP;
  utl_http.end_response(resp);
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
END;


in this Program I need Escape Character for & at line
  url := 'http://10.202.12.17:8080/login.asp?user=XYZ&pass=yzx123';

when I run the code it asks
Enter value for pass:

Instead & is part of string

Thanks in advance

LVL 2
rahulbagalAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MohanKNairConnect With a Mentor Commented:
DECLARE
  req   utl_http.req;
  resp  utl_http.resp;
  value VARCHAR2(1024);
  URL VARCHAR2(1024);
  v_amp char(1) := chr(38);
BEGIN
  url := 'http://10.202.12.17:8080/login.asp?user=XYZ'||v_amp||'pass=yzx123';
............


0
 
oogoogliesCommented:
Hi

Are you running this from SQL Plus? If so you can set the enviroment variables. Try set define off

Thanks
0
 
Ivo StoykovCommented:
Hello rahulbagal,

one of the solutions is to concatenate the string - i.e.

variable url varchar2;
exec :url := 'http://10.202.12.17:8080/login.asp?user=XYZ' || '&' || 'pass=yzx123';
print url;
url
---------
http://10.202.12.17:8080/login.asp?user=XYZ&pass=yzx123

HTH

I
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sathyagiriCommented:
Either set define off

Or set escape off
 url := 'http://10.202.12.17:8080/login.asp?user=XYZ\&pass=yzx123';

should work for you
0
 
neo9414Commented:
you can also use

set scan off

0
 
Ivo StoykovCommented:
Hi rahulbagal,

you could use
set define off before DECLARE

and
set define on
after END;

regards

I
0
 
rahulbagalAuthor Commented:
Thanks a lot
this works in SQL plus  
How can I use it in toad ..
I am planning to execute this code in a trigger
0
 
oogoogliesCommented:
rahulbagal

If you are going to use it as a storwed proc or part of a trigger the best solution would be the concant shown above.
0
 
GGuzdziolCommented:
You can always concat with CHR(38)...
0
 
Ivo StoykovCommented:
Hi rahulbagal,

escape it with '\&', i.e.
url := 'http://10.202.12.17:8080/login.asp?user=XYZ\&pass=yzx123';

regards

I
0
 
actonwangCommented:
>>How can I use it in toad ..
    I think that you don't need to do anything in toad for this.

    & is just for sql*plus variable.
0
 
rahulbagalAuthor Commented:
Thanks a lot that worked perfectly
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.