Solved

Stripping non-printable characters from varchar2 column

Posted on 2004-09-03
9
2,062 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
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 125 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now