Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL decode a column in table

How can I url decode a value in Oracle?

I have a URL encoded string stored in oracle DB table. I want to url_encode it while selecting the results. Any quick way to achieve this ?

like image 395
TopCoder Avatar asked Aug 27 '13 11:08

TopCoder


People also ask

How do you decode a space in a URL?

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

How do I decode a URL in SharePoint?

To decode SharePoint URLs, you can also use Online tools like: https://www.urldecoder.org.

What does URL decode do?

URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.


2 Answers

Oracle provides utl_url package containing two functions escape() and unescape() which allow you encode and decode urls. To decode an encoded url string http://www.%24-%26-%3C-%3E-%3F, for example, we can do the following:

SQL> select utl_url.unescape('http://www.%24-%26-%3C-%3E-%3F') as res
  2   from dual
  3  ;

Result:

RES
---------------------
http://www.$-&-<->-?

Note. If you need to use escape() function, you wont be able to use it in a select statement directly, because the second parameter of the function is of Boolean datatype. You will need to write a wrapper function.

SQL> create or replace function url_encode(p_url in varchar2)
  2  return varchar2
  3  is
  4  begin
  5    return utl_url.escape(p_url, true);
  6  end;
  7  /
Function created

SQL> 
SQL> select Url_encode('http://www.$-&-<->-?') as res
  2   from dual
  3  ;

Result:

RES
-------------------------------------
http%3A%2F%2Fwww.%24-%26-%3C-%3E-%3F
like image 94
Nick Krasnov Avatar answered Oct 07 '22 07:10

Nick Krasnov


This worked for me:

utl_url.unescape(replace('your text here', '+', ' '),'UTF-8')

like image 45
Oranit Dar Avatar answered Oct 07 '22 07:10

Oranit Dar