Char and varchar
There are great differences between a char(1999) and varchar2(1999) as the CHAR is always 1999 characters long physically AND logically. the varchar is physically 1999 bytes but logically can be any size in between 0 and 1999.
What does it mean when this sentence says that char is 1999 long physically and logically ,,,,,,and varchar is 1999 long physically and logically could be between 0 and 1999 .
for char i guess it means 1999 bytes are alocatted in memory on the disk ? And all that memory is taken up !!!!
for varchar how is it interpreted ?
thanks!!!!
Hi,
I will try to explain in simpe way, if you perform and see the steps provided in the link
[http://www.orafaq.com/wiki/SQL_FAQ#What_is_the_difference_between_VARCHAR.2C_VARCHAR2_and_CHAR_data_types.3F]
then check the user_tab_columns table and check the column data_length, this displays the length of the Column by which it validates length.
Then try and see the char_test table with single "A" and check the dump of that Column as he said that spaces are padded and memory is fully filled.
When compared to Varchar the memory is dynamically filled as need (based on Updated), internally the it allocates the required memory using the realloc() function or extends the memory further (not sure about the function).
you have keed in mind that it stored the length of the data along with the Column.
When you compare with the varchar, it will not stored or will not pad the spaces in the remaing memory, so that can be utlizied by remaining blocks of data in the Row.
- Pavan Kumar N
Similar Messages
-
Difference between char and varchar, also the difference between varchar2
Hi,
Can anyone explain me the difference between char and varchar, and also the difference between varchar and varchar2...Varchar2 is variable width character data type, so if you define column with width 20 and insert only one character to tis column only, one character will be stored in database. Char is not variable width so when you define column with width 20 and insert one character to this column it will be right padded with 19 spaces to desired length, so you will store 20 characters in the dattabase (follow the example 1). Varchar data type from Oracle 9i is automaticlly promoted to varchar2 (follow example 2)
Example 1:
SQL> create table tchar(text1 char(10), text2 varchar2(10))
2 /
Table created.
SQL> insert into tchar values('krystian','krystian')
2 /
1 row created.
SQL> select text1, length(text1), text2, length(text2)
2 from tchar
3 /
TEXT1 LENGTH(TEXT1) TEXT2 LENGTH(TEXT2)
krystian 10 krystian 8
Example 2:
create table tvarchar(text varchar(10))
SQL> select table_name,column_name,data_type
2 from user_tab_columns
3 where table_name = 'TVARCHAR'
4 /
TABLE_NAME COLUMN_NAME DATA_TYPE
TVARCHAR TEXT VARCHAR2
Best Regards
Krystian Zieja / mob -
Joining table using CHAR and VARCHAR data type as indicator
Hi All,
I would like to join 3 tables together but I'm unable to get a perfect concordance (using =) between CHAR and VARCHAR data type.
Does a command exist to get impartially all data treated as CHAR or VARCHAR ?
Thanks in advance for your help !You want the database to perform with such a crappy database design? Good luck with that.. Instead, you need to look at why you are NOT using surrogate integer based keys for your data tables..
Thank you,
Tony Miller
Webster, TX
If vegetable oil is made of vegetables, what is baby oil made of?
If this question is answered, please mark the thread as closed and assign points where earned.. -
Char and varchar performance issues
I am creating a child table with varchar2(4) column which takes the value from parent table which has char(4) column.
pls give ur suggestion that child table also should have char(4) as like parent table or having varchar2(4) is good one.? which one gives better peformance?
SAswinGousalya wrote:
I am creating a child table with varchar2(4) column which takes the value from parent table which has char(4) column. You mean like a Primary Key and Foreign key relation? In that case the data type must be the same for both the columns.
pls give ur suggestion that child table also should have char(4) as like parent table or having varchar2(4) is good one.? which one gives better peformance? If you are going to stick to parent being CHAR(4) then child must be definitely be CHAR(4).
Whats the difference between CHAR and VARCHAR2 data type?
CHAR is a fixed length data type and VARCHAR2 is a variable length. What does that mean? Lets say you have a CHAR(4) and VARCHAR2(4) column. You are storing the word 'AA' in both. Oracle will allocate 4 byte of space for CHAR column and just 2 byte of space to VARCHAR2 column. i.e. as i already said CHAR is a fixed length string. So the 'AA' is actually stored as 'AA ' (AA<two blank spaces>).
So the next question is which of the two is better? You cant compare them, they are just two different tools provided by oracle. Use which is best suited for you. -
Data type difference of char and varchar will affect the searching result?
Hi,
My issue is tht i have created an item in db as char(20) while creating EO for tht particular table, data type for tht item attribute is by default coming as string. wen i search from table based on tht item, no rows are returned.So can anyone help me to solve this?
Thanks
HarshaHi,
My requirement is having a page with search region and result region. Search region shud be done programmatically. In the search region im having a lov item, radion group item, date and poplist. poplist is having, for eg., list of countries which is fetched from lookupcode. i have to buttons "go" and "clear". wen i select any of the items and click go btn results shud be displayed in a multiselect table which is updatable. Since im using updatable table im using EO which is linked to tht search region. So my issue is tht wen i select a value from poplist and click "go" btn no rows are returned, even if rows based on tht selected values are present in the table. Wht i did is tht wen i click go btn, im taking the value from tht poplist im callin VOImpl to implement the search. The value which i fetched from the poplist is available in tht method to search also. Also when i activated tht console o/p it is showing the query as country_id = :1. But it is not selecting any rows. I think im clear now, like y EO is used and all. Please help me.
Thanks
Harsha. -
Difference between CHAR and VARCHAR2 datatype
Difference between CHAR and VARCHAR2 datatype
CHAR datatype
If you have an employee name column with size 10; ename CHAR(10) and If a column value 'JOHN' is inserted, 6 empty spaces will be inserted to the right of the value. If this was a VARCHAR column; ename VARCHAR2(10). How would it handle the column value 'JOHN' ?The CHAR datatype stores fixed-length character strings, and Oracle compares CHAR values using blank-padded comparison semantics.
Where as the VARCHAR2 datatype stores variable-length character strings, and Oracle compares VARCHAR2 values using nonpadded comparison semantics.
This is important when comparing or joining on the columns having these datatypes;
SQL*Plus: Release 10.2.0.1.0 - Production on Pzt Au 6 09:16:45 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn hr/hr
Connected.
SQL> set serveroutput on
SQL> DECLARE
2 last_name1 VARCHAR2(10) := 'TONGUC';
3 last_name2 CHAR(10) := 'TONGUC';
4 BEGIN
5 IF last_name1 = last_name2 THEN
6 DBMS_OUTPUT.PUT_LINE ( '-' || last_name1 || '- is equal to -' || last_name2
|| '-');
7 ELSE
8 DBMS_OUTPUT.PUT_LINE ( '-' || last_name1 || '- is NOT equal to -' || last_n
ame2 || '-');
9 END IF;
10 END;
11 /
-TONGUC- is NOT equal to -TONGUC -
PL/SQL procedure successfully completed.
SQL> DECLARE
2 last_name1 CHAR(6) := 'TONGUC';
3 last_name2 CHAR(10) := 'TONGUC';
4 BEGIN
5 IF last_name1 = last_name2 THEN
6 DBMS_OUTPUT.PUT_LINE ( '-' || last_name1 || '- is equal to -' || last_name2
|| '-');
7 ELSE
8 DBMS_OUTPUT.PUT_LINE ( '-' || last_name1 || '- is NOT equal to -' || last_n
ame2 || '-');
9 END IF;
10 END;
11 /
-TONGUC- is equal to -TONGUC -
PL/SQL procedure successfully completed.
Also you may want to read related asktom thread - "Char Vs Varchar" http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1542606219593
and http://tahitiviews.blogspot.com/2007/05/less-is-more-more-or-less.html
Best regards. -
OWB-Import does not distinguish between nls_length_semantics char and byte.
We have a 10g-DB with UTF8 charset and nls_length_semantics=char and we've created an OWB warehouse module for 10g with several tables in it. After deploy operation for a table the column length attributs are looking nice. But if we re-import this table the varchar fields have the threefold length!
This makes life hard for us, because sometimes it's necessary to reconcile discrepancies in development cycle and some tables have about 150 columns.
Does anybody have suggestions?
The OWB version is 10.1.0.3.0.
Regards
RalfRalf,
Oracle stores the length of VARCHAR columns in two ways in its metadata. One is the length as required by the application, and the other is the length required to store UTF data.
One UTF character can take upto 3 characters of storage. When OWB reads in the definition from data dictionary, it uses the actual characters allocated to the column, and thus u see a three fold increase in VARCHAR columns.
Try this for your table
select
column_name, data_length, char_length
from
user_tab_columns
where
table_name='nameOfTable'
And that is how Oracle designed the database, but unfortunately OWB does not have that twin way of seeing things.
- Jojo -
Hello,
Is this issue still valid with the latest OMWB release.
When converting from Informix Online to Oracle 8i:
"Data type issue, here problem comes converting chars to varchars as chars are padded and may not work in indexes, so you have to trim them afterwards."
Thanks
MikeWe had a lots of cases in which CHAR(n) is defined and we wanted to convert all these
CHAR(n)s to VARCHAR2(n). But since CHAR(n) datatype will allocated the extra spaces
even if the length of the string is less than 'n'; we wanted to change that.
We realized that after migration all the VARCHAR2(n) are still padded with extra spaces.
Thanks -
Does it make sense to set the entity fields username password, to be 48 chars of length and to be CHAR instead of varchar ?
Is it better to choose the former in the presence of an index ?
How does CHAR perform when the encoding of the strings in the RDBMS is UTF (for those who dont know, this is a variable length encoding, e.g. japanese chars can be encoded in UTF-8, 24bit code points could be encoded in UTF16, and so on) ?
What does make sense ? char or varchar for username and password for speed searching ?
ThanksDoes it make sense to set the entity fields username password, to be 48 chars of length and to be CHAR instead of varchar ?
Is it better to choose the former in the presence of an index ?
How does CHAR perform when the encoding of the strings in the RDBMS is UTF (for those who dont know, this is a variable length encoding, e.g. japanese chars can be encoded in UTF-8, 24bit code points could be encoded in UTF16, and so on) ?
What does make sense ? char or varchar for username and password for speed searching ?
Thanks -
I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
here is the procedure
create or replace
procedure temp(
P_MTR_ID VARCHAR2,
P_FROM_DATE IN DATE ,
P_THROUGH_DATE IN DATE ) AS
L_XML CLOB;
l_query VARCHAR2(2000);
BEGIN
l_query:= 'SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
||'mi''), ''00:'
||'00'',''24:'
||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
||'mi'')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = '
||P_MTR_ID||
' AND s_mtrch = ''1''
AND s_datetime BETWEEN TO_DATE('
||P_FROM_DATE||
',''DD-MON-YY'') AND (TO_DATE('
||P_THROUGH_DATE||
',''DD-MON-YY'') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = '
||P_MTR_ID||
' AND s_mtrch = ''2''
AND s_datetime BETWEEN TO_DATE('
||P_FROM_DATE||
',''DD-MON-YY'') AND (TO_DATE('
||P_THROUGH_DATE||
','' DD-MON-YY'') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)';
SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML FROM DUAL;
INSERT INTO NK VALUES (L_XML);
DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
END;
OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
L_QUERY IS :SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = N3165 AND s_mtrch = '1'
AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = N3165 AND s_mtrch = '2'
AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)The correct way to handle this is to use bind variables.
And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
create or replace procedure temp (
p_mtr_id in varchar2
, p_from_date in date
, p_through_date in date
is
l_xml CLOB;
l_query VARCHAR2(2000);
l_ctx dbms_xmlgen.ctxHandle;
begin
l_query:= 'SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
||'mi''), ''00:'
||'00'',''24:'
||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
||'mi'')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = :P_MTR_ID
AND s_mtrch = ''1''
AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = :P_MTR_ID
AND s_mtrch = ''2''
AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)';
l_ctx := dbms_xmlgen.newContext(l_query);
dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
l_xml := dbms_xmlgen.getXML(l_ctx);
dbms_xmlgen.closeContext(l_ctx);
insert into nk values (l_xml);
end; -
How to compare char and numc in select query
Hi Experts,
I am using For all entries to combine two tables.
I want to fetch the data from these tables.
The field in one table char, and in another the field is numc.
1st Query from table BDCP2 and get the tabkey value is like (2000000000000000000086200000000000000000000)
2nd query For all entries found,
query table ESTMJ with the following parameter.
ESTMJ-RECN = BDCP2-TABKEY+3(20)
1.TABKEY CHAR 254
2.RECN NUMC 20
How to compare these two ?
Regards,
Bindhu Priya.for two fields numc & char , please check out their Conversion routine in their respective Database table.
1st in SE11-> enter table names in different sessions. and check out the data domain used by this fields
In their respective domains of fields, click on tab 'DEFINITIONS', then check out the conversion routines in Output Characteristics of the Data Domain of field
From my point of view, both the Conversion routines should be the same.
If Conversion Routines are not there, then insert suitable Conversion routine for both the fields domain
For help for for conversion routines:
conversion routine
http://help.sap.com/saphelp_46c/helpdata/en/cf/21ee19446011d189700000e8322d00/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/35/26b217afab52b9e10000009b38f974/content.htm
http://abaplovers.blogspot.com/2008/03/conversion-routines-in-sap.html
hope this solution could solve your issue..
<begging removed by moderator>
Gaur Mayank
Edited by: Gaur Mayank on Nov 5, 2011 10:40 AM
Edited by: Thomas Zloch on Nov 6, 2011 3:59 PM -
JTextPane (reading char and its attributes)
Hellow,
I am trying to write a simple editor, where a person could write his text (in different size and color etc.) and than i need to turn this text to html code.
So the way that i determen the shape of the text in JTextPane is:
StyleConstants.setBold(set, false);
* pane.setCharacterAttributes(set, false);*
And now i have to you trought the document and read the chars and its asstributes.
And the way that i go trought the doc is by using the caret: moveCaretPosition(x);
Reading the char: char c=pane.getText(pane.getCaretPosition(),1).charAt(0);
But the problem now is... by moving the caret (dot) the mark stays in its place, so when I try to read the attribues(*AttributeSet crka;crka=pane.getCharacterAttributes();*), i read them for all the chars selected so far (0->x).
How do i move this oround, so that only one char is read and its attributes?
Edited by: Defero on Jul 19, 2008 3:09 AMSorry for that,
Yeah but it still doesnt work right.
Example:
Text in pane:
AB C DEFGH... (ignore spacers)
And then if i read the number of attributes on each char, they go like this:
00111111...
Just in case, i post my code of setting the arguments:
JButton gumb=new JButton("bold");
gumb.addActionListener((
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(bold==false){
StyleConstants.setBold(set, true);
pane.setCharacterAttributes(set, true);
pane.requestFocus();
bold=true;
}else {
StyleConstants.setBold(set, false);
pane.setCharacterAttributes(set, false);
bold=false;
pane.requestFocus();
));And reading should go like this right?:
StyledDocument ddoc=pane.getStyledDocument();
for(int i=0;i<ddoc.getLength();i++){
int x=ddoc.getCharacterElement(i).getAttributes().getAttributeCount();
}Edited by: Defero on Jul 19, 2008 10:12 PM
Edited by: Defero on Jul 19, 2008 10:12 PM -
How to define Length of char. and KF
During infoobject creation, how to define the length of char. and KF, is it related to master data text length ? Should we take other things into account? When we see one field in table, the length of the field was defined with 2, but its master data text length was more than 2, what's the reason for this things?
Edited by: hi ni on Apr 18, 2008 12:12 PMhi,
how to define the length of char. and KF, is it related to master data text length ?
ther business will have defined length and type for any characteristics. ex - Materail number may have lenth of max 15 and is Char type.
but for text max size is by default 40 chars.
Should we take other things into account?
get spec from client, that could be better and also consider the field used to map ur char/KF from source system.
Ramesh -
Transformation logic for char and keyfigure from source keyfigures and flag
Hi All,
My requirement is populate char and keyfigure values from source keyfigures and flag, which is like transformation of converting the Key Figure based structure to the accounts based structure. I am loading data from the cube1 to cube2,
cube1 structure with sample data:
Plant Furnace ZFurnace ZPlant1 Zplant2 Flag
P01 Blank 0 56 73 P
Blank F01 335 0 0 F
Target Cube str with sample data
Plant Furnace FS(Char) KYF Flag
P01 Blank 1 56 P
Blank F01 2 335 F
P01 Blank 3 73 P
ZPlant1, ZPlant2 and ZFurnace are the keyfigure tech.names.
FS has master data:
FScode KYF Flag
1 ZPlant1 P
2 ZFurnace F
3 Zplant2 P
While loading data from the source cube1 I need to read FS master data and than fill FS code in target cube based on source Flag and Key figure technical names.
I would be greatly appreciate with points if anyone can help me in writing the ABAP logic. The challenging part for me is comparing key figure technical names in cube1 with the FS master data key figure values.
Thanks.
Baba.Hi All,
Actually there will be 18 records in FS master data and there will not more than 18 Key figures. Is there any way I can hardcore the values and write small code.
something like:
if KYF = Zplant1.
WA_FSCODE = '1'.
WA_EU = source_fields-KYF.
WA_PLant = source_fields-plant.
wa_furnace = source_fields-furnace.
else
if kyf = zplant2
Please let me know the sample logic with code. I greatly appreciate with points..
Regards
Baba -
Hi all,
I am having a requirement wer i need to create the report which include the fields
PO line item, PO del. date, PO LOI date, and some other char
Now can i create the PO line item and char and PO del dat, PO LOI dat as attributes of it. Does it works fine.
Another thing i am getting all the 3 fields from the R3 and v r not any of them as varibles.
pls suggest me u a optimal solution and let me know the reasons for the same
RegardPriya,
can i create the PO line item and char and PO del dat, PO LOI dat as attributes of it. is that fine.
--> Attribute of what..? Create as a characteristics and use.
what happen if i create every field as a saperate char.
--> Create as a characteristics only, not attribute.
when creating the char what the difference between creating by reference char and template.
--> Template: Copies only technical properties(type, length...ect). For these objects data has to be loaded.
Reference: Cpies technical properties and also uses same tables from source characteristics, so for these objects no need to maintain data. As it picks data from reference objects.
You create objects by using template. or if you want to use same master data, create as with reference.
Hope it Helps
Srini
Maybe you are looking for
-
My hard drive crashed. Should I replace it myself?
My last question posted about an hour ago helped me realize my hard drive on my mid-2009 13" MBP died. So now the question, should I just replace the hard drive myself? I am fairly comfortable around computers and have opened the computer and replace
-
Is it possible to limit (i.e. set a maximum) number of direct deposit banks for employees? For instance, we would like to limit the number of banks employees can send direct deposits to at 3 per employee. Thanks!
-
Print problem in Forms y Reports 10g via OAS
Hello: I am using 10g Reports and Forms10G and when command to print any report compelled me OAS calls passing through and I register with a user connection to lift the printing service. how to fix this problem?
-
Compatibility betw Soundbooth/Audition and Nero
I am demo-ing Soundbooth and Audition. I think that Soundbooth is sufficient to my needs. I have previously used Cool Edit 1.2. (I'm on a new computer now.) I make live recordings to teach Torah chanting, Jewish prayers, etc. And then sometimes cut
-
I would like to populate the cost center in work order to PR. Is there any user exit or BADI ? I had try IWO10009, it doesn't work. Please help on this. Thanks.