Home » Developer & Programmer » Application Express, ORDS & MOD_PLSQL » number error in apex during uploading csv file to table
number error in apex during uploading csv file to table [message #459918] |
Wed, 09 June 2010 00:44 |
shobhakashyapgmailcom
Messages: 58 Registered: June 2010 Location: India
|
Member |
|
|
hi
i need to upload the csv file to table.i got the code for it in OTN
site.but it is working well only for the varchar2 type,not with the number type.if i mension number type its giving error during uploading,ERROR:character to Number..
one thing i found in my cade is..i ve a data of type number with single value.but it gives error if i mention number type so i declared it as varchar2(1)..but it is giving ORA-12899: value too large for column "DEV"."SRS_COMC_DATA"."PRIORITY" (actual: 3, maximum: 1).if i declare it as Varchar2(3)..it works fine.but it creates some problem further..plz help me to resolve it soon..
urgent...
[MERGED by LF]
[Updated on: Thu, 10 June 2010 04:02] by Moderator Report message to a moderator
|
|
|
|
Re: number error in apex during uploading csv file to table [message #459934 is a reply to message #459922] |
Wed, 09 June 2010 01:49 |
shobhakashyapgmailcom
Messages: 58 Registered: June 2010 Location: India
|
Member |
|
|
hi,
thanks for your reply..
am not understanding wats the changes in need to made in my code..
i have mensioned VARCHAR2(1 CHAR) only in my table..
my code is as follows to upload the csv to table using oracle apex application
DECLARE
v_clob_data CLOB;
v_blob_data BLOB;
v_clob_len NUMBER;
v_position NUMBER;
--v_raw_chunk RAW(10000);
v_char CHAR (1);
c_chunk_len NUMBER := 1;
v_line VARCHAR2 (32767) := NULL;
v_data_array wwv_flow_global.vc_arr2;
v_rows NUMBER;
v_count NUMBER := 0;
v_add NUMBER := 1;
v_file_size INTEGER := DBMS_LOB.lobmaxsize;
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_blob_csid NUMBER := DBMS_LOB.default_csid;
v_lang_context NUMBER := DBMS_LOB.default_lang_ctx;
v_warning INTEGER;
sep VARCHAR2 (1) := '~';
BEGIN
DELETE FROM BO_TEST_CSV;
DBMS_LOB.createtemporary (v_clob_data, TRUE);
-- Read data from wwv_flow_files
SELECT blob_content
INTO v_blob_data
FROM wwv_flow_files
WHERE last_updated = (SELECT MAX (last_updated) FROM wwv_flow_files)
AND id = (SELECT MAX (id) FROM wwv_flow_files);
DBMS_LOB.CONVERTTOCLOB (v_clob_data,
v_blob_data,
v_file_size,
v_dest_offset,
v_src_offset,
v_blob_csid,
v_lang_context,
v_warning);
v_clob_len := DBMS_LOB.getlength (v_clob_data);
v_position := 1;
-- Read and convert binary to char
WHILE (v_position <= v_clob_len)
LOOP
-- v_raw_chunk := dbms_lob.substr(v_clob_data,c_chunk_len,v_position);
v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
-- v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
v_line := v_line || v_char;
v_position := v_position + c_chunk_len;
IF v_char = CHR (10)
THEN
-- Convert comma to : to use wwv_flow_utilities
-- v_line := REPLACE (v_line, ',', ':');
-- Convert each column separated by : into array of data
-- v_data_array := wwv_flow_utilities.string_to_table (v_line);
v_line := REPLACE (v_line, ',', '~');
v_data_array := wwv_flow_utilities.string_to_table (v_line, sep);
IF v_count > 0
THEN
EXECUTE IMMEDIATE 'insert into SRS_COMC_DATA(OUTAGE,TAR_#,CUSTOMER_NAME,SEVERITY,PRIORITY,RECEIVED,RESOLUTION_TIME)
values (:1,:2,:3,:4,:5,:6,:7)'
USING v_data_array (1),
v_data_array (2),
v_data_array (3),
v_data_array (6),
v_data_array (7),
v_data_array (4),
v_data_array (5);
END IF;
-- Clear out
v_count := v_count + v_add;
v_line := NULL;
END IF;
END LOOP;
END;
table contains::
OUTAGE VARCHAR2(4000)
TAR_# VARCHAR2(4000)
CUSTOMER_NAME VARCHAR2(4000)
SEVERITY, VARCHAR2(1)
PRIORITY, VARCHAR2(1)
RECEIVED, VARCHAR2(4000)
RESOLUTION_TIME VARCHAR2(4000)
i need to make the sevirity and priority column as NUMBER TYPE
please help out
[EDITED by LF: reformatted code and applied [code] tags]
[Updated on: Wed, 09 June 2010 01:54] by Moderator Report message to a moderator
|
|
|
|
|
|
|
Re: number error in apex during uploading csv file to table [message #459980 is a reply to message #459951] |
Wed, 09 June 2010 05:02 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
This is a simple CSV file. Regarding information you provided, I created a table as well as sample control file (used by SQL*Loader) and loaded some records into a table.
This is the first (slightly modified) CSV line and columns you mentioned earlier - you should tell us what goes where (these are just my assumptions)
811953, 7634826.993, 3D SYSTEMS, 7/30/2009 0:00, 5:07:00, 1, 1
------ ----------- ------------- --------------- --------------- -------- --------
outage tar_# customer_name received resolution_time severity priority
OUTAGE VARCHAR2(4000)
TAR_# VARCHAR2(4000)
CUSTOMER_NAME VARCHAR2(4000)
SEVERITY, VARCHAR2(1) -> changed to NUMBER(1), as you wanted it to
PRIORITY, VARCHAR2(1) -> changed to NUMBER(1), as you wanted it to
RECEIVED, VARCHAR2(4000)
RESOLUTION_TIME VARCHAR2(4000)
However, why do you want to put (an obvious) date value (received and resolution_time) into a character column?
Here's how it goes:
SQL> desc apex_test
Name Null? Type
----------------------------------------- -------- ----------------------------
OUTAGE VARCHAR2(4000)
TAR_# VARCHAR2(4000)
CUSTOMER_NAME VARCHAR2(4000)
SEVERITY NUMBER(1)
PRIORITY NUMBER(1)
RECEIVED VARCHAR2(4000)
RESOLUTION_TIME VARCHAR2(4000)
SQL>
A control file:load data
infile check.csv
replace
into table apex_test
fields terminated by ','
trailing nullcols
(outage,
tar_#,
customer_name,
received,
resolution_time,
severity,
priority
)
Loading session and a few loaded records:SQL> $sqlldr scott/tiger@ora10 control=test8.ctl log=test8.log
SQL*Loader: Release 10.2.0.1.0 - Production on Sri Lip 9 11:53:29 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 64
Commit point reached - logical record count 98
SQL> select count(*) from apex_test;
COUNT(*)
----------
98
SQL> select * from apex_test where rownum < 6;
OUTAGE TAR_# CUSTOMER_NAME SEVERITY PRIORITY RECEIVED RESOLUTION
---------- ---------------- -------------------- ---------- ---------- --------------- ----------
811953 7634826.993 3D SYSTEMS 1 1 7/30/2009 0:00 5:07:00
791540 7498330.993 3D SYSTEMS 1 2 5/10/2009 0:00 1:47:00
797537 21347888.6 A3I 1 2 6/7/2009 0:00 1:30:00
796302 21321260.6 AAFES 1 1 5/31/2009 0:00 1:00:00
791043 21212668.6 ACHIEVO CORP 1 1 5/8/2009 0:00 0:28:00
SQL>
I don't know ... something like this seems to be far simpler than your code.
However: I don't know how to make SQL*Loader work from an Apex application. SQLLDR is an executable and it runs at operating system command prompt. I guess that there is a way to call an executable from Apex.
Its "advantage" is that you can run it on any computer with installed Oracle Client software (at least its Utilities). Disadvantage is the same - you have to install SQL*Loader.
External table works on the same principle, but has its (dis)advantages too: user has to have access to the database server (because CSV file must be on a server); directory read/write privileges must be granted. User doesn't have to install any Oracle software on his/her PC.
If you can't afford anything I mentioned, maybe you'll have to fix program you posted earlier.
On the other hand, there might be some other options, but none crosses my mind at the moment.
|
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Jan 22 06:23:28 CST 2025
|