Hi,
In COBOL-SQL program, while inserting data into a VARCHAR field, is it necessary to populate the length host variable, before insert?
Is not it that DB2 automatically stores the length?
VARCHAR considerations in DB2.
-
- Registered Member
- Posts: 19
- Joined: Wed Aug 20, 2014 5:24 pm
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: VARCHAR considerations in DB2.
Hi Ankit,
Db2 automatically pads for the whole length and does not save space , which is not needed and also breaks the purpose of having a varchar field ...
So it is better to pass the length of the data before inserting into the table
Db2 automatically pads for the whole length and does not save space , which is not needed and also breaks the purpose of having a varchar field ...
So it is better to pass the length of the data before inserting into the table
zprogrammer
-
- Registered Member
- Posts: 19
- Joined: Wed Aug 20, 2014 5:24 pm
Re: VARCHAR considerations in DB2.
What re you telling here Pandora-Box, sorry I did not get you?Pandora-Box wrote:Db2 automatically pads for the whole length and does not save space , which is not needed and also breaks the purpose of having a varchar field ...
-
- Global Moderator
- Posts: 588
- Joined: Wed Nov 20, 2013 11:53 am
- Location: Mars
Re: VARCHAR considerations in DB2.
For If have a FIELD VARCHAR(40) and try to insert 'Pandora' using host variable without mentioning the length of the data what happens is it pads extra 33 spaces to 'pandora' and stores in table
so there no use in having a varchar if you are going to use the 40 bytes instead if you pass the length which 7 to the length field and store only the actual data is stored
so there no use in having a varchar if you are going to use the 40 bytes instead if you pass the length which 7 to the length field and store only the actual data is stored
zprogrammer
- Anuj Dhawan
- Founder
- Posts: 2802
- Joined: Sun Apr 21, 2013 7:40 pm
- Location: Mumbai, India
- Contact:
Re: VARCHAR considerations in DB2.
Yes.Ankit Kumar Gupta wrote:In COBOL-SQL program, while inserting data into a VARCHAR field, is it necessary to populate the length host variable, before insert?
Yes and no. DB2 will pick up the length of the column defined as VARCHAR. If the data in the column is always of maximum length as of column, well that's the length (but that beats the purpose to define the column as VARCHAR), however if the data is not of same length as column-length - DB2 won't determine it its own and you've to tell it to DB2.Is not it that DB2 automatically stores the length?
Hope this helps.
Thanks,
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute