Home » SQL & PL/SQL » SQL & PL/SQL » Code to Convert English Names to Arabic (oracle 10g)
Code to Convert English Names to Arabic [message #503515] |
Sun, 17 April 2011 02:04  |
 |
shanie
Messages: 118 Registered: January 2011
|
Senior Member |
|
|
Hi,
I need Code or Procedure which can convert
English Names to Arabic Names in Oracle.
Like Given Student ID it fetch Student Name
But I need to Convert this name to Arabic.
Please share if you have any solution.
Regards,
Shanie
|
|
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503536 is a reply to message #503533] |
Sun, 17 April 2011 12:25   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
I don't know the Arabic alphabet or have your character set. What you can do is create a table with the letters of the English alphabet in one column and the corresponding letters of the Arabic alphabet in the other column, then create a function that will replace the letters one at a time. I have demonstrated below, using lower case letters instead of Arabic letters.
SCOTT@orcl_11gR2> create table english_arabic
2 (english varchar2 (1),
3 arabic nvarchar2 (4))
4 /
Table created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('M', 'm')
3 /
1 row created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('A', 'a')
3 /
1 row created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('R', 'r')
3 /
1 row created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('T', 't')
3 /
1 row created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('I', 'i')
3 /
1 row created.
SCOTT@orcl_11gR2> insert into english_arabic values
2 ('N', 'n')
3 /
1 row created.
SCOTT@orcl_11gR2> create or replace function english_to_arabic
2 (p_english in varchar2)
3 return nvarchar2
4 as
5 v_arabic nvarchar2 (4);
6 v_result nvarchar2 (4000);
7 begin
8 for i in 1 .. length (p_english) loop
9 select arabic
10 into v_arabic
11 from english_arabic
12 where english = substr (p_english, i, 1);
13 v_result := v_result || v_arabic;
14 end loop;
15 return v_result;
16 end english_to_arabic;
17 /
Function created.
SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select english_to_arabic ('MARTIN') from dual
2 /
ENGLISH_TO_ARABIC('MARTIN')
--------------------------------------------------------------------------------
martin
1 row selected.
SCOTT@orcl_11gR2>
|
|
|
|
|
|
|
|
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503763 is a reply to message #503716] |
Tue, 19 April 2011 10:01   |
manubatham20
Messages: 566 Registered: September 2010 Location: Seattle, WA, USA
|
Senior Member |

|
|
Hi All,
A lot of discussion on Google Translator. Well, as I earlier said that we can't use it in Business Applications. One can attach a POLL here for opinios about automatic translators.
Well, suppose if we stick to use that how we will integrate it with Oracle for translation?
[EDIT]
I just saw the post
Using internet translators from Oracle
Syakobson and Barbara discussed something over there, but I am unable to execute their codes, as I don't know head and tail of that code (means I am totally unaware of that package). Its giving the following error that its not declared. From where to install that package?
PLS-00201: identifier 'DBMS_NETWORK_ACL_ADMIN.CREATE_ACL' must be declared
PLS-00201: identifier 'DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL' must be declared
and '&' sign in url also causing some problem...
Thanks,
Manu
[Updated on: Tue, 19 April 2011 10:29] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503787 is a reply to message #503778] |
Tue, 19 April 2011 12:58   |
manubatham20
Messages: 566 Registered: September 2010 Location: Seattle, WA, USA
|
Senior Member |

|
|
Hi Michel,
I am currently using Oracle 10.2.0.3 and my character set is as follows-
SQL> SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;
VALUE$
--------------------------------------------------------------------
WE8MSWIN1252
I am unable to alter the database character set as the character set I am using is already the super set of the character set that I want to use, am I right?
SQL> connect system/manager
Connected.
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
ALTER DATABASE CHARACTER SET AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
As far as client is concerned, I tried the below-
SQL> select translation('I','HI','EN') from dual;
ERROR:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00217: invalid character 2350 (U+092E)
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at "SCOTT.TRANSLATION", line 41
ORA-06512: at line 1
on sqlplus on command prompt and by opening isqlplus on Opera.
I think, Opera supports Hindi, as I am able to see Google Translations for Hindi on Opera.
So why this error, does my OS doesn't support that Character Set or what?
Many Thanks,
Manu
[Updated on: Tue, 19 April 2011 12:59] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503796 is a reply to message #503794] |
Tue, 19 April 2011 13:39   |
manubatham20
Messages: 566 Registered: September 2010 Location: Seattle, WA, USA
|
Senior Member |

|
|
Below is my SQL session:
SQL> set define off
SQL> create or replace function translation
2 (p_words in clob, -- words to be translated
3 p_to in varchar2 default 'de', -- language to translate to (German)
4 p_from in varchar2 default 'en') -- language to translate from (English)
5 -- ar = Arabic
6 -- en = English
7 -- es = Spanish
8 -- fr = French
9 return clob
10 as
11 l_res clob;
12 l_words clob;
13 begin
14 l_res := httpuritype
15 ('http://translate.google.com/?hl=' ||
16 p_from || '&layout=1&eotf=1&sl=' || p_from ||
17 '&tl=' || p_to || '&text=' ||
18 utl_url.escape (p_words) || '#').getclob();
19 l_res := substr (l_res, instr (l_res, '<span title="' || p_words || '"'));
20 l_res := substr (l_res, 1, instr (l_res, '</span>') + 6);
21 l_words := XmlType (l_res).extract ('/span/text()').getStringVal();
22 return l_words;
23 end translation;
24 /
Function created.
SQL> show errors
No errors.
SQL> select translation ('cats and dogs') from dual;
TRANSLATION('CATSANDDOGS')
--------------------------------------------------------------------------------
Katzen und Hunde
SQL> select translation ('I Love You','de','en') from dual;
TRANSLATION('ILOVEYOU','DE','EN')
--------------------------------------------------------------------------------
Ich liebe dich
SQL> select translation ('I Love You','hi','en') from dual;
ERROR:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00217: invalid character 2350 (U+092E)
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at "SCOTT.TRANSLATION", line 21
ORA-06512: at line 1
no rows selected
SQL> spool off
Regards,
Manu
|
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503808 is a reply to message #503803] |
Tue, 19 April 2011 14:50   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
If the Hindi character set is not allowed in XML, then you could substitute the code using regexp_substr that Solomon provided in the other thread for the xml in the function that I provided as demonstrated below. Please try it and let us know if it works with Hindi.
SCOTT@orcl_11gR2> create or replace function translation
2 (p_words in clob, -- words to be translated
3 p_to in varchar2 default 'ar', -- language to translate to
4 p_from in varchar2 default 'en') -- language to translate from
5 -- ar = Arabic
6 -- en = English
7 -- es = Spanish
8 -- fr = French
9 return clob
10 as
11 l_res clob;
12 l_words clob;
13 begin
14 l_res := httpuritype
15 ('http://translate.google.com/?hl=' ||
16 p_from || '&layout=1&eotf=1&sl=' || p_from ||
17 '&tl=' || p_to || '&text=' ||
18 utl_url.escape (p_words) || '#').getclob();
19 l_words := regexp_substr
20 (l_res,
21 '<span id=result_box class="short_text"><span[^>]*>(.*)</span></span>',
22 1, 1, 'i', 1);
23 return l_words;
24 end translation;
25 /
Function created.
SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'es') from dual
2 /
TRANSLATION('CATSANDDOGS','ES')
--------------------------------------------------------------------------------
gatos y perros
1 row selected.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'fr') from dual
2 /
TRANSLATION('CATSANDDOGS','FR')
--------------------------------------------------------------------------------
les chats et les chiens
1 row selected.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'de') from dual
2 /
TRANSLATION('CATSANDDOGS','DE')
--------------------------------------------------------------------------------
Katzen und Hunde
1 row selected.
SCOTT@orcl_11gR2>
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503812 is a reply to message #503810] |
Tue, 19 April 2011 15:04   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Michel Cadot wrote on Tue, 19 April 2011 12:54
Solomon's code works only in 11g, OP is in 10g.
Are you sure? Regexp_substr was available in 10g. The ACL stuff is required in 11g, but not needed in 10g. In 10g, you just leave that part out.
Using the latest function that I posted above, I ran:
select translation ('I love you.', 'HI', 'EN') from dual
/
and got:
मैं तुमसे प्यार करता हूँ
When I copied and pasted that into google translate to translate it back to English, I got, "I love you." as seen in the link below.
http://translate.google.com/#hi|en|%E0%A4%AE%E0%A5%88%E0%A4%82%20%E0%A4%A4%E0%A5%81%E0%A4%AE%E0%A4%B8%E0%A5%87%20%E0%A4%AA%E0%A5%8D%E 0%A4%AF%E0%A4%BE%E0%A4%B0%20%E0%A4%95%E0%A4%B0%E0%A4%A4%E0%A4%BE%20%E0%A4%B9%E0%A5%82%E0%A4%81
[Updated on: Tue, 19 April 2011 15:05] Report message to a moderator
|
|
|
Re: Code to Convert English Names to Arabic [message #503814 is a reply to message #503812] |
Tue, 19 April 2011 15:16   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Substituting Solomon's code that uses regexp_substr for the xml in the function seems to work better with other character sets. Although the result in other character sets displays on my system as numbers and ampersands, when copied and pasted onto this site, it displays in the proper character set.
SCOTT@orcl_11gR2> create or replace function translation
2 (p_words in clob, -- words to be translated
3 p_to in varchar2 default 'ar', -- language to translate to
4 p_from in varchar2 default 'en') -- language to translate from
5 -- ar = Arabic
6 -- en = English
7 -- es = Spanish
8 -- fr = French
9 return clob
10 as
11 l_res clob;
12 l_words clob;
13 begin
14 l_res := httpuritype
15 ('http://translate.google.com/?hl=' ||
16 p_from || '&layout=1&eotf=1&sl=' || p_from ||
17 '&tl=' || p_to || '&text=' ||
18 utl_url.escape (p_words) || '#').getclob();
19 l_words := regexp_substr
20 (l_res,
21 '<span id=result_box class="short_text"><span[^>]*>(.*)</span></span>',
22 1, 1, 'i', 1);
23 return l_words;
24 end translation;
25 /
Function created.
SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select translation ('I love you.', 'HI', 'EN') from dual
2 /
TRANSLATION('ILOVEYOU.','HI','EN')
--------------------------------------------------------------------------------
मैं तुम्हें प्यार करता हूँ.
1 row selected.
SCOTT@orcl_11gR2>
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503824 is a reply to message #503820] |
Tue, 19 April 2011 23:35   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
You could just use substr and instr instead of regexp_substr, as shown below.
SCOTT@orcl_11gR2> set define off
SCOTT@orcl_11gR2> create or replace function translation
2 (p_words in clob, -- words to be translated
3 p_to in varchar2 default 'ar', -- language to translate to
4 p_from in varchar2 default 'en') -- language to translate from
5 -- ar = Arabic
6 -- de = German (Deutsch)
7 -- en = English
8 -- es = Spanish (Español)
9 -- fr = French (Français)
10 return clob
11 as
12 l_words clob;
13 begin
14 l_words := httpuritype
15 ('http://translate.google.com/?hl=' ||
16 p_from || '&layout=1&eotf=1&sl=' || p_from ||
17 '&tl=' || p_to || '&text=' ||
18 utl_url.escape (p_words) || '#').getclob();
19 l_words := substr (l_words, instr (l_words, '<span id=result_box class="short_text"><span'));
20 l_words := substr (l_words, instr (l_words, '>') + 1);
21 l_words := substr (l_words, instr (l_words, '>') + 1);
22 l_words := substr (l_words, 1, instr (l_words, '</span></span>') - 1);
23 return l_words;
24 end translation;
25 /
Function created.
SCOTT@orcl_11gR2> show errors
No errors.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'es') from dual
2 /
TRANSLATION('CATSANDDOGS','ES')
--------------------------------------------------------------------------------
gatos y perros
1 row selected.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'fr') from dual
2 /
TRANSLATION('CATSANDDOGS','FR')
--------------------------------------------------------------------------------
les chats et les chiens
1 row selected.
SCOTT@orcl_11gR2> select translation ('cats and dogs', 'de') from dual
2 /
TRANSLATION('CATSANDDOGS','DE')
--------------------------------------------------------------------------------
Katzen und Hunde
1 row selected.
SCOTT@orcl_11gR2> select translation ('I love you.', 'HI', 'EN') from dual
2 /
TRANSLATION('ILOVEYOU.','HI','EN')
--------------------------------------------------------------------------------
मैं तुम्हें प्यार करता हूँ.
1 row selected.
SCOTT@orcl_11gR2>
|
|
|
Re: Code to Convert English Names to Arabic [message #503831 is a reply to message #503824] |
Wed, 20 April 2011 00:45   |
manubatham20
Messages: 566 Registered: September 2010 Location: Seattle, WA, USA
|
Senior Member |

|
|
Hi,
Thanks, now I can execute the function for Hindi as well. But its showing me output as follows-
SQL> select translation ('cats and dogs','hi','en') from dual;
TRANSLATION('CATSANDDOGS','HI','EN')
----------------------------------------------------------------
बिल्लियों और & <-- I wrote here some number with & like & # 2348; & # 2367
(I putted space between & and # and number because
its automatically converting them to characters here.)
I am getting some numbers followed by &# sign, but when I posting those numbers here, Its automatically gets converting into Hindi characters. I just want to know, which settings needs to be changed.
Thanks,
Manu
[Updated on: Wed, 20 April 2011 00:55] by Moderator Report message to a moderator
|
|
|
|
Re: Code to Convert English Names to Arabic [message #503913 is a reply to message #503836] |
Wed, 20 April 2011 06:22   |
 |
shanie
Messages: 118 Registered: January 2011
|
Senior Member |
|
|
I am using database 1og
Though the function is created but I got errors
while running the statement
select translation ('cats and dogs') from dual;
ERROR:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1674
ORA-12541: TNS:no listener
ORA-06512: at "SYS.HTTPURITYPE", line 34
ORA-06512: at "SYS.TRANSLATION", line 14
ORA-06512: at line 1
set define off
create or replace function translation
(p_words in clob, -- words to be translated
p_to in varchar2 default 'de', -- language to translate to (German)
p_from in varchar2 default 'en') -- language to translate from (English)
-- ar = Arabic
-- en = English
-- es = Spanish
-- fr = French
return clob
as
l_res clob;
l_words clob;
begin
l_res := httpuritype
('http://translate.google.com/?hl=' ||
p_from || '&layout=1&eotf=1&sl=' || p_from ||
'&tl=' || p_to || '&text=' ||
utl_url.escape (p_words) || '#').getclob();
l_res := substr (l_res, instr (l_res, '<span title="' || p_words || '"'));
l_res := substr (l_res, 1, instr (l_res, '</span>') + 6);
l_words := XmlType (l_res).extract ('/span/text()').getStringVal();
return l_words;
end translation;
/
Function created.
Regards
Shanie
|
|
|
Goto Forum:
Current Time: Fri May 16 06:01:53 CDT 2025
|