Clob's versus Varchar fields
It's been a day of learning. I found out that when Kodo gets a
columnlength of -1 for a String field, it will ask the Dictionary for
the sql for generating a Clob. Also when Kodo finds a positive
columnlength it will call getLenString on the dictionary.
We're using MySQL and in this case, when the column-length of a String
is set to -1 this creates a TEXT field and when the column-length is
positive this creates a VARCHAR(column-length) field.
When querying the database, Kodo once again turns to the meta data. When
the column-length has been set to -1 Kodo does a separate query for each
text field. If the column-length is positive, Kodo includes the field in
it's default-fetch-group.
Am I correct so far?
The problem I have is that when a query for a certain field is
performed, I want it to be in the first group fetched. It is always
needed and not that large at all. It will at most be 1500 characters. In
SQL Server and possibly others, I can put the column-length at 1500 and
wind up with a varchar field of 1500 characters long. MySQL however,
does not support anything over 255 characters for a varchar field.
So, I need to create a field of type TEXT to allow it to contain more
than 255 chars. However, I do not want a separate query for the field
since it won't be that big anyway.
I've been able to get this working using the column-length -1 at schema
time and the value 1500 at runtime. This is not at all convenient and
will very likely result in a wrong schema being created or the wrong
query being run in the long run.
Is the solution I just mentioned the only one, or are there other scenarios?
Thanks in advance,
Martin van Dijken
Martin-
Your analysis is exactly right. Kodo 3.0 allows a lot more latitude in
how this behavior is defined.
One way in which you might be able to get around this problem is to
leave the "column-length" attribute to -1, but manually force the
mapping to not be the ClobMapping (which is the mechanism by which Kodo
knows to issue a separate query for the object). You can do this by
setting the "custom-mapping" field-level metadata extension to
"com.solarmetric.kodo.impl.jdbc.ormapping.ValueMapping".
I'll be interested to know if this works for you.
In article <[email protected]>, Martin van Dijken wrote:
It's been a day of learning. I found out that when Kodo gets a
columnlength of -1 for a String field, it will ask the Dictionary for
the sql for generating a Clob. Also when Kodo finds a positive
columnlength it will call getLenString on the dictionary.
We're using MySQL and in this case, when the column-length of a String
is set to -1 this creates a TEXT field and when the column-length is
positive this creates a VARCHAR(column-length) field.
When querying the database, Kodo once again turns to the meta data. When
the column-length has been set to -1 Kodo does a separate query for each
text field. If the column-length is positive, Kodo includes the field in
it's default-fetch-group.
Am I correct so far?
The problem I have is that when a query for a certain field is
performed, I want it to be in the first group fetched. It is always
needed and not that large at all. It will at most be 1500 characters. In
SQL Server and possibly others, I can put the column-length at 1500 and
wind up with a varchar field of 1500 characters long. MySQL however,
does not support anything over 255 characters for a varchar field.
So, I need to create a field of type TEXT to allow it to contain more
than 255 chars. However, I do not want a separate query for the field
since it won't be that big anyway.
I've been able to get this working using the column-length -1 at schema
time and the value 1500 at runtime. This is not at all convenient and
will very likely result in a wrong schema being created or the wrong
query being run in the long run.
Is the solution I just mentioned the only one, or are there other scenarios?
Thanks in advance,
Martin van Dijken
Marc Prud'hommeaux [email protected]
SolarMetric Inc. http://www.solarmetric.com
Similar Messages
-
Hi folks
I have two columns which I am querying and they are both of datatype CLOB and which I bring my sql in my development environment these two columns are being displayed as nulls eventhough my sql works fine in Toad env. So, I'm pretty sure its because of the datatype of these two columns so could someone please advise on how I convert these types to varchar please.
Thanks in advance
EmmaHi,
I had similar problem. My front end application is in Java. In my app. iam selecting the clob columns and converting the clob data into string (below is the method i used) before displaying it in my text area fields. Java string type can handle large amount of data. Converting the clob data into varchar within the pl/sql function will not work because we cann't assign large (clob) data to a varchar variable. Hope this helps.
public String clobToString(Clob clob) throws SQLException,IOException {
String textString = "";
if (clob != null)
// get stream from Clob Object
java.io.Reader clobReader = clob.getCharacterStream();
// find the length
int textLength = (int)clob.length();
// prepare a char array
char[] textCharArray = new char[textLength];
// read the data from the clob
clobReader.read(textCharArray, 0, textLength);
// convert char array to string
textString = new String(textCharArray);
// close the stream
clobReader.close();
return textString;
} -
How do I Load a clob from an XML field in an XMLTYPE using XMLTABLE ?
I am trying to load data into a CLOB from a XML field using XMLTABLE.
I have a SUMMARY xml field with over 100 K of data (potentialy)
and I can load all the other datatype fields to columns but can not load the xml fields over 4000 characters.
example
First I create a table of XMLTYPE. I need to sqlload new files in at regular intervals.
Create table WEB_XML of XMLTYPE;
Then I create my relational table....
create table WEB_WORKING
request_id varchar(10),
ref_number varchar(20),
summary clob
The I use the .ctl file to sqlload the xml data in
LOAD DATA
INFILE *
INTO TABLE WEB_XML
append
xmltype(XMLDATA)
ext_fname filler char(90),
XMLDATA LOBFILE(ext_fname) TERMINATED BY EOF
BEGINDATA
XMLFILE1.xml
After loading the WEB_XML table using sqlldr, I try to load my relational table using XMLTable
INSERT into WEBBAR_WORKING
request_id ,
ref_number ,
summary
SELECT X.* FROM WEB_XML P2,
XMLTable ( '//Request//REQUESTVIEW'
PASSING P2.object_value
COLUMNS
"request_id" VARCHAR(10) PATH 'REQUEST_ID',
"ref_number" VARchar(20) PATH 'REF_NUMBER',
"SUMMARY" clob PATH 'SUMMARY'
) AS X;
This gives an error saying its not expecting clob
My XML looks somthing like
-<Request>
-<REQUESTVIEW>
<REQUEST_ID>3140</REQUEST_ID>
<ref_number>2003-04-02</RECEIVED_DATE>
<SUMMARY>
OVER 100 K of data
</SUMMARY>
</REQUESTVIEW>
</Request>ok
that helped lot, im getting there however some more help please
This SQL
SELECT request_id, recieved_by, X.SUMMARY.getClobVal()
FROM WEB_XML P2,
XMLTable
'//Request//REQUESTVIEW'
PASSING P2.object_value
COLUMNS
"request_id" VARCHAR(10) PATH 'REQUEST_ID',
"received_by" VARCHAR(10) PATH 'RECEIVED_BY',
"SUMMARY" xmltype PATH 'SUMMARY'
) AS X;
SELECT request_id, recieved_by, X.SUMMARY.getClobVal()
ERROR at line 1:
ORA-00904: "RECIEVED_BY": invalid identifier
If I use the X.request_id, X.received_by ......
i get the error message
Package or function is in aan invalid state.
But this SQL was successful in getting the clob by itself but with the XML tgs around it still, how do I strip the XML tags from around this result ?
SELECT X.SUMMARY.getClobVal()
FROM WEBBAR_XML P2,
XMLTable
'//Request//REQUESTVIEW'
PASSING P2.object_value
COLUMNS
"SUMMARY" XMLTYPE PATH 'SUMMARY'
) AS X;
---------------------------------------------------------- -
Best practice to define length for varchar field of table in sql server
What is best practice to define length for a varchar field in table
where field suppose Remarks By Person varchar(max) or varchar(4000)
Could it affect on optimization in future????
experts Reply Must ...
Dilip Patil..Hi Dilip,
Varchar(n/max) is a variable-length, non-unicode character data. N defines the string length and can be a value from 1 through 8,000. Max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered
+ 2 bytes. We always use varchar when the sizes of the column data entries vary considerably. While if the filed data size might exceed 8,000 bytes in some way, we should use varchar(max).
So the conclusion is just like Uri said, use varchar(max) or varchar(4000) is depends on how much characters we are going to store.
The following document about varchar in SQL Server is for your reference:
http://technet.microsoft.com/en-us/library/ms176089.aspx
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
I have a procedure which accepts a varchar field as input and compares it with each value in a table. how do I code it.
e.g. proc1(xx IN varchar, yy OUT)
--say column name is abc then
where abc = xx;
Dosent giving any output.here it goes
SQL> ED
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE
2 COMPARE_VARCHAR_FIELDS(XX IN VARCHAR,YY OUT VARCHAR)
3 IS
4 A NUMBER:=0;
5 BEGIN
6 FOR I IN (SELECT * FROM AX WHERE X=XX)
7 LOOP
8 A:=A+1;
9 END LOOP;
10 IF A>0 THEN
11 YY:=XX||' FOUND '||A||' TIMES';
12 ELSE
13 YY:=XX||' NOT FOUND';
14 END IF;
15* END;
SQL> /
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 Z VARCHAR2(40);
3 BEGIN
4 COMPARE_VARCHAR_FIELDS('x',z);
5 dbms_output.put_line(z);
6* end ;
SQL> /
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> /
x FOUND 3 TIMES
PL/SQL procedure successfully completed. -
Dividing sum of varchar fields?
I'm using SQL Server 2014 and I have the following table containing two varchar fields I need to sum and divide:
CREATE TABLE.[VMs](
[VMID] [int] IDENTITY(1,1) NOT NULL,
[vCenter] [varchar](100) NULL,
[VMName] [varchar](100) NULL,
[Template] [varchar](100) NULL,
[PowerState] [varchar](100) NULL,
[ClusterName] [varchar](100) NULL,
[Disk] [int] NULL,
[DiskPartition] [varchar](70) NULL,
[DiskSizeGB] [decimal](10, 3) NULL,
[Hostname] [varchar](100) NULL,
CONSTRAINT [PK_VMs] PRIMARY KEY CLUSTERED
[VMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
I'm trying to get the distinct sum of 'VMName' and 'Hostname' to get the count of each, and then divide the 'VMName' count by 'Hostname' count on a per 'vCenter' basis.
I'm not sure how to perform calculations against the varchar fields and any help would be appreciated.
Thanks in advance
AdamThis is the main query, the top portion was sample data I just put based on your provided data
;With CTE
AS
SELECT
vCenter
,COUNT(DISTINCT VMName) As CountVMName
,COUNT(DISTINCT HostName) As CountHostName
FROM
@myTable
GROUP BY
vCenter
SELECT *, (CASE WHEN CountHostName <> 0 THEN CountVMName / CountHostName ELSE 0 END) As CountPerVCenter
FROM
CTE
Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered. -
Converting varchar field to date
I got a varchar field in DB with format YYYY/MM/DD HH:MI:SS in DB . I want to convert this to date field in RPD. When I did
CAST ( VarChar field AS DATE) in RPD it is not working I am getting sql error.
Thanks for your help.Hi,
can you try once to cast your char as a timestamp.
Hope that works.
Kr,
A -
Automatically trim a varchar field in an update SQL
We have an ETL application that does an update with a varchar field. When the field contains spaces, we see that with an update these spaces are trimmed automatically. We wonder whether there is a HANA setting that can be set to disable this trim....
For your ETL, Is HANA the source system?
If yes, then you got to change at ETL side right?
Regards,
Krishna Tangudu -
Using a varchar field as number on ui
Hello
In one of the requirements we got to use a varchar field in db to store as number in UI. The user may specify + or - in the begining and it can be number up to 2 decimal places.
So, how to achieve this?
We are using jdev 11.1.1.6.2may be have a transient field with number datatype and use af:convertNumber with minFractionDigits and maxFractionDigits to 2. it would take - not sure about + sign (might remove automatically). convert this as string and try saving it with your actual field.
-
Getting all VARCHAR fields with string length different then x
Hello,
I am trying to get from a table all the rows which contain in a certain varchar field a string length different than x (5 i.e.):
varchar field
treds
fd <-
grgrt
sdfsdfsdf <-
fdsds
the marked rows will been given out.
Thanks!Term, the Oracle SQL manual contains documentation on the Oracle functions. Most of the functions can be classified as either character functions, number (math) functions, date functions, and conversion functions.
If you are going to work with Oracle you will benefit from looking on the list of available functions to become familiar with what is available.
HTH -- Mark D Powell -- -
Can anyone suggest a way for me to arrange a varchar field which starts with numbers? For example it has the following data in it.
SUBSTR(CB_TEXT,1,3)
0.
1.
10.
2.
3.
3a.
3b.
4.
4a.
4b.
5.
5a.
5b.
5c.
5d.
5e.
5f.
6.
7.
7a.
SUBSTR(CB_TEXT,1,3)
7b.
7c.
8.
8a.
9.
What I'd like to do is force the row starting with '10.' to the end of the list and keep the rest in the same order.
thanksselect
XXX
, to_number( substr(XXX, 1, length(XXX) - nvl(length(ltrim(translate(XXX,'0123456789.','___________'),'_')),0)) ) A
, nvl(substr(XXX, length(XXX) - nvl(length(ltrim(translate(XXX,'0123456789.','___________'),'_')),0) + 1 ),' ') B
from
select '0.' XXX from dual
UNION select '1.' from dual
UNION select '10.' from dual
UNION select '2.' from dual
UNION select '3.' from dual
UNION select '3a.' from dual
UNION select '3b.' from dual
UNION select '4.' from dual
UNION select '4a.' from dual
UNION select '4b.' from dual
UNION select '5.' from dual
UNION select '5a.' from dual
UNION select '5b.' from dual
UNION select '5c.' from dual
UNION select '5d.' from dual
UNION select '5e.' from dual
UNION select '5f.' from dual
UNION select '6.' from dual
UNION select '7.' from dual
UNION select '7a.' from dual
) AAA
order by
to_number( substr(XXX, 1, length(XXX) - nvl(length(ltrim(translate(XXX,'0123456789.','___________'),'_')),0)) )
,nvl(substr(XXX, length(XXX) - nvl(length(ltrim(translate(XXX,'0123456789.','___________'),'_')),0) + 1 ),' ')
0. 0
1. 1
2. 2
3. 3
3a. 3 a.
3b. 3 b.
4. 4
4a. 4 a.
4b. 4 b.
5. 5
5a. 5 a.
5b. 5 b.
5c. 5 c.
5d. 5 d.
5e. 5 e.
5f. 5 f.
6. 6
7. 7
7a. 7 a.
10. 10 -
How to insert a carriage return in a varchar field
Post Author: gilles
CA Forum: Data Integration
Hello,
How do you insert a carriage return in a varchar field in BODI ? I couldn't find a function like CHAR(13)...
Thanks
GillesPost Author: gilles
CA Forum: Data Integration
Thanks a lot,
I'll upgrade to 11.7 (currently 11.5.1)
Gilles -
Query a date in a varchar field
I am trying to do a simple query...
Count the number of records in a particular month...
I use variables in the URL and use this query (in MSSQL)
SELECT recorddate FROM sometable
WHERE Year(recorddate) LIKE '#Url.year#'
AND Month(recorddate) LIKE '#Url.month#'
This should work in theory, I believe, but the problem is that the date field is varchar (though all records have a timestamp which has been added as:
<INPUT type="hidden" name="recordate" value="#Now()#">
I'm not that advanced in ColdFusion so I'm hoping someone can help me out... Is there a simple way to do this?
Thanks!I agree with Dan Bracuk that you should store your date values in a date column. For SQL server this would be DATETIME, SMALLDATETIME, or DATE depending on your server version and requirements.
As a quick fix you can use a derived table that converts your varchar column values to dates. Be aware that this should only be used as work around until you can update your table to use a date column. This query will probably not perform well on large data sets. You should also use the CFQUERYPARAM tag to avoid SQL injection vulnerabilities.
<cfquery name="report" datasource="mydsn">
SELECT recorddate
FROM
SELECT CONVERT(DATETIME, recorddate) AS recorddate
FROM sometable
) AS Q
WHERE Year(recorddate) = <cfqueryparam value="#url.year#" cfsqltype="cf_sql_integer" />
AND Month(recorddate) = <cfqueryparam value="#url.month#" cfsqltype="cf_sql_integer" />
</cfquery> -
How do select on 6 digit varchar field yymmdd index between 960530 & 120630
I've been told that when you have a 6 digit date in the form of varchar2(6) yymmdd as an index for a table that you can't use a function on it or else it will mess up the index. For instance, you can do
SELECT cust_date
FROM customer
WHERE to_date(cust_date,'RRMMDD') BETWEEN '01-MAY-1995' AND '31-JUL-2012'
....but it will mess up the index and it will search through the whole table.
So, I'm looking for a way to formulate my SELECT statement to search on a date range on cust_date without messing up the index which is a varchar2(6) field containing yymmdd. The actual info that the user is entering is in the form of yymmdd so we can use that instead of the formatted '01-MAY-1995' AND '31-JUL-2012' if you like. And yes, this is in a pl/sql procedure so you can use variables if you like.
p.s. I didn't design the table nor am I allowed to alter it.Hi,
if you work yet on this terrific date design, why not being consistent then?
create table customers as (select ename, hiredate from emp)
alter table customers add (cust_date varchar(6))
insert into customers (select ename||'20', add_months(hiredate, 360), null from emp)
14 row(s) inserted.
update customers
set cust_date = to_char(hiredate,'YYMMDD')
28 row(s) updated.
create index idx_cust_custdate on customers (cust_date)
Index created.
select cust_date, hiredate from customers
where
cust_date > '950501'
or
cust_date < '120731'
order by hiredate
CUST_DATE HIREDATE
101217 12/17/2010
110220 02/20/2011
110222 02/22/2011
110402 04/02/2011
110501 05/01/2011
110609 06/09/2011
110908 09/08/2011
110928 09/28/2011
111117 11/17/2011
111203 12/03/2011
111203 12/03/2011
120123 01/23/2012
Operation Options Object Rows Time Cost Bytes Filter
Predicates * Access
Predicates
SELECT STATEMENT
13 1 5 182
SORT
ORDER BY 13 1 5 182
CONCATENATION
TABLE ACCESS
BY INDEX ROWID CUSTOMERS 12 1 2 168
INDEX
RANGE SCAN IDX_CUST_CUSTDATE 3 1 1 "CUST_DATE"<'120731'
TABLE ACCESS
BY INDEX ROWID CUSTOMERS 1 1 2 14
INDEX
RANGE SCAN IDX_CUST_CUSTDATE 3 1 1 LNNVL("CUST_DATE"<'120731') "CUST_DATE">'950501'Just to be complete: you didnt ask for emulating the RR-date-format, did you?
regards
Edited by: chris227 on 17.07.2012 16:09 -
Sort a varchar field numerically
select streetnum from address_points_sp where streetname='THORNWAY' and suffix='AVE' order by streetnum asc
is the sql I'm trying to run. But StreetNum is defined as a varchar... unfortunately. I cannot change the DB schema. Is there a way to do this via sql?
Also, I need to find out the lowest number and the highest....
Thank youIf you are quite sure that you'll only have Numeric data in streetnum field, try TO_NUMBER function.
SQL> desc temp_1
Name Null? Type
COL_1 VARCHAR2(3)
SQL>
SQL> insert into temp_1 values ('3')
2 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> ed
Wrote file afiedt.buf
1 select to_number(col_1)+1 from temp_1
2* where col_1 = '3'
SQL> /
TO_NUMBER(COL_1)+1
4But there is also a potential problem if you have non-numeric data in the field. Like below:
SQL> select to_number(col_1) from temp_1
2 /
select to_number(col_1) from temp_1
ERROR at line 1:
ORA-01722: invalid numberCheers
Sarma.
Maybe you are looking for
-
I try to ignore this message, it show: itunes was not installed correctly. Please reinstall iTunes. Error 7 (Windows error 126)
-
How do I get a specific website to load?
All of a sudden, this afternoon, firefox quit loading any of my schools student web pages. I asked all of my classmates if they were having this issue and the answer was no. I called the school tech support, they checked the server, and said it had t
-
Can we customize the column name in filter view?
When i select filter view and select an option from the drop down, it shows the name of the column and not the variable set in the prompt. I want to customize that name so that it does not show the column name,shows the name given by us instead. Plea
-
Cannot register my photoshops starter edition
I have downloaded Photoshop 3.2 for uplading my camera photos but when i try to register it it doesn't send me an email with the code to put in the box. Can anyone help with this please as I've been on chat and they can't help. If they can't help c
-
3G S stocked in Apple Stores on Saturday?
Did any of you today get a sense, hear, or ask if the Apple stores you were at sold out of their iPhones today? Did any of them say they would have more for Saturday? Any word on whether 16GB or 32GB or BOTH were selling/sold out? I just ordered mine