Querying character column sizes using DatabaseMetadata

Hi,
In a UTF-8 database, I've created two testing tables, one that uses byte length semantics (BLS) for its CHAR and VARCHAR2 columns, and one using character length semantics (CLS). If I use the standard JDBC DatabaseMetdata.getColumns() query, the size of the CLS columns is reported as 4 times that of the BLS columns. I don't believe this is the desired behaviour for the JDBC drivers.
Regardless, does anyone know a way to accurately determine (preferably using standard JDBC methods) the size of a CHAR or VARCHAR column in characters across different database configurations? I need this to compare column lengths in a ASCII and UTF8 database.
I'm using the standalone JDBC drivers v9.2.0.3 for JDK1.4 (odjbc.jar) running aginst Oracle 9.2.0.0.
The following code, which contains some DDL to create sample tables, can be used to dump the column metadata returned by Oracle's database drivers.
import java.sql.*;
import java.util.*;
The following script can be used to create two test tables, the first with
byte-size columns, and the second with character-size columns.
CREATE TABLE TMP
TMP_ID NUMBER(12) NOT NULL PRIMARY KEY,
TMP_CHAR CHAR(200 BYTE),
TMP_VCHAR VARCHAR2(100 BYTE)
CREATE TABLE TMP2
TMP_ID NUMBER(12) NOT NULL PRIMARY KEY,
TMP_CHAR CHAR(200 CHAR),
TMP_VCHAR VARCHAR2(100 CHAR)
public class DatabaseMetadata
private static final String COLUMN_NAMES[] = {
"TABLE_CAT",
"TABLE_SCHEM",
"TABLE_NAME",
"COLUMN_NAME",
"DATA_TYPE",
"TYPE_NAME",
"COLUMN_SIZE",
"BUFFER_LENGTH",
"DECIMAL_DIGITS",
"NUM_PREC_RADIX",
"NULLABLE",
"REMARKS",
"COLUMN_DEF",
"SQL_DATA_TYPE",
"SQL_DATETIME_SUB",
"CHAR_OCTET_LENGTH",
"ORDINAL_POSITION",
"IS_NULLABLE"
private static final int COLUMN_WIDTHS[] = {
10, // "TABLE_CAT",
11, // "TABLE_SCHEM",
10, // "TABLE_NAME",
11, // "COLUMN_NAME",
10, // "DATA_TYPE",
10, // "TYPE_NAME",
11, // "COLUMN_SIZE",
13, // "BUFFER_LENGTH",
13, // "DECIMAL_DIGITS",
13, // "NUM_PREC_RADIX",
10, // "NULLABLE",
10, // "REMARKS",
10, // "COLUMN_DEF",
10, // "SQL_DATA_TYPE",
10, // "SQL_DATETIME_SUB",
10, // "CHAR_OCTET_LENGTH",
10, // "ORDINAL_POSITION",
10, // "IS_NULLABLE"
private static final char WHITESPACE[] =
.toCharArray();
private static final String HYPHENS =
private static String formatRow(String row[])
StringBuffer buffer = new StringBuffer(128);
for (int j=0;j<row.length;j++)
if (j > 0)
buffer.append(" | ");
String text = row[j];
int width = COLUMN_WIDTHS[j];
if (text == null)
buffer.append(WHITESPACE, 0, width);
else if (text.length() > width)
buffer.append(text.substring(0, width));
else
buffer.append(text).append(WHITESPACE, 0, width - text.length());
} // j
return buffer.toString();
} // private static String formatRow(String[])
private static void printColumnMetadata(
DatabaseMetaData metadata, String tableName)
throws SQLException
System.out.println("\n" + tableName + "\n");
System.out.println(formatRow(COLUMN_NAMES));
String hyphens[] = new String[18];
Arrays.fill(hyphens, HYPHENS);
System.out.println(formatRow(hyphens));
ResultSet results = metadata.getColumns(null, null, tableName, "%");
String columnMetadata[] = new String[18];
while (results.next())
for (int i=0;i<18;i++)
Object result = results.getObject(i+1);
columnMetadata[i] = result == null ? "NULL" : result.toString();
} // i
System.out.println(formatRow(columnMetadata));
results.close();
} // private static void printColumnMetadata(DatabaseMetaData, String)
public static void main(String argv[])
throws Exception
Driver driver = (Driver)Class.forName(
"oracle.jdbc.driver.OracleDriver").newInstance();
DriverManager.registerDriver(driver);
Connection connection = DriverManager.getConnection(
argv[0], argv[1], argv[2]);
// ((oracle.jdbc.OracleConnection)connection).setRemarksReporting(true);
try
DatabaseMetaData metadata = connection.getMetaData();
printColumnMetadata(metadata, "TMP");
printColumnMetadata(metadata, "TMP2");
catch (SQLException e)
e.printStackTrace();
connection.close();
} // public class DatabaseMetadata

It appears that this forum uses "[" "i" "]" to denote italics internally, so these characters are missing where the code sample becomes italic, between 'columnMetadata' and '='.

Similar Messages

  • Sorting character column ( used in order by clause dynamically)

    Hi,
    I need help on sorting character-based numbers. Like say, I want to sort customers based on street numbers(which is a character string being used in the
    order by clause) they live in.
    The criteria are :
    i. Numbers must take precedence.
    This being a character string, 1000001 comes before 2. This shouldn't happen. And you cannot use to_number
    since using it with a string having characters in it would raise an error.
    ii. If only a single alphabet occurs as the last character, then treat the whole string as a number except the last character and then sort it
    as if sorting a number. Something like : if you have 1000A, 200D, 200B, 1000X, the result would be 200B,200D,1000A,1000X.
    iii. if a character occurs elsewhere in the string, then perform the search normally as if performing a character search.
    The output of the following data :
    100
    A101
    B100A
    110C
    C120B
    120
    100020
    120C
    C1100
    100D
    would be like :
    100
    100D
    110C
    120
    120C
    100020
    A101
    B100A
    C120B
    C1100
    Please note that the sort is being done dynamically, so I could have access to the values of the street numbers only during run time.
    Any help is really appreciated.
    Thanks in advance.
    Regards,
    Anil.

    Create a function to test whether the column is numeric :
    create FUNCTION is_numeric(v_number VARCHAR2)
    RETURN INTEGER
    IS
    l_number NUMBER;
    BEGIN
    IF INSTR(UPPER(v_number),'E') > 0 THEN
    RETURN 0;
    END IF;
    l_number := TO_NUMBER(v_number);
    RETURN 1;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN 0;
    END;
    And try this query
    Assume the table name is TEST with column STREET
    select * from TEST
    order by case is_numeric(STREET) when 1 then LPAD(STREET,20, ' ') else STREET end
    Please make sure that 20 mentioned above is the column size for STREET.
    Hope this helps.
    -Nags

  • Querying CHAR columns with character length semantics unreliable

    Hi again,
    It appears that there is a bug in the JDBC drivers whereby it is highly unlikely that the values of CHAR columns that use character length semantics can be accurately queried using ResultSet.getString(). Instead, the drivers return the value padded with space (0x#20) characters out to a number of bytes equal to the number of characters multiplied by 4. The number of bytes varies depending on the number and size of any non-ascii characters stored in the column.
    For instance, if I have a CHAR(1) column, a value of 'a' will return 'a ' (4 characters/bytes are returned), a value of '\u00E0' will return '\u00E0 ' (3 characters / 4 bytes), and a value of '\uE000' will return '\uE000 ' (2 characters / 4 bytes).
    I'm currently using version 9.2.0.3 of the standalone drivers (ojdbc.jar) with JDK 1.4.1_04 on Redhat Linux 9, connecting to Oracle 9.2.0.2.0 running on Solaris.
    The following sample code can be used to demonstrate the problem (where the DDL at the top of the file must be executed first):
    import java.sql.*;
    import java.util.*;
    This sample generates another bug in the Oracle JDBC drivers where it is not
    possible to query the values of CHAR columns that use character length semantics
    and are NOT full of non-ascii characters. The inclusion of the VARCHAR2 column
    is just a control.
    CREATE TABLE TMP2
    TMP_ID NUMBER(10) NOT NULL PRIMARY KEY,
    TMP_CHAR CHAR(10 CHAR),
    TMP_VCHAR VARCHAR2(10 CHAR)
    public class ClsCharSelection
    private static String createString(char character, int length)
    char characters[] = new char[length];
    Arrays.fill(characters, character);
    return new String(characters);
    } // private static String createString(char, int)
    private static void insertRow(PreparedStatement ps,
    int key, char character)
    throws SQLException
    ps.setInt(1, key);
    ps.setString(2, createString(character, 10));
    ps.setString(3, createString(character, 10));
    ps.executeUpdate();
    } // private static String insertRow(PreparedStatement, int, char)
    private static void analyseResults(PreparedStatement ps, int key)
    throws SQLException
    ps.setInt(1, key);
    ResultSet results = ps.executeQuery();
    results.next();
    String tmpChar = results.getString(1);
    String tmpVChar = results.getString(2);
    System.out.println(key + ", " + tmpChar.length() + ", '" + tmpChar + "'");
    System.out.println(key + ", " + tmpVChar.length() + ", '" + tmpVChar + "'");
    results.close();
    } // private static void analyseResults(PreparedStatement, int)
    public static void main(String argv[])
    throws Exception
    Driver driver = (Driver)Class.forName(
    "oracle.jdbc.driver.OracleDriver").newInstance();
    DriverManager.registerDriver(driver);
    Connection connection = DriverManager.getConnection(
    argv[0], argv[1], argv[2]);
    PreparedStatement ps = null;
    try
    ps = connection.prepareStatement(
    "DELETE FROM tmp2");
    ps.executeUpdate();
    ps.close();
    ps = connection.prepareStatement(
    "INSERT INTO tmp2 ( tmp_id, tmp_char, tmp_vchar " +
    ") VALUES ( ?, ?, ? )");
    insertRow(ps, 1, 'a');
    insertRow(ps, 2, '\u00E0');
    insertRow(ps, 3, '\uE000');
    ps.close();
    ps = connection.prepareStatement(
    "SELECT tmp_char, tmp_vchar FROM tmp2 WHERE tmp_id = ?");
    analyseResults(ps, 1);
    analyseResults(ps, 2);
    analyseResults(ps, 3);
    ps.close();
    connection.commit();
    catch (SQLException e)
    e.printStackTrace();
    connection.close();
    } // public static void main(String[])
    } // public class ClsColumnInsertion

    FYI, this has been mentioned as early as November last year:
    String with length 1 became 4 when nls_lang_semantics=CHAR
    and was also brought up in Feburary:
    JDBC thin driver pads CHAR col to byte size when NLS_LENGTH_SEMANTICS=CHAR

  • Query Result Sizes Using LiveOffice

    I'd like to get a community response on this one:
    Can viewers of this post who have LiveOffice product experience answer a question for me?  I am using the Universe Query functionality to place data into Excel.  The result size is roughly 4500 rows by 6 columns of data.  If I remove a condition in the query to expand the results LiveOffice fails with this error:
    Failed to get the document information. (LO 26315)  Maximum character output size limit reached. Contact your BusinessObjects administrator. (Error: ERR_WIS_30272)(6315)
    After checking in Desktop Intelligence...I found the result size of the failed query to be just under 10,000 rows.
    I've been using LiveOffice for some time now, but this is the first instance where I have attempted to run a large amount of data into Excel.  I wouldn't call 10,000 rows a lot, but it is a lot more than I have done in the past.
    Can users of LiveOffice tell me the largest row result they have thrown into Excel using LiveOffice?  It can be with a report part or straight query.  I tried to provide with a webi report part and got the same failure.
    I've logged this with SAP Support and they're baffled so far...

    Hi Gregg,
    what's the data source behind your universe? Can it be the case that somewhere in your results exists a field that holds more than 32K. As far as I know Excel allows 32 K per cell.
    Regards,
    Stratos

  • Query for  to get  database size, used size, freesize, db size after drop

    Pls give me a query for to get database size, used size, freesize, tablespacesize of sometables which is starting with 'RQ%'
    I have to get result like this
    Total size, used size, free size ,tablespace size of RQ tables alone
    Reason why i go for "tablespace size of RQ tables" i want to know the size of database after deleting the rq tables
    Pls reply
    S

    i tried with
    SELECT
    --fs.tablespace_name name,
    df.totalspace/1024/1024 mbytes,
    (df.totalspace - fs.freespace)/1024/1024 used,
    fs.freespace/1024/1024 free
    FROM
    (SELECT
    --tablespace_name,
    ROUND(SUM(bytes)) TotalSpace
    FROM
    dba_data_files
    ) df,
    (SELECT
    --tablespace_name,
    ROUND(SUM(bytes)) FreeSpace
    FROM
    dba_free_space
    ) fs
    i AM GETTING total bytes, used bytes, free bytes
    I WANT TO include one more column.. database size after deleting rq tables
    Pls reply
    S
    Edited by: AswinGousalya on Jul 10, 2009 2:17 PM

  • Fetching file size using CAML query in Javascript client object model

    Hi,
    I am using the Javascript client object model to retrieve contents of a document library.
    I have a document library, which contains a folder "Folder1" . "Folder1" has a zip file. I would like to get the file size of the zip file.
    I have tried the below code, but not sure, how to fetch the file size.
    function FetchImage() {
    var clientcontext = new SP.ClientContext.get_current();
    var oweb = clientcontext.get_web();
    var olibrary = oweb.get_lists().getByTitle(DocLibrary);
    var query = new SP.CamlQuery();
    query.set_folderServerRelativeUrl("Lists/DocLibrary/folder1/");
    folder = olibrary.getItems(query);
    clientcontext.load(folder, 'Include(Title,ContentType, FileLeafRef,FileDirRef,File)');
    clientcontext.executeQueryAsync(Function.createDelegate(this, this.RenderDataOnSuccess), Function.createDelegate(this, this.RenderDataOnFailure));
    function RenderDataOnSuccess() {
    var ListEnumerator = this.folder.getEnumerator();
    while (ListEnumerator.moveNext()) {
    var currentItem = ListEnumerator.get_current();
    if (_contentType.get_name() != "Folder") {
    var File = currentItem.get_file();
    if (File != null) {
    // Fetch file size
    How to fetch the file size?
    Thanks

    <script>
    function getSize()
            var myFSO = new ActiveXObject("Scripting.FileSystemObject");
            var filepath = document.upload.file.value;
            var thefile = myFSO.getFile(filepath);
            var size = thefile.size;
            alert(size + " bytes");
    </script>
    http://social.msdn.microsoft.com/Forums/en-US/e5d2ff3d-01c7-4cc0-a081-29a4dfbb0fad/getting-the-sharepoint-list-attachment-size-using-javascript?forum=sharepointcustomizationlegacy

  • SSMS 2012: Using CTE in a query - Invalid column name 'EmployeeID' !!??

    Hi all,
    From Page 88 of the Book "SQL Programming & Database Design Using Microsoft SQL Server 2012" written by Kalman Toth, I copied the following code of Using CTE in a query:
    -- CTETest2.sql /// saved in C:\My Documents\SQL Server Management Studio\
    ----Page 88 of Book by Toth === Using CTE in a query ----- 13 March 2015
    --Using CTE in a query
    ;WITH CTE (SalesPersonID, NumberOfOrders, MostRecentOrderDate)
    AS (SELECT SalesPersonID, COUNT(*), CONVERT(date, MAX(OrderDate))
    FROM Sales.SalesOrderHeader GROUP BY SalesPersonID )
    --Start of outer (main) query
    SELECT E.EmployeeID,
    OE.NumberOfOrders AS EmpOrders,
    OE.MostRecentOrderDate AS EmpLastOrder,
    E.ManagerID,
    OM.NumberOfOrders AS MgrOrders,
    OM.MostRecentOrderDate AS MgrLastOrder
    FROM HumanResources.Employee AS E
    INNER JOIN CTE AS OE ON E.EmployeeID = OE.SalesPersonID
    LEFT OUTER JOIN CTE AS OM ON E.ManagerID = OM.SalesPersonID
    In my SQL Server 2012 Management Studio, I executed this set of code and I got the following fatal error:
    Msg 207, Level 16, State 1, Line 16
    Invalid column name 'EmployeeID'.
    I have no clues why I got this error message in this .sql trial of my second practice in doing CTE.  Please kindly help and let me know where I made mistake and how to resolve this problem.
    Thanks in advance,
    Scott Chang

    Hi scott_morris-ga, Thanks for your nice response.
    I changed EmployeeID to BusinessEntityID as you pointed out and executed the revised code:
    -- CTETest2.sql /// saved in C:\My Documents\SQL Server Management Studio\
    ----Page 88 of Book by Toth === Using CTE in a query ----- 13 March 2015
    --Using CTE in a query
    ;WITH CTE (SalesPersonID, NumberOfOrders, MostRecentOrderDate)
    AS (SELECT SalesPersonID, COUNT(*), CONVERT(date, MAX(OrderDate))
    FROM Sales.SalesOrderHeader GROUP BY SalesPersonID )
    --Start of outer (main) query
    SELECT E.BusinessEntityID,
    OE.NumberOfOrders AS EmpOrders,
    OE.MostRecentOrderDate AS EmpLastOrder,
    E.ManagerID,
    OM.NumberOfOrders AS MgrOrders,
    OM.MostRecentOrderDate AS MgrLastOrder
    FROM HumanResources.Employee AS E
    INNER JOIN CTE AS OE ON E.BusinessEntityID = OE.SalesPersonID
    LEFT OUTER JOIN CTE AS OM ON E.ManagerID = OM.SalesPersonID
    I got 2 new error messages:
    Msg 207, Level 16, State 1, Line 17
    Invalid column name 'ManagerID'.
    Msg 207, Level 16, State 1, Line 12
    Invalid column name 'ManagerID'.
    I have no ideas what should be used to replace 'ManagerID' in my revised code. Could you please help again and give me the right thing to replace the 'ManagerID'? By the way, where in the AdventureWorks do you find the right things?  Please enlighten
    me in this matter.
    Many Thanks again,  Scott Chang 

  • How to Increase the Rows and Columns Size of Bex Query in Enterprise Portal  of SAP  7.3

    Dear All,
    Please let me know the process how to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Currently I am getting Only  4 columns and 10 rows in One Page .And I am getting 1,2 etc tabs for both row and column. So i want to increase the column length more than 100  and row length more than 10000.
    Please suggest me a suitable solution to over come this issue.
    Please find the Below screen shot.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • How to show the VALUE as the Column Header using SQL query?

    Hi
    I have a requirement to show the picked value as the column header using SQL query.
    Example:
    ======
    SELECT EMPNO FROM EMP
    WHERE EMPNO=7934;
    Result Should be:
    7934
    7934

    I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
    SQL> set verify on
    SQL> def e =  7934
    old: SELECT empno "&&e"  FROM emp  WHERE empno = &&e
    new: SELECT empno "7934"  FROM emp  WHERE empno = 7934
    SQL> SELECT empno "7934"  FROM emp  WHERE empno = 7934
          7934
          7934
    1 row selected.

  • How to sum a column value using CAML Query?

    Hi All,
    I would like to sum the column value using CAML qeury. Actually in my list, I have two column "Projects Name" and "Number of Issues". Now need to get sum of "Number of Issues" column. How to achieve in CAML Query.
    Thanks in advance!

    Hi Sam,
    it looks like you can use your current view based agregation, otherwise it is not possible(
    http://msdn.microsoft.com/en-us/library/ms467521.aspx) and you need to work on custom bit on this requirement.
    use the below link and create a view element as described and see if that works for you
    Aggregations Element
    http://msdn.microsoft.com/en-us/library/ms468626%28v=office.12%29.aspx
    Another reference
    Query Element
    http://msdn.microsoft.com/en-us/library/ms471093.aspx
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • QUERY TO GET database size, used size, freesize, tablespacesize of RQ table

    Pls give me a query for to get database size, used size, freesize, tablespacesize of sometables which is starting with 'RQ%'
    I have to get result like this
    Total size, used size, free size ,tablespace size of RQ tables alone
    Reason why i go for "tablespace size of RQ tables" i want to know the size of database after deleting the rq tables
    ( Since i am not getting any reply i go for database forum)
    Pls reply
    S
    Edited by: AswinGousalya on Jul 8, 2009 3:41 PM

    Hello,
    This question looks like it is really for the Oracle RDBMS and not for Berkeley DB. In BDB, we do not have a notion of tablespace size. What database product are you using?
    regards,
    mike brey
    BDB engineering

  • Data type column size does not match size of values returned

    I've tried searching but couldn't find what I was looking for, sorry if this has been answered or is a duplicate.
    I am using the (Java) method below to get the column definitions of a table. I am doing this through an ODBC connection (using Oracle ODBC driver) and I have NO CHOICE in the matter.
    The problem I am having is that one particular column has a column size is smaller than the size of the data it purportedly holds (ie attendance_code = varchar size 3 but data value is "Absent". I suspect the data is actually a look up to situation, where my attendance_code column has a value of 'ABS' and Oracle goes and fetchs the "Absent" value.
    My issue is that the meta data returned from ODBC is the actual column definition (ie varchar(3) and not varchar2(10) for example).
    The resultset metadata has a size of 3 for the column in question, and querying the schema also yields 3 for that column.
    How do I resolve this? I do not have access to all_columns table etc. I have to do it using ODBC metadata only.
    I've tried recreating the situation using the Oracle XE DB, but as I am not familiar with Oracle, I do not know how to recreate this scenario (which would then lead me to test other options with ODBC).
    TIA.
    The select I am using is SELECT * FROM <tableName>.
    public ArrayList<SchemaColumn> getColumnsForTable(String catalog,
    String schema,
    String tableName) {
    ArrayList<SchemaColumn> columns = new ArrayList<SchemaColumn>();
    ResultSet rs = null;
    try {
    DatabaseMetaData metaData = connection.getMetaData();
    rs = metaData.getColumns(catalog, schema, tableName, "%");
    SchemaColumn column;
    while (rs.next()) {
    column = new SchemaColumn();
    column.setName(rs.getString("COLUMN_NAME"));
    column.setDataType(rs.getInt("DATA_TYPE"));
    column.setTypeName(rs.getString("TYPE_NAME"));
    column.setColumnSize(rs.getInt("COLUMN_SIZE")); <-------- this is the value that is coming back smaller than the data it actually returns
    column.setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
    column.setNumPrecisionRadix(rs.getInt("NUM_PREC_RADIX"));
    column.setNullable(rs.getInt("NULLABLE"));
    column.setRemarks(rs.getString("REMARKS"));
    column.setDefaultValue(rs.getString("COLUMN_DEF"));
    column.setSqlDataType(rs.getInt("SQL_DATA_TYPE"));
    column.setSqlDateTimeSub(rs.getInt("SQL_DATETIME_SUB"));
    column.setCharOctetLength(rs.getInt("CHAR_OCTET_LENGTH"));
    column.setOrdinalPosition(rs.getInt("ORDINAL_POSITION"));
    columns.add(column);
    } catch (Exception e) {
    Log.getLogger().error("Could not capture table schema");
    closeResultSet(rs);
    return columns;
    }

    I can't say I've ever seen a case where a column held more data than it was declared as, and would have to file that under "see it to believe it" category.
    Even if that somehow were the case, I'd expect the ODBC driver to return what the column is defined as anyway, not the data. The data changes with every row, but I'd expect the table metadata to be consistent, and refer to the table definition.
    For grins though, can you provide system.out.println output of the metadata, and also a "describe xxxx" from sqlplus if you can, where xxx is the table name?
    ie,
    while (rs.next()) {
    System.out.println("column name is " + rs.getString("COLUMN_NAME"));
    System.out.println("data type is " + rs.getInt("DATA_TYPE"));
    ..etc..
    Greg

  • ALV Report Print problem after 255 character line size

    Hi ABAP Gurus,
    I have created one alv report where i am getting output more then 255 character line size.
    so whenever i tried to print this report it print only line upto first 255 character and truncated after it in printing.
    is there any way i can print this report without truncation ....
    Thanks,
    Jack

    no there is no such way because you acan print at most 99 columns and utmost 255 characters .
    and alternative is take your filed in separate screen and make it appear through hotspot in another filedcatalog.then u will get more space .
    reward if useful
    keep rockin
    vivek

  • What table column size is needed to accomodate Unicode characters

    Hi guys,
    I have encounter something which i dont understand and i hope gurus here will shed some light on me.
    I am running a non-unicode database and i decided to port the data over to a unicode database.
    So
    1) i export the schema out --> data.dmp
    2) then i create the unicode database + create a user
    3) then i import the schema into the database
    during the imp i can see that character conversion will take place.
    During importing of data into the unicode database
    I encounter some error
    saying column size is too small
    so i went to check the row that has the column value that is too large to fit in the table.
    I realise it has some [][][][] data.. so i went to the live non-unicode database and find the row. Indeed it has some [][][][] rubbish data which i feel that someone has inserted other language then english into the database.
    But regardless,
    I went to modify the column size to a larger size, now the row can be accommodated. However the data is still [][][].
    q1) why so ? since now my database is unicode, during the import, this column data [][][] should be converted to unicode already but i still have problem seeing what language it is.
    q2) why at the non-unicode database, the [][][] data can fit into the table column size, but on unicode database, the same table column size need to be increase ?
    q3) while doing more research on unicode, it was said that unicode character takes up 2 byte per character. Alot of my table data are exactly the same size of the table column size.
    E.g Name VARCHAR2(5);
    value - 'Peter'
    Now if converting to unicode, characters will take 2byte instead of 1, isnt 'PETER' going to take up 10byte ( 2 byte per character ),
    why is it that i can still accomodate the data into the table column ?
    q4) now with unicode database up, i will be supporting different language characters around the world. How big should i set my column size to ? the longest a name can get ? or ?
    Thanks guys!

    /// does oracle automatically "look" at the each and individual characters in a word and determine how much byte it should take.
    Characters usually originate from a keyboard, which has an associated keyboard layout and an associated character set encoding (a.k.a code page, a.k.a. encoding). This means, the keyboard driver knows that when a key with a letter "á" on it is pressed on a French keyboard, and the associated character set encoding is MS Code Page 1252 (Oracle name WE8MSWIN1252), then one byte with the value 225 is generated. If the associated character set encoding is UTF-16LE (standard internal Windows encoding), two bytes 225 and 0 are generated. When the generated bytes travel through APIs, they may undergo character set conversions from one encoding to another encoding. The conversion algorithms use translation tables to find out how to translate given byte sequence from one encoding to another encoding. In case of translation from WE8MSWIN1252 to AL32UTF8, Oracle will know that the byte sequence resulting from conversion of the code 225 should be 195 followed by 161. For a Chinese characters, for example when converting it from ZHS16GBK, Oracle knows the resulting sequence as well, and this sequence is usually 3 bytes.
    This is how AL32UTF8 data gets into a database. Now, when Oracle processes a multibyte string, and needs to look at individual characters, for example to count them with LENGTH, or take a substring with SUBSTR, it uses information it has about the structure of the character set. Multibyte character sets are of two type: fixed-width and variable-width. Currently, Oracle supports only one fixed-width multibyte character set in the database: AL16UTF16, which is Oracle's name for Unicode UTF-16BE encoding. It supports this character set for NCHAR/NVARCHAR2/NCLOB data types only. This character set uses two bytes per each character code. To find the next code, 2 is simply added to the string pointer.
    All other Oracle multibyte character sets are variable-width character sets, including AL32UTF8. In most cases, the length of each character code can be determined by looking at its first byte. In AL32UTF8, the number of 1-bits in the most significant positions in the first byte before the first 0-bit tells how many bytes a character has. 0 such bits means 1 byte (such codes are identical to 7-bit ASCII), 2 such bits mean two bytes, 3 bits mean 3 bytes, 4 bits mean four bytes. 1 bit (e.g. the bit sequence 10) starts each second, third or fourth byte of a code.
    In other ASCII-based multibyte character sets, the number of bytes is usually determined by the value range of the first byte. Bytes below 128 means a one-byte code, bytes above 128 begin a two- or three-byte sequence, depending on the range.
    There are also EBCDIC-based (mainframe) multibyte character sets, a.k.a shift-sensitive character sets, where a sequence of two-byte codes is introduced by inserting the SO character (code 14=0x0e) and ended by inserting the SI character (code 15=0x0f). There are also character sets, like ISO-2022-JP, which use more complicated byte sequences to define the length and meaning of byte sequences but Oracle supports them only in limited number of places.
    /// e.g i have a word with 4 character. the 3rd character will be a chinese character..the rest are ascii character
    /// will oracle use 4 byte per character regardless its ascii(english) or chinese
    No.
    /// or it will use 1 byte per english character then 3 byte for the chinese character ? e.g.total - 6 bytes taken
    It will use 6 bytes.
    Thnx,
    Sergiusz

  • How to increase the column size of interactive report

    Hi , I am using apex 4.2 and theme 25 ..
    i did not find any option to increase the column size of interactive report. where as in classic report i can do so ,,
    Please guide me to achieve that.
    Thank You,
    Nihar Narla

    Nihar Narla wrote:
    Hi , I am using apex 4.2 and theme 25 ..
    i did not find any option to increase the column size of interactive report. where as in classic report i can do soThis can be done using CSS. Create a rule like this in the page Inline CSS property:
    .apexir_WORKSHEET_DATA td[headers="COLUMN_ALIAS"] {
      width: 10em;
    }where COLUMN_ALIAS is the alias of the column in the report query and the width measure is whatever you require.

Maybe you are looking for

  • Error installing grub boot loader

    I am currently following the beginner guide for installing arch, and once I get to the place where I need to install a boot loader and use the command pacman -S grub-bios, I get a seemingly never ending output of "sh: /usr/bin/wget: no such file or d

  • Ken Burn Problem in latest iMovie

    I've just updated iMovie with the Mavericks update. When I create a ken burn on a photo it plays back jerky and not smooth as per the previous version.  Any ideas? I'm on a 2013 mac mini.

  • Af:query for master detail

    Hi Experts, Can we have an af:query to show master detail data ? What we generally have is af:query showing records of 1 table. What i want is for the records that get populated from af:query in the master table, i want to show the records in the det

  • Please help me it urgent....

    hello everyone. i have created a class which is extending from JWindow ,when it load I want to show dialog class which extends JDesktopPane to be loaded.I have added windowlistener to the window but it does not working. here is the code that i have t

  • RE: Computername dosent change after reboot.

    Hi! I have one computer with an exchanged harddrive, with the same size but a different brand. After deploying the image on the computer and after registration the DNS objekt gets the same name with an "1" after, but the computername within the XP is