Index as varchar or numeric
Hi:
I'm using a field that contains only digits (0..9) and will use this field as a primary key. Does it make any difference if the field is a varchar or a numeric? I do not plan on performing any mathematical operations on the field's value, so it would be easier to store & retrieve as a varchar. But is it quicker to assess a row based on a primary key which is numeric or varchar?
Thanks.
- Rolf.
You would, potentially, have to call TO_CHAR on the number when you wrote it out, but I would tend to just rely on implicit conversion there. Depending on how you are reading the XML response, you can probably get a numeric value back without doing any conversion.
I would have two primary functional considerations here
1) Is this a key that any human will ever use? If you are generating an invoice number, for example, someone may want to look up that invoice using the invoice number even though invoice number doesn't have any business meaning. Do the users think of this string in numeric terms? Or as a string? For example, do the users see value 1 as the same as 000001? Or would they prefer to always enter the "right" number of characters.
2) Data integrity- if non-numeric characters would be incorrect, the field should be a number. Otherwise, someone will end up writing alphabetical characters to the field.
Both of these would tend toward using NUMBER columns, unless users were really attached to the idea that it isn't invoice #1, it is invoice "000000001".
As secondary factors, numbers are more compact than strings, so performance is likely to be marginally better with numers rather than strings. By the same token, the table and index(es) are likely to cnosume less disk space when you use numbers. Performance here, though, should be a secondary consideration to functionality.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Similar Messages
-
Im getting an error when running a procedure that includes this code.
I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
DECLARE @retval AS DECIMAL(12,2)
DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
DECLARE @sqlcmd AS NVARCHAR(150)
DECLARE @paramdef NVARCHAR(150)
SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
--default
SET @retval = 0.0;
EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
SELECT @retval
DECLARE @return_value DECIMAL(12,2)
EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
@SpreadKey = 1,
@MonthNumber = 4
SELECT 'Return Value' = @return_value
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
>> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
the shoe size, the phone number or something else at run time of this entity.
In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point.
Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity.
Do you know that SQL is a declarative language? This family of languages does not use local variables!
Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.
Think about how silly this is:
SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental.
We need to see the DDL so we can re-write this mess. Want to fix it or not?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Is it possible to use index by varchar in Oracle8i . Is there any other way to simulate this.
That is more commonly known as an associative array (or a hash) and was added in 9.2. You can of course roll your own using a hashing function to convert your string key values into integers within the normal indexing range of a binary_integer array. Of course you need to resolve collisions yourself as well. Here's a snip of code from something similar I did before ...
C_HASH_BASE constant pls_integer := 0;
C_HASH_SIZE constant pls_integer := power(2, 30);
vplsint_hash_value := dbms_utility.get_hash_value(v_key, C_HASH_BASE, C_HASH_SIZE);
-- find the first available slot after the hash location
-- to store the data in
loop
if inout_tab_code.exists(vplsint_hash_value) then
vplsint_hash_value := vplsint_hash_value + 1;
else
inout_tab_code(vplsint_hash_value).key := v_key;
inout_tab_code(vplsint_hash_value).value := v_value;
exit;
end if;
end loop;
-- hash the key value and see if it is present in
-- our hash table
vplsint_hash_value := dbms_utility.get_hash_value(in_key, C_HASH_BASE, C_HASH_SIZE);
-- check all contiguous rows for our key until
-- we find a gap indicating our row is not
-- present in the hash table or we find the key
loop
if in_tab_code.exists(vplsint_hash_value) then
if in_tab_code(vplsint_hash_value).key = in_key then
return in_tab_code(vplsint_hash_value).value;
else
-- try the next hash table entry
vplsint_hash_value := vplsint_hash_value + 1;
end if;
else
return C_UNKNOWN_KEY;
end if;
end loop;Richard -
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. -
Error converting data type varchar to numeric - maybe non printable character?
Hello all. I'm having some trouble converting a column in my table from varchar(50) to decimal(20,4). I've also tried to convert it to int and had no luck. In trying to find the records with non numeric data, I ran this query...
SELECT *
FROM [table]
WHERE [column] not like '%[^0-9]%'
My result set was 32 rows where the field in question had zeros. This doesn't make sense to me. If it was a real zero, it would have been excluded from the query.
So, I flipped it around and ran the following query, and got the same results.
SELECT *
FROM [table]
WHERE [column] = '0'
If it's really a string 0, what would keep it from converting to a numeric type? I'm wondering if there are non printable characters in there because this table was populated via SSIS package using a flat file.
Thanks for any help you can provide!
WeeLassI have discovered one of the values that will not convert. It is '-1.2317 ' and I tried RTRIM and those trailing spaces stay there.
It has a length of 8, and ASCII value of 45, and converting to varbinary gives 0x2D312E3233313709.
The 45 and 2D both point to a negative sign. This one does indeed have a negative sign, but it's in the front, not trailing. Also, another value that was failing was not negative, but did have the trailing spaces.
Any ideas on how to figure out what those spaces actually are? Hopefully, if I know that, then I can know how to get rid of them.
WeeLass
It may be a hard space
RTRIM trims only soft spaces
try this and see if works
REPLACE(ColumnName,CHAR(160),'')
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Oci_bind_array_by_name with pl/sql vararray indexed by varchar
Hello, is it possible to bind with php function "oci_bind_array_by_name" a PL/SQL vararray indexed by varchar2 ? it works quite fine with number indice but with varchar2 indice I get a PLS-00306 wrong number or types of arguments in call to 'string'
$statement = oci_parse($c, "BEGIN arraybindpkg1.iobind(:c1); END;");
$array = array('one'=>'1', 'two'=>'2', 'three'=>'3', 'four'=>'4', 'five'=>'5');
oci_bind_array_by_name($statement, ":c1", $array, 5, -1, SQLT_CHR);
oci_execute($statement);
Thank's for help
OlivierNot possible in PHP, I believe. I'm not sure whether the OCI C code API even supports this.
-
WHat is the best index type for non uniqueness / Varchar columns in SQL 2008 R2
Hello All Greetings,
Please help me here with my doubt,
in my table i have two columns about a million rows, it has about 20 columns in it, three columns with name as Period, Gender so most of the time these two columns use in where clause,
Gender will contain Either M or F , Period contains YYYY-Month (2013-December, 2013-August) etc so i would like to add a Index to these two columns so that in will increase the performance, so please let me know what type of indexes i need to add to
these columns in the table,
please note that only one time we will add data to the table which will take only 2 minutes but we query the table every day
so my question what is the best index type that i need to create on columns with non uniqueness values in the column.,
Thank you In Advance,
MilanThere is nothing whatever wrong with creating an index on a VARCHAR column, or set of columns.
Regarding the performance of VARCHAR/INT, as with everything in a RDBMS, it depends on what you are doing. What you may be thinking of is the fact that clustering a table on a VARCHAR key is (in SQL Server) marginally less efficient than clustering on a monotonically
increasing numerical key, and can introduce fragmentation.
Or you may be thinking of what you have heard about writing JOINs on VARCHAR columns - it is true, it is a little less efficient than a JOIN on numeric type, but it is only a little less efficient, nothing that would lead you to never join on varchar cols.
None of this does not mean that you should not create indexes on VARCHAR columns. A needed index on a VARCHAR column will boost query performance, often by orders of magnitude. If you need an index on a VARCHAR, create it. It makes no sense to try to find an
integer column to create the index on - the engine will never use it.
Check this reference: http://stackoverflow.com/questions/14041481/is-it-good-to-create-a-nonclustered-index-on-a-column-of-type-varchar
Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
INSQLSERVER.COM
Mohammad Nizamuddin -
Convert varchar to decimal - arithmetic overflow
I'm using SQL Server 2014 and I'm trying to convert data from a staging table over to a production table. I seem to be getting an Arithmetic overflow error converting varchar to numeric on the decimal conversion. I'm sure I've overlooked something with the
syntax of the CONVERT.
This is the staging table:
CREATE TABLE [dbo].[staging_table](
[TimeIndex] [varchar](100) NULL,
[Cluster] [varchar](100) NULL,
[AvgMem] [varchar](100) NULL,
[AvgCPU] [varchar](100) NULL,
[TotalMemory] [varchar](100) NULL,
[TotalCPU] [varchar](100) NULL,
[Datacenter] [varchar](100) NULL,
[vCenter] [varchar](100) NULL
) ON [PRIMARY]
This is the prod table I'm moving it to:
CREATE TABLE [dbo].[Clusters](
[ClusterID] [int] IDENTITY(1,1) NOT NULL,
[ClusterName] [varchar](25) NULL,
[DatacenterName] [varchar](25) NULL,
[TimeIndex] [datetime] NULL,
[AvgCPU] [decimal](5, 2) NULL,
[AvgMem] [decimal](5, 2) NULL,
[TotalCPU] [decimal](8, 2) NULL,
[TotalMem] [decimal](8, 2) NULL,
[vCenterID] [int] NULL,
CONSTRAINT [PK_Clusters_1] PRIMARY KEY CLUSTERED
[ClusterID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
and here's an example INSERT INTO statement throwing the error:
INSERT INTO [dbo].[Clusters] (ClusterName,DatacenterName,TimeIndex,AvgCPU,AvgMem,TotalCPU,TotalMem,vCenterID)
SELECT SUBSTRING(Cluster,1,25) AS ClusterName,
SUBSTRING(Datacenter,1,25) AS DatacenterName,
CONVERT(datetime,TimeIndex,103) AS TimeIndex,
CONVERT(decimal(5,2),AvgCPU) AS AvgCPU,
CONVERT(decimal(5,2),AvgMem) AS AvgMem,
CONVERT(decimal(8,2),TotalCPU) AS TotalCPU,
CONVERT(decimal(8,2),TotalMemory) AS TotalMem,
'3' FROM [dbo].[staging_table]
Sample data is 0.00 to 100.00 in fields AvgCPU and AvgMem, and TotalCPU and TotalMem usually goes up to about 7 digits with no decimal (eg. 7543253) but could be 8 and although I've never seen a decimal I wouldn't rule it out so decided to account for it.
I assume it's something I've overlooked with the syntax but any ideas would help.
Thanks
AdamThe problem is your precision and scale you are assigning to your decimals.
decimal(5,2) = this is a total of 5 digits, 3 digits for the whole number and 2 for the fractional.
decimal(8,2) = this is a total of 8 digits, 6 digits for the whole number and 2 for the fractional.
So converting a varchar of 7 or 8 digits for TotalCPU or TotalMem will give you an error because your definition will actually only allow for 6 digits of storage. You could test this by doing decimal(8,0) or decimal(10,2) both which will allow for up to
8 whole numbers.
If you are worried about space Sql Server will allocate a set number of bytes for ranges based on the precision (first number in the parenthesis). See this page which explains in detail how much space each range takes up and also further details on
decimal and numerics.
-Igor -
I have a mif file from which I need to create a 1 level index.
I have numerous data which contains a colon; so the MText tag looks something like this - <MText `Accredited: Representative'>
Now, I know that the function of a colon is "Separates levels in an entry"
I also read "Note: To enter a backslash or any special character used in these building blocks—colon, semicolon, bracket, or angle bracket—as regular characters, precede it with a backslash (\)."
I can make the MText look like this - <MText `Acccredited\: Representative'>
But this does not work; I still get a 2 level entry in my index. What am I missing?
Any help is greatly appreciated.Entering:
colon\: test
in the normal Special > Marker > Marker Text: field
then saving the file as MIF, and searching for it, finds:
<MText `colon\\: test'>
Apparently the rule is single-escape for dialogs, double-escapes in MIF. -
Hi,
I'am working on a catalogue which has 12 separate section (indesign files) controlled by a book file.
My issue is that when I generate the index through all book sections it crashes indesign. I can though generate separate indexes for each section but then its not all in numerical order.
Is there any way of combining the separate section indexes and make them numerical??
I tried the same files on a machine with CS4 and it did the same thing.
Any ideas or work arounds for this as I'm rapidly losing my hair as the deadline is next week.
Cheers for any help at all.I can't think of anything you can do except (a) fix that crash, which shouldn't be happening and doesn't on most installations, or (b) print out all of the indexes and collate them manually.
Have you done the "usual" fixes of removing preferences, clearing font caches, searching for missing fonts, and checking for ID updates?
Can you temporarily remove certain documents from the book to see if there's one document that's causing the crash? Or does it crash any time you make an index from a file outside of the one holding the index? If you start a new set of test documents, do they crash also? -
Is it needed to convert the values frm text field to numeric for sql server
hi all,
i'm using tomvat4.0,back end sql server 200.
when i insert the values in to the table it is giving an exception sayin "Error in converting varchar to numeric"
is it necessary to convert those strings from text fields into int before passing them to the sql query..
i think it is not necessary for oracle..but not sure with sql server..
pls help me
cheers
chanduyap, every thing is fine...
n i got the solution...when the text field is left blank....the requst.getParameter returns [coe]""(null)
wen the database is lookin for a numeric it is giving null...which is not acceptable...
so inserted this code...
if(request.getParameter("...").equals("")) {
//assign zero to a variable then insert that variable....
}thanx for the responses
cheers
May the solutions to one's problem pop up in one's mind itself
chandu -
Varchar(max) vs varchar(255)
Hi guys,
I'm new to MS-SQL 2005, I will ask you a bunch of questions and I hope I will not be too boring hehe !
I learned that in MS-SQL 2005, you can now use varchar(max), my question is why not always use varchar(max) since it will automatically use only the space needed ? Is there an advantage in specifying a size other than max when you use a varchar for an entry that can vary in length alot ?
Thank you very much,
KonnanThere are a few diferences between VARCHAR(1-8000) and VARCHAR(MAX).
when you store data to a VARCHAR(N) column, the values are physically stored in the same way. But when you store it to a VARCHAR(MAX) column, behind the screen the data is handled as a TEXT value. So there is some additional processing needed when dealing with a VARCHAR(MAX) value. (only if the size exceeds 8000)
VARCHAR(MAX) or NVARCHAR(MAX) is considered as a 'large value type'. Large value types are usually stored 'out of row'. It means that the data row will have a pointer to another location where the 'large value' is stored. By default sql server will try to accomodate the value 'in row' but if it could not, it will store the large values 'out of row'. When values are stored 'out of row' there will be slight processing overhead in reading the information. Here is a good reference: http://msdn2.microsoft.com/en-us/library/ms189087.aspx
I guess you cannot index a VARCHAR(MAX)/NVARCHAR(MAX) column.
coming back to your question:
I dont think it is bad to use VARCHAR(MAX) is bad. If you are storing smaller piecs of data in a VARCHAR(MAX) column, it will be treated as normal. If you dont want to index the column, then you can definitely go with VARCHAR(MAX) option.
But most people do not advise that. First of all, by having a VARCHAR(MAX) will confuse some one who looks at the data later on. For example, if you want to store a comment of 100 characters or address of 80 characters, why should you go for VARCHAR(MAX)? If you use Address VARCHAR(MAX), comments VARCHAR(MAX), Name VARCHAR(MAX), some one trying to read or write data on a later date will be confused. They will not know what is the expected size of the data and they will be compelled to use LARGE VALUE types always.
Again, these are not rules but conventions. -
CLOB / Charset / Java / Unix Issue
Hi,
I'm encountering the following problem.
I'm working on a 3-tiers architecture with an Oracle Database (8.1.7)
a Weblogic application server 6.1 SP4 and a Web server under Aix 4.3
(all 3 are under AIX 4.3 on the same platform).
My application has a web interface that allows users to upload files
to the server from their PC clients and a webbrowser, that insert each
file into a oracle Clob (via Java Code) and that call a stored
procedure (with java code again) to extract this clob to a file
(UTL_file package), then, the extracted file is processed line by line
and information inserted in others tables.
The issue is that some characters (acute, grave accent ....etc)
appears as question marks in the database or that some date from the
file can't be processed because they are structured as DD/MM/YYYY
(french notation, but that normal I'm from france).
I first thougt of an NLS_LANG problem but on the weblogic server it is
set to french_france.WE88859P15 that seems to be right and the same
the database configuration.
I then tried to performs some conversion when the clob data were
extracted to file (from WE88859P15 TO CP152 or vice-versa) with the
oracle convert function but it seems that it doesn't work.
An other but coherent symptoms is that the extracted files (from the
clob columns) seems not to be fine (accent are not recognized).
This is the java code used to load file to clob (on the weblogic
server side)
con = dbHandle.getAdminConnection();
con.setAutoCommit(false);
/// NEW IMPORT
// int taskId = DBTools.getOraSeqValue("vtr.VTR_SEQ_LOG_IMPORT",
DBTools.NEXTVAL,con);
int taskId = DBTools.getOraSeqValue(SqlQueryDefinition.seqLogImport.toString(),
DBTools.NEXTVAL,con);
Debug.out.println("taskId " + taskId);
// String cmd = "insert into vtr.vtr_log_import
(cod_task,DTE_DEBUT,lob_imp,lob_rej,lob_log, txt_nom_fic_orig,
txt_utilisateur) " +
// "values ("+ taskId
+",sysdate,empty_clob(),empty_clob(),empty_clob(), '"+file+"','"+
((UserBean)request.getSession().getAttribute("userbean")).getIdentifier()+"')";
// stmt = con.createStatement();
// stmt.executeQuery(cmd);
// stmt.close();
pstmt = con.prepareStatement(SqlQueryDefinition.initLigneImport.toString());
pstmt.setInt(1,taskId);
pstmt.setString(2,file);
pstmt.setString(3,((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
pstmt.executeQuery();
pstmt.close();
con.commit();
// Writing CLOB
// cmd = "SELECT cod_task,lob_imp,lob_rej,lob_log FROM
vtr.vtr_log_import WHERE cod_task="+ taskId +" for update";
// stmt = con.createStatement();
// rset = stmt.executeQuery(cmd);
pstmt = con.prepareStatement(SqlQueryDefinition.setBlobImport.toString());
pstmt.setInt(1,taskId);
rset = pstmt.executeQuery();
rset.next();
File csvFile = new File(localFile);
System.out.println("csvFile length = " + csvFile.length());
File unixFile = new File(localFile+".ux");
Tools.dos2Unix(csvFile, unixFile);
FileInputStream instream = new FileInputStream(unixFile);
// support Weblogic
clob = ClobComponent.factory(DBUtil.getInstance().isWebLogicPlatform());
clob.setClob(rset,2);
outstream = clob.getAsciiOutputStream();
size = clob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
instream.close();
outstream.close();
rset.close();
// stmt.close();
pstmt.close();
rset=null;
// stmt = null;
pstmt=null;
con.commit();
// IMPORT
cs = con.prepareCall(SqlQueryDefinition.importStoredProc.toString());
index = 1;
cs.setString(index++, fullPath); // 1
cs.setString(index++,
((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
// 2
cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 3
cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 4
cs.registerOutParameter(index++,java.sql.Types.NUMERIC); // 5
cs.setInt(index++, taskId); // 6
cs.executeQuery();
String fichier1 = cs.getString(3);
String fichier2 = cs.getString(4);
int returnCode = cs.getInt(5);
System.out.println("returnCode/fichier1/2 : " + returnCode + " & "
+ fichier1 + " & " + fichier2);
cs.close();
con.commit();
This is the PL/SQL code used to unload clob to dile (on the oracle
side)
PROCEDURE writeToFile (id NUMBER, a_fichier VARCHAR2)
IS
result CLOB;
cvl_tmp VARCHAR2 (32000);
nvl_amount NUMBER := 250;
nvl_pos NUMBER := 1;
nvl_clob_length NUMBER;
instr_pos NUMBER;
file_handle UTL_FILE.file_type;
BEGIN
file_handle := UTL_FILE.FOPEN(
substr(a_fichier, 1, instr(a_fichier, file_separator, -1,
1)-1), -- dir
substr(a_fichier, instr(a_fichier, file_separator, -1, 1)+1),
-- file
'W');
select lob_imp
INTO result
from vtr_log_import
where cod_task = id;
--write clob to file
nvl_clob_length := DBMS_LOB.getlength (result);
cvl_tmp := NULL;
nvl_amount := 250;
nvl_pos := 1;
LOOP
instr_pos :=
DBMS_LOB.INSTR (result, CHR (10), nvl_pos, 1) -
nvl_pos;
--DBMS_OUTPUT.PUT_LINE(nvl_pos||': Of length : '||instr_pos);
IF nvl_pos + instr_pos > nvl_clob_length
THEN
instr_pos := nvl_clob_length - nvl_pos;
DBMS_LOB.READ (
lob_loc=> result,
amount=> instr_pos,
offset=> nvl_pos,
buffer=> cvl_tmp
EXIT;
END IF;
DBMS_LOB.READ (
lob_loc=> result,
amount=> instr_pos,
offset=> nvl_pos,
buffer=> cvl_tmp
-- DBMS_OUTPUT.PUT_LINE(cvL_tmp);
cvl_tmp := CONVERT(cvl_tmp, 'WE8MSWIN1252', 'WE8ISO8859P15');
UTL_FILE.put_line (file_handle, cvl_tmp);
nvl_pos := nvl_pos
+ instr_pos
+ 1;
IF nvl_pos > nvl_clob_length
THEN
EXIT;
END IF;
END LOOP;
UTL_FILE.fclose (file_handle);
END writeToFile;
I'm using the oracle thin driver but it's not set in classpath maybe a
problem with that ?
<JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
InitialCapacity="1" MaxCapacity="100" Name="oracleUserPool"
Password="XXXXXXX
Properties="user=vtr_usr;dll=ocijdbc8;protocol=thin"
Targets="myserver" TestConnectionsOnRelease="true"
TestConnectionsOnReserve="true" TestTableName="dual"
URL="jdbc:oracle:thin:@localhost:1521:ssr"/>
Maybe a problem with the properties of weblogic.codeset (I don"t set
it) ?
Many thanks in advance, I have no idea even if I suspect the java
store to file or the UTL_file extration to file steps to be in cause !
Run-ORun-O wrote:
Hi,
I'm encountering the following problem.Hi. The first thing I'd do to narrow the search is to see if my Java code
worked in a standalone program, without weblogic in the picture. Once
you get Oracle's JDBC driver to work with Oracle's DBMS, it shouldn't
be hard to get the same stuff to work inside weblogic, or find out why it
doesn't.
Joe
>
>
I'm working on a 3-tiers architecture with an Oracle Database (8.1.7)
a Weblogic application server 6.1 SP4 and a Web server under Aix 4.3
(all 3 are under AIX 4.3 on the same platform).
My application has a web interface that allows users to upload files
to the server from their PC clients and a webbrowser, that insert each
file into a oracle Clob (via Java Code) and that call a stored
procedure (with java code again) to extract this clob to a file
(UTL_file package), then, the extracted file is processed line by line
and information inserted in others tables.
The issue is that some characters (acute, grave accent ....etc)
appears as question marks in the database or that some date from the
file can't be processed because they are structured as DD/MM/YYYY
(french notation, but that normal I'm from france).
I first thougt of an NLS_LANG problem but on the weblogic server it is
set to french_france.WE88859P15 that seems to be right and the same
the database configuration.
I then tried to performs some conversion when the clob data were
extracted to file (from WE88859P15 TO CP152 or vice-versa) with the
oracle convert function but it seems that it doesn't work.
An other but coherent symptoms is that the extracted files (from the
clob columns) seems not to be fine (accent are not recognized).
This is the java code used to load file to clob (on the weblogic
server side)
con = dbHandle.getAdminConnection();
con.setAutoCommit(false);
/// NEW IMPORT
// int taskId = DBTools.getOraSeqValue("vtr.VTR_SEQ_LOG_IMPORT",
DBTools.NEXTVAL,con);
int taskId = DBTools.getOraSeqValue(SqlQueryDefinition.seqLogImport.toString(),
DBTools.NEXTVAL,con);
Debug.out.println("taskId " + taskId);
// String cmd = "insert into vtr.vtr_log_import
(cod_task,DTE_DEBUT,lob_imp,lob_rej,lob_log, txt_nom_fic_orig,
txt_utilisateur) " +
// "values ("+ taskId
+",sysdate,empty_clob(),empty_clob(),empty_clob(), '"+file+"','"+
((UserBean)request.getSession().getAttribute("userbean")).getIdentifier()+"')";
// stmt = con.createStatement();
// stmt.executeQuery(cmd);
// stmt.close();
pstmt = con.prepareStatement(SqlQueryDefinition.initLigneImport.toString());
pstmt.setInt(1,taskId);
pstmt.setString(2,file);
pstmt.setString(3,((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
pstmt.executeQuery();
pstmt.close();
con.commit();
// Writing CLOB
// cmd = "SELECT cod_task,lob_imp,lob_rej,lob_log FROM
vtr.vtr_log_import WHERE cod_task="+ taskId +" for update";
// stmt = con.createStatement();
// rset = stmt.executeQuery(cmd);
pstmt = con.prepareStatement(SqlQueryDefinition.setBlobImport.toString());
pstmt.setInt(1,taskId);
rset = pstmt.executeQuery();
rset.next();
File csvFile = new File(localFile);
System.out.println("csvFile length = " + csvFile.length());
File unixFile = new File(localFile+".ux");
Tools.dos2Unix(csvFile, unixFile);
FileInputStream instream = new FileInputStream(unixFile);
// support Weblogic
clob = ClobComponent.factory(DBUtil.getInstance().isWebLogicPlatform());
clob.setClob(rset,2);
outstream = clob.getAsciiOutputStream();
size = clob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
instream.close();
outstream.close();
rset.close();
// stmt.close();
pstmt.close();
rset=null;
// stmt = null;
pstmt=null;
con.commit();
// IMPORT
cs = con.prepareCall(SqlQueryDefinition.importStoredProc.toString());
index = 1;
cs.setString(index++, fullPath); // 1
cs.setString(index++,
((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
// 2
cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 3
cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 4
cs.registerOutParameter(index++,java.sql.Types.NUMERIC); // 5
cs.setInt(index++, taskId); // 6
cs.executeQuery();
String fichier1 = cs.getString(3);
String fichier2 = cs.getString(4);
int returnCode = cs.getInt(5);
System.out.println("returnCode/fichier1/2 : " + returnCode + " & "
+ fichier1 + " & " + fichier2);
cs.close();
con.commit();
This is the PL/SQL code used to unload clob to dile (on the oracle
side)
PROCEDURE writeToFile (id NUMBER, a_fichier VARCHAR2)
IS
result CLOB;
cvl_tmp VARCHAR2 (32000);
nvl_amount NUMBER := 250;
nvl_pos NUMBER := 1;
nvl_clob_length NUMBER;
instr_pos NUMBER;
file_handle UTL_FILE.file_type;
BEGIN
file_handle := UTL_FILE.FOPEN(
substr(a_fichier, 1, instr(a_fichier, file_separator, -1,
1)-1), -- dir
substr(a_fichier, instr(a_fichier, file_separator, -1, 1)+1),
-- file
'W');
select lob_imp
INTO result
from vtr_log_import
where cod_task = id;
--write clob to file
nvl_clob_length := DBMS_LOB.getlength (result);
cvl_tmp := NULL;
nvl_amount := 250;
nvl_pos := 1;
LOOP
instr_pos :=
DBMS_LOB.INSTR (result, CHR (10), nvl_pos, 1) -
nvl_pos;
--DBMS_OUTPUT.PUT_LINE(nvl_pos||': Of length : '||instr_pos);
IF nvl_pos + instr_pos > nvl_clob_length
THEN
instr_pos := nvl_clob_length - nvl_pos;
DBMS_LOB.READ (
lob_loc=> result,
amount=> instr_pos,
offset=> nvl_pos,
buffer=> cvl_tmp
EXIT;
END IF;
DBMS_LOB.READ (
lob_loc=> result,
amount=> instr_pos,
offset=> nvl_pos,
buffer=> cvl_tmp
-- DBMS_OUTPUT.PUT_LINE(cvL_tmp);
cvl_tmp := CONVERT(cvl_tmp, 'WE8MSWIN1252', 'WE8ISO8859P15');
UTL_FILE.put_line (file_handle, cvl_tmp);
nvl_pos := nvl_pos
+ instr_pos
+ 1;
IF nvl_pos > nvl_clob_length
THEN
EXIT;
END IF;
END LOOP;
UTL_FILE.fclose (file_handle);
END writeToFile;
I'm using the oracle thin driver but it's not set in classpath maybe a
problem with that ?
<JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
InitialCapacity="1" MaxCapacity="100" Name="oracleUserPool"
Password="XXXXXXX
Properties="user=vtr_usr;dll=ocijdbc8;protocol=thin"
Targets="myserver" TestConnectionsOnRelease="true"
TestConnectionsOnReserve="true" TestTableName="dual"
URL="jdbc:oracle:thin:@localhost:1521:ssr"/>
Maybe a problem with the properties of weblogic.codeset (I don"t set
it) ?
Many thanks in advance, I have no idea even if I suspect the java
store to file or the UTL_file extration to file steps to be in cause !
Run-O -
Query Report:To Retrieve Data from A/R Invoice and A/P Invoice
Hii Experts,
I am a new Sap B1 Trainee.I am facing a problem when retrieving data from A/R Invoice and A/P Invoice in order to track
Expenditure and Revenue according to a Bussiness partner,
I am using union to retrieve the information,but it is saying a error that Error Converting Varchar to Numeric and also
i would like to know how can i show the total final payment by reflecting Downpayments in A/R Invoice and A/P Invoice
With Regards
Cherry.Hii.
My Sap B1 version is 8.8.1 and patch level is 20. Actully i need a scenario where i can able to show both Expenditure and Revenue of a particular bussiness partner and profit/loss in a single query report.
I need some tips regarding this,When i am doing union i am getting conversion error converting varchar to numeric when i take
Sum(Line Total) from OINV and Sum(line total) OPCH group by docdate and docentry and BP .
and another scenario is how to deduct A/P downpayment or A/R downpayment from A/P invoices and A/R invoice to get the final Revenue and Expenditure ..
Thanks & Regards
Cherry -
Unit price validation in Purchase Order, Goods Receipt PO and A/R Invoice
Hello!
I want to have validation of the Unit Price field in Purchase Order, Goods Receipt PO and A/R Invoice documents.
This means that user has to get some kind of message if she/he do not enter the Unit price in above mentioned documents.
I can not use the price lists for this, to get the field populated automatically, because I do not have all the prices...
I am no longer newbie when it come to SAP, but this really puzzles me
Thanks,
DejanHello guys,
I have tried to add this code to check if the field Unit Price was empty in the Purchase Order form (Object ID 22)
But it gives me an error message - Error converting data type varchar to numeric (CINF)
I am getting the same error message even if I have some value in the Unit Price field...
I am really confused - what is wrong with it???
Here is the code from the Transaction notification
IF (@object_type = N'22' AND @transaction_type in (N'A', N'U') )
BEGIN
IF EXISTS (SELECT T1.DocEntry FROM OPOR T0 inner join POR1 T1 on T0.DocEntry = T1.DocEntry
WHERE (T1.PriceBefDi IS NULL OR T1.PriceBefDi = ' ') AND T0.DocEntry = @list_of_cols_val_tab_del)
BEGIN
Set @error =1
set @error_message = 'Unit Price cannot be blank'
END
END
Thanks,
Dejan
Maybe you are looking for
-
How do I add video to my iphone with icloud
How do I add videos (personal; not music or ripped) to my iphone when using iCloud? These used to sync over when I used itunes but with the transition to icloud, when I plug in to my computer (a PC), itunes wants to restore the phone or set it up aga
-
Error while creating excise invoice to return Delivery (J1IS)
Dear all, Plz help to solve this problem. After MIGO. I have done return delivery to vendor(Movt-122). With ref to the return delivery doc I am trying to create excise invoice to send to vendor in J1IS. but error appears as Vendor not related to mate
-
How do you add a dingbat to character viewer in order to select it?
I understand that being unicode pages cannot use ITC Zaph dingbats from the keyboard that i need to use the special characters. very awkward! but how do i insert a character from zaph dignbat into special characters? thank you
-
Exchange 2010 Export Mailbox to PST using only .EDB file
I have Exchange 2010 SP2 Update Rollup 4, SBS 2011 (which is similar to Server 2008 R2). I have recently recovered from a server crash due to a faulty RAID controller and need to recover some e-mail (and possibly contacts) from a couple of mailboxes.
-
Program rfumsv00(VAT return) not displaying VAT amount correctly
Id like to post an invoice purely to record the VAT on an invoice. I dont have a base amount. How do I do this? I posted a document in SAP with the VAT amount. But when I run the advance tax report in SAP - rfumsv00, the tax amount i posted is appear