delete non-ASCII characters [message #595217] |
Mon, 09 September 2013 08:06  |
 |
rc3d
Messages: 213 Registered: September 2013 Location: Baden-Württemberg
|
Senior Member |
|
|
In field APPLICATIONNAME are non ASCII characters. Howto delete them?
for example
old value:
new value:
table
CREATE TABLE MIDDLEWARE_CONT
(
APPLICATIONNAME VARCHAR2(120 BYTE),
PRODUCTNAME VARCHAR2(70 BYTE),
HOSTNAME VARCHAR2(60 BYTE),
VIRTUALHOST VARCHAR2(60 BYTE),
HARDWARENAME VARCHAR2(60 BYTE),
HWMODEL VARCHAR2(60 BYTE),
STANDORT VARCHAR2(60 BYTE),
STATUS VARCHAR2(60 BYTE),
OS VARCHAR2(60 BYTE),
OSVERSION VARCHAR2(60 BYTE)
)
SELECT count(REPLACE (
TRANSLATE (SUBSTR (APPLICATIONNAME, 1, 60),
CONVERT (SUBSTR (APPLICATIONNAME, 1, 60), 'us7ascii'),
'x'),
'x'))
non_ascii
FROM MIDDLEWARE_CONT
WHERE REPLACE (
TRANSLATE (SUBSTR (APPLICATIONNAME, 1, 60),
CONVERT (SUBSTR (APPLICATIONNAME, 1, 60), 'us7ascii'),
'x'),
'x') IS NOT NULL
result:
|
|
|
|
|
|
|
Re: delete non-ASCII characters [message #595233 is a reply to message #595232] |
Mon, 09 September 2013 09:18   |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
rc3d wrote on Mon, 09 September 2013 15:14
is there a placeholder ('abcdef<... and all the characters you want to keep>') for all ASCII chars? I can't list all the chars allowed.
Why not?
|
|
|
|
|
Re: delete non-ASCII characters [message #595236 is a reply to message #595231] |
Mon, 09 September 2013 09:46   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
rc3d wrote on Mon, 09 September 2013 19:42
non ascii char can be every where in text.
Ok, so I will edit my query per your requirement. Follow next part.
rc3d wrote on Mon, 09 September 2013 19:44
is there a placeholder ('abcdef<... and all the characters you want to keep>') for all ASCII chars? I can't list all the chars allowed.
Sure, using regular expression a bit of workaround could be avoided -
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE TABLE MIDDLEWARE_CONT ( APPLICATIONNAME VARCHAR2(120 BYTE));
Table created.
SQL>
SQL> insert into middleware_cont values('René');
1 row created.
SQL> insert into middleware_cont values('Löscher Bet');
1 row created.
SQL> insert into middleware_cont values('Summà Ira');
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> select * from middleware_cont;
APPLICATIONNAME
--------------------------------------------------------------------------------
René
Löscher Bet
Summà Ira
SQL>
SQL> select REGEXP_REPLACE(applicationname,'[^[a-z,A-Z,0-9,chr(0)-chr(127)[:spac
e:]]]*','') my_output from middleware_cont;
MY_OUTPUT
--------------------------------------------------------------------------------
Ren
Lscher Bet
Summ Ira
SQL>
So, since it works, you could update the table -
SQL> update middleware_cont set applicationname=REGEXP_REPLACE(applicationname,'
[^[a-z,A-Z,0-9,chr(0)-chr(127)[:space:]]]*','');
3 rows updated.
SQL> select * from middleware_cont;
APPLICATIONNAME
--------------------------------------------------------------------------------
Ren
Lscher Bet
Summ Ira
SQL>
[Updated on: Mon, 09 September 2013 10:00] Report message to a moderator
|
|
|
|
|
|
|
|
|