If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > getting LTRIM and RTRIM to work

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-14-09, 13:18
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
getting LTRIM and RTRIM to work

My success rate to getting those to work is only .5%

what is a magic?

db2 "select rtrim(INDSCHEMA), rtrim(INDNAME), rtrim(COLNAME) from syscat.INDEXCOLUSE"
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #2 (permalink)  
Old 05-14-09, 14:18
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
does not work for me either. It works in concatenations though:

db2 "select rtrim(INDSCHEMA)||‘.’||rtrim(INDNAME)||’ ’||rtrim(COLNAME) from syscat.INDEXCOLUSE"
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS

Last edited by MarkhamDBA; 05-14-09 at 14:23.
Reply With Quote
  #3 (permalink)  
Old 05-14-09, 14:34
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Cool, that just might work for what I am looking to do with it.

Bella, can you shine a light on it why it works the way it works, and maybe you can ask your IBM friends to get it to work
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #4 (permalink)  
Old 05-14-09, 15:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I assume you problem is the display in the CLP still showing too long. The reason is that the column has a maximum length and that is what DB2 uses to return the column lengths. Doing rtrim has no visual effect. It would work in an application where the strings had trailing blanks.

Andy
Reply With Quote
  #5 (permalink)  
Old 05-14-09, 16:07
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Yes Andy,

I am using telnet and it will stay there. I guess it does not have to win a pageant contest
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #6 (permalink)  
Old 05-14-09, 16:19
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You can shorten up the fields this way, but it may cause some truncation:


db2 "select varchar(INDSCHEMA,30), varchar(INDNAME,30), varchar(COLNAME,30) from syscat.INDEXCOLUSE"


Andy
Reply With Quote
  #7 (permalink)  
Old 05-14-09, 16:50
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
truncation is the problem I can not afford. I am going with SUBSTR and giving plenty room to make sure that nothing will get cut.

Thank you.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #8 (permalink)  
Old 05-14-09, 18:54
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Пума,

The number of dashes in the column heading can't be trimed. CLP has no idea what the next column is going to be like. Since we don't know the length of the next column, we need to consider the maximum length so that the data is column-aligned properly. substr gives CLP a clear indication that the output will have a constant column length so it's able to align the output properly.
Reply With Quote
  #9 (permalink)  
Old 05-15-09, 02:42
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by Cougar8000
db2 "select rtrim(INDSCHEMA), rtrim(INDNAME), rtrim(COLNAME) from syscat.INDEXCOLUSE"
If it's a display problem, maybe the following will work?
Code:
db2 -x "select rtrim(INDSCHEMA), rtrim(INDNAME), rtrim(COLNAME) from syscat.INDEXCOLUSE"
(For me, on Linux, it works both with and without "-x".)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #10 (permalink)  
Old 05-15-09, 10:28
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
It is a display issue and no, -x did not work for me. Thank you.

Bella,

огромное спасибо
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #11 (permalink)  
Old 05-15-09, 13:24
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
you're welcome, Oлег
Reply With Quote
  #12 (permalink)  
Old 05-15-09, 16:22
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The -x doesn't help, of course, because the maximum length of the column doesn't change. And since DB2 tries to come up with a tabular output and because it doesn't know the longest of all values in the result, it has to stick with the maximum length.

Since you cannot tolerate truncation, you cannot use SUBSTR() because that would truncate the values if they are too long - and you wouldn't even get a warning on that.

What I would do in your case is this:
- ignore the issue - why do some spaces bother you?
- use some scripting language like Perl and its connectivity modules for DB2 and fetch the results regularly
- use "sed" or some other tool to remove multiple spaces:
Code:
db2 -x "..." | sed -e 's/  *//g'
Also note that if you have LOBs in your output, those will be truncated at 4K or 8K (I don't know which). The reason is simply that the DB2 won't be so stupid as trying to put 2GB to the console, which just takes a few hours to write all the dashes and the values - and no one could really do anything with this anyway.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #13 (permalink)  
Old 05-15-09, 16:33
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Knut,

I hear what you are saying as far as SUBSTR goes. I just refuse to accept that someone would generate a schema name longer then 15 char and tab or ind name longer then 50.

I was just trying to get the layout in a way that it would be easy to look at it, even so I would be doing further changes to it.

Your method did crossed my mind I was just trying to avoid it for some reason and get db2 to do it all. As it stands right now I will use your method if there is no royalty

Danke.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #14 (permalink)  
Old 05-15-09, 17:55
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
If you really want a "nice looking" tabular output, but with a minimum of useless spaces, you could use perl or sed to replace the inter-column spaces into TABs and load the resulting tab-separated file into Excel (or OpenOffice of course).
Or maybe even better, convert it to an HTML table and look at it with your favourite browser:
Code:
db2 -x "select '<tr><td>'.rtrim(INDSCHEMA)||'</td><td>'||rtrim(INDNAME)
     ||'</td><td>'||rtrim(COLNAME)||'</td></tr>' from syscat.INDEXCOLUSE" \
| perl -p -e "BEGIN{print '<html><body><table border=1>';}s/\s//g;
              END{print '</table></body></html>';}" > indexcoluse.html
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 05-15-09 at 20:14.
Reply With Quote
  #15 (permalink)  
Old 05-15-09, 18:12
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Cougar8000
Knut,

I hear what you are saying as far as SUBSTR goes. I just refuse to accept that someone would generate a schema name longer then 15 char and tab or ind name longer then 50.
I don't like such very restrictive limitations. I consider self-explaining and well-chosen names extremely important for maintenance and the times where disk space was not available and that's why you had to use short, cryptic identifiers have long passed.

Also, I think you are on very thin ice with your assumption refusal - especially since you also used the word "generate"...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On