| |
|
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.
|
 |
|

05-14-09, 13:18
|
|
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
|
|

05-14-09, 14:18
|
|
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.
|

05-14-09, 14:34
|
|
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
|
|

05-14-09, 15:16
|
|
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
|
|

05-14-09, 16:07
|
|
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
|
|

05-14-09, 16:19
|
|
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
|
|

05-14-09, 16:50
|
|
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
|
|

05-14-09, 18:54
|
|
∞∞∞∞∞∞
|
|
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.
|
|

05-15-09, 02:42
|
|
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/
|
|

05-15-09, 10:28
|
|
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
|
|

05-15-09, 13:24
|
|
∞∞∞∞∞∞
|
|
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
|
|
you're welcome, Oлег 
|
|

05-15-09, 16:22
|
|
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
|
|

05-15-09, 16:33
|
|
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
|
|

05-15-09, 17:55
|
|
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.
|

05-15-09, 18:12
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|