Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stripping non-printable characters from varchar2 column

Posted on 2004-09-03
9
Medium Priority
?
2,075 Views
Last Modified: 2008-01-09
I am storing all the sql generated by Informatica PowerMart ETL tool and the sql is being stored with chr(10) and chr(13) in it causing ugly viewing.  I'd like to strip that out for easy viewing.

Here is an example:

SELECT DISTINCT HRA_QUESTIONNAIRE.HEALTH_RELATED_ACTIVITY_ID

FROM

 HRA_QUES_ANSWER_HISTORY, HRA_Q

I've reviewed some of the other answers related to this topic and having found what I need or am not understanding how it works.   Can somebody show me how to strip those two characters, maybe replacing them with spaces, and leave the rest of the text?

0
Comment
Question by:DonFreeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Expert Comment

by:pratikroy
ID: 11972844
There could be different ways of doing this. Tell us how do you wish to do it ?

You can use grep, awk, sed or write a program in C, perl etc to get rid of blank lines from a file. Depends on how and where you have stored this SQL file.
0
 
LVL 9

Accepted Solution

by:
pratikroy earned 500 total points
ID: 11972882
oops ... did'nt see tha you have this stored in a varchar2 column.

well, if you just wish to ignore the chr(10) and chr(13) you can do this :

SQL> desc TAB_CHARS
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 MYFLD                                              VARCHAR2(10)

SQL> select * from TAB_CHARS;

MYFLD
----------
120
180
1700
SEED

SQL> insert into TAB_CHARS values ('abc' || chr(10) || 'def');

1 row created.

SQL> insert into TAB_CHARS values ('ghi' || chr(13) || 'jkl');

1 row created.

SQL> select * from TAB_CHARS;

MYFLD
----------
abc
def

jkl
120
180
1700
SEED

6 rows selected.

SQL> select translate(MYFLD,chr(13)||'A', 'A') from select translate(MYFLD,chr(13)||'^C

SQL>
SQL> select translate(MYFLD,chr(13)||chr(10)||'A','A') from TAB_CHARS;

TRANSLATE(
----------
abcdef
ghiAjkl
120
180
1700
SEED

6 rows selected.

Hope this helps!
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11972901
I just got rid of the special characters, but if you wish to convert them to a space character (which I think you would want), then do this :

SQL> select translate(MYFLD,chr(13)||chr(10)||'A', '  A') from TAB_CHARS;

TRANSLATE(
----------
abc def
ghi jkl
120
180
1700
SEED

6 rows selected.

Hope this helps!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:erhanyayli
ID: 11972913
Hi

You may use replace function to eliminate unwanted characters

Below should omit char(10+13)

select replace(replace(string, chr(10)),chr(13)) from dual

Regards,
Erhan
0
 
LVL 4

Expert Comment

by:mottor
ID: 11973084
pratikroy,

You can alo delete 'A':
select translate(MYFLD,chr(13)||chr(10), '  ') from TAB_CHARS;
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11973244
true :))
0
 
LVL 1

Author Comment

by:DonFreeman
ID: 11973340
I'm not getting consistent results.

The two chrs come in pairs.
There is a pair of chr(13)||chr(10) at the end of each of these lines

SELECT HEALTH_RELATED_ACTIVITY.HEALTH_RELATED_ACTIVITY_ID
FROM
 HEALTH_RELATED_ACTIVITY
WHERE

0
 
LVL 1

Author Comment

by:DonFreeman
ID: 11973425
This got it. Thanks everybody!

SELECT TRANSLATE(SUBSTR(SQL_STATEMENT_TEXT,1,100),CHR(13)||CHR(10),' ') FROM RPT_SQL_STATEMENTS WHERE ROWID='AAA1IpAATAAABEeAE/';

TRANSLATE(SUBSTR(SQL_STATEMENT_TEXT,1,100),CHR(13)||CHR(10),'')
----------------------------------------------------------------------------------------------------
SELECT HEALTH_RELATED_ACTIVITY.HEALTH_RELATED_ACTIVITY_ID  FROM  HEALTH_RELATED_ACTIVITY  WHERE
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 11973946
Glad your problem is solved !! Cheers !
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question