Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Stripping non-printable characters from varchar2 column

Posted on 2004-09-03
9
Medium Priority
?
2,081 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup

876 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