CONVERTTOCLOB procedure
I'm new to using this procedure.
There is a ConvertToClob procedure in Oracle that I want to use.
I have a BLOB named BLOB_CONTENT already being inserted into my database table named "xmltest2" I want to be able to either
1) Extract the Blob_content out of the table and convert it into a clob -OR-
2) Have the blob convert over to clob before inserting into the table.
Either is fine as long as it converts. lol
I have this so far.
Begin
-- this portion works just fine to add the BLOB into my database.
insert into xmltest2 (ID,ITEM_ID,TYPE,ENTERED_DATE,ENTERED_BY,VALIDATED,VALIDATED_DATE,VALIDATED_BY,
FILENAME, blob_content, clob_content)
select item_xml_seq.nextval,gda_item_id, v_xml_type, v_entered_date, v_entered_by,
v_validated, v_validated_date, v_validated_by, name, blob_content, clob_content
from gda_files@apex_gda_dev
where gda_item_id = v_item_id and name = v_file_name_xml;
---Here is where I think I am having issues. I have also put update SQL command at the end but it doesnt change anything.
DBMS_LOB.CREATETEMPORARY(lob_loc=>src_blob, cache=>TRUE, dur=>dbms_lob.SESSION);
DBMS_LOB.CREATETEMPORARY(lob_loc=>dest_lob, cache=>TRUE, dur=>dbms_lob.SESSION);
DBMS_LOB.CONVERTTOCLOB(dest_lob,src_blob,amount,dest_offset,src_offset,blob_csid,lang_context,warning);
Ive seen small bits of information on using a loop but thats probably over doing what I need. I just need the Blob to convert to clob and insert it into the table. Does anyone have any suggestions?
Thank you for any help. :))
Hello,
You can just try this function to convert the BLOB data to CLOB.
Before converting this just create this function.
Then you may try as given below
Declare
b blob;
c clob;
begin
select blobdata into b from table_name;
c := blob2clob(b);
-- Use this clob data and insert into the table.
end;
FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
-- typecasts BLOB to CLOB (binary conversion)
IS
|| Purpose : To Convert a BLOB File to CLOB File
|| INPUT : BLOB File
|| OUTPUT : CLOB File
|| History: MB V5.0 24.09.2007 RCMS00318572 Initial version
ln_file_check NUMBER;
ln_file_size NUMBER;
v_text_file CLOB;
v_binary_file BLOB;
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
v_warning INTEGER;
csid VARCHAR2(100) := 'WE8ISO8859P15'; --'AL32UTF8';
lv_data CLOB;
ln_length NUMBER;
BEGIN
DBMS_LOB.createtemporary (v_text_file, TRUE);
SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
--DBMS_LOB.convertToClob(file_clob,file_blob,ln_file_size,ln_file_size,1);
--dbms_output.put_line(ln_file_size);
DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
--dbms_lob.substr(v_text_file,ln_file_size,1) into lv_data from dual;
RETURN v_text_file;
END;
Similar Messages
-
UTF-8 stored in VARCHAR2 on a non-Unicode DB
Hi there,
we have a company that implements storing Unicode data in Oracle in the following way:
A plain VARCHAR2 on a non-Unicode DB (charset is actually WE8MSWIN1252) receives UTF-8 coded data.
As client and server have the same setting for NLS_LANG, no conversion takes place, and the app will run fine.
(in my eyes, a clean way to set this up would be utilizing NVARCHAR fields for this, but this is no option)
But: how can I do query based on these columns without getting garbage for each non-ASCII character?
I imagine setting up views for that purpose, but I need the syntax on how to re-interpret the UTF-8 data coming from a VARCHAR2 field.
I tried the following:
SELECT CONVERT(column, 'WE8MSWIN1252', 'AL32UTF8') FROM table where ...
This will give me the right data on a client with cp 1252 set up, with the restriction to 8 bit output.
Now I would like to have a Unicode-capable application like SQL*Developer to be fully capable of dealing with the Unicode data, but I guess, for that to work, I would need the DB to deliver a NVCHAR2 output from the above query?
Any help and comments appreciated.
Tom
Message was edited by: snmdlawe have a company that implements storing Unicode data in Oracle in the following way:
No - they don't. They are NOT storing unicode data - they are storing individual one-byte characters and using that VARCHAR2 column as a BLOB. Ask them how, of if, they query the data.
A plain VARCHAR2 on a non-Unicode DB (charset is actually WE8MSWIN1252) receives UTF-8 coded data.
No - it doesn't. It receives a string of one byte characters in the WE8MSWIN1252 character set. It does not know, or care, what those one-byte characters represent. All you are doing is storing BINARY data in that VARCHAR2 column one byte at a time. When you query it you will get one or several bytes back - but since Oracle thinks it is really character data, when it is actually binary, you can only match it by matching those one-byte characters.
I imagine setting up views for that purpose, but I need the syntax on how to re-interpret the UTF-8 data coming from a VARCHAR2 field.
You don't have UTF-8 data - you have a BLOB that you need to convert to UTF-8 data. You can use the DBMS_LOB.CONVERTTOCLOB procedure to do the conversion and specify the character set to use. See the DBMD_LOB API
http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_lob.htm#i1020356
CONVERTTOCLOB Procedure
This procedure takes a source BLOB instance, converts the binary data in the source instance to character data using the character set you specify, writes the character data to a destination CLOB or NCLOB instance, and returns the new offsets.
See this AskTom article for further review
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3575852900346063772 -
Hi,
Has anybody been successful in using the DBMS_LOB.ConvertToClob procedure. It's giving me "invalid lob locator specified" error.
here's my code
create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
v_file_blob blob;
v_file_clob clob;
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;
begin
select a.blob_content into v_file_blob
from txt_files a
where name = p_file;
dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
v_dest_offset, v_src_offset, v_blob_csid,
v_lang_context, v_warning);
if v_warning = 0 then
return v_file_clob;
end if;
end;
Any help would be greatly appreciated
Thanks.I figured it out...
here 's the new code..
create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
v_file_blob blob;
v_file_clob clob;
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;
begin
select a.blob_content into v_file_blob
from txt_files a
where name = p_file;
-- the following line solved it
DBMS_LOB.CREATETEMPORARY(v_file_clob, TRUE);
dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
v_dest_offset, v_src_offset, v_blob_csid,
v_lang_context, v_warning);
if v_warning = 0 then
return v_file_clob;
end if;
end; -
I have a problem I hope someone can help with.
I am reading CSV files and storing as a BLOB. Later I want to interpret the contents of the BLOB so I am using the DBMS_LOB.convertToCLOB procedure. How should I use the blob_csid and lang_context parameters if my original file was taken from a PC using one character set (e.g. WE8MSWIN1252) and the server database has a different character set (e.g. AL32UTF8)? The CSV file can contain extended characters like trade mark (™) and copyright (©) symbols.
Any help gratefully received,
Thanks.Yes, you can according to http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm#ADFNS012:
- see "Example: Modifying LOB Columns with a Trigger" section
- no DBMS_LOB mentioned in "Restrictions on Creating Triggers " section. -
ConvertToClob and byte order mark for UTF-8
We are converting a blob to a clob. The blob contains the utf-8 byte representation (including the 3-byte byte order mark) of an xml-document. The clob is then passed as parameter to xmlparser.parseClob. This works when the database character set is AL32UTF8, but on a database with character set WE8ISO8859P1 the clob contains an '¿' before the '<'AL32UTF8');
I would assume that the ConvertToClob function would understand the byte order mark for UTF-8 in the blob and not include any parts of it in the clob. The byte order mark for UTF-8 consists of the byte sequence EF BB BF. The last byte BF corresponds to the upside down question mark '¿' in ISO-8859-1. Too me, it seems as if ConvertToClob is not converting correctly.
Am I missing something?
code snippets:
l_lang_context number := 1;
dbms_lob.createtemporary(l_file_clob, TRUE);
dbms_lob.convertToClob(l_file_clob, l_file_blob,l_file_size, l_dest_offset,
l_src_offset, l_blob_csid, l_lang_context, l_warning);
procedure fetch_xmldoc(p_xmlclob in out nocopy clob,
o_xmldoc out xmldom.DOMDocument) is
parser xmlparser.Parser;
begin
parser := xmlparser.newParser;
xmlparser.parseClob(p => parser, doc => p_xmlclob);
o_xmldoc := xmlparser.getDocument(parser);
xmlparser.freeParser(parser);
end;The database version is 10.2.0.3 on Solaris 10 x86_64
Eyðun
Edited by: Eyðun E. Jacobsen on Apr 24, 2009 8:58 PMcan this be of some help? http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions027.htm#SQLRF00620
Regards
Etbin -
Upload/import procedure works only when last column filled
To upload csv-files I use something like
TYPE line_tab_type IS TABLE OF VARCHAR2 (4000)
INDEX BY BINARY_INTEGER;in the package header
and the procedure itself looks like
PROCEDURE get_mitglieder_csv (p_file_name IN VARCHAR2,
p_rec_sep IN VARCHAR2,
p_header IN VARCHAR2,
p_blzkto IN VARCHAR2
) IS
v_binary_file BLOB;
v_text_file CLOB;
-- Conversion Variables
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
v_warning INTEGER;
-- Parsing Variables
v_rec_sep_len PLS_INTEGER;
v_start_pos PLS_INTEGER := 1;
v_end_pos PLS_INTEGER := 1;
v_line_num PLS_INTEGER := 1;
v_file_length PLS_INTEGER;
-- Parsing Line Variables
v_field_array wwv_flow_global.vc_arr2;
p_lines line_tab_type;
doszeilen CONSTANT VARCHAR2(2) := CHR(13) || CHR(10);
unixzeilen CONSTANT VARCHAR2(1) := CHR(10);
geloescht BOOLEAN := FALSE;
err_code NUMBER;
err_msg VARCHAR2(400);
BEGIN
IF p_file_name IS NULL THEN
raise_application_error(-20000, 'Dateiname wird benoetigt');
END IF;
IF p_rec_sep IS NULL THEN
raise_application_error(-20000, 'Feldtrenner wird benoetigt');
END IF;
IF (UPPER(p_rec_sep) LIKE '%DOS%') THEN
v_rec_sep_len := LENGTH(doszeilen);
ELSE
v_rec_sep_len := LENGTH(unixzeilen);
END IF;
SELECT blob_content
INTO v_binary_file
FROM my_wwv_flow_files
WHERE my_wwv_flow_files.name = p_file_name
--AND mime_type = 'text/plain'
AND doc_size > 0;
DBMS_LOB.createtemporary(v_text_file, TRUE);
DBMS_LOB.converttoclob(v_text_file,
v_binary_file,
DBMS_LOB.lobmaxsize,
v_dest_offset,
v_src_offset,
DBMS_LOB.default_csid,
v_lang_context,
v_warning);
IF v_warning = DBMS_LOB.warn_inconvertible_char THEN -- error converting
raise_application_error(-20000, 'Kann Datei nicht konvertieren');
END IF;
v_file_length := DBMS_LOB.getlength(v_text_file);
--INSERT INTO DEBUG_TAB (a) VALUES (v_file_length);
LOOP
EXIT WHEN v_start_pos > v_file_length;
-- erste Vorkommen von p_rec_sep in v_text_file, starte suche bei v_start_pos
IF (UPPER(p_rec_sep) LIKE '%DOS%') THEN
v_end_pos := DBMS_LOB.INSTR(v_text_file, doszeilen, v_start_pos);
ELSE
v_end_pos := DBMS_LOB.INSTR(v_text_file, unixzeilen, v_start_pos);
END IF;
--INSERT INTO DEBUG_TAB (a,b) VALUES ('p_rec_sep',UPPER(p_rec_sep));
--INSERT INTO DEBUG_TAB (a,b) VALUES ('v_end_pos',v_end_pos);
IF v_end_pos = 0 --- nichts gefunden, leeres v_text_file
THEN
v_end_pos := v_file_length + 1;
END IF;
IF v_end_pos - v_start_pos > 4000 --- mehr als 4000 Zeichen in Zeile
THEN
raise_application_error(-20000, 'Zeile hat mehr als 4000 Zeichen, Dateiformat beachten');
END IF;
--- DBMS_LOB.SUBSTR(source, amount, position)
p_lines(v_line_num) := DBMS_LOB.SUBSTR(v_text_file,
v_end_pos - v_start_pos,
v_start_pos);
--- Change the ',' field delimiter to ':' , to use the built-in string_to_table function
--- optionale Hochkomma " entfernen
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), '"', '');
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ':', ' ');
--- passende Feldtrenner auswaehlen , ; |
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), '|', ':');
-- p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ',', ':');
-- p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ';', ':');
v_field_array := wwv_flow_utilities.string_to_table(p_lines(v_line_num));
IF v_field_array.COUNT <= 1 THEN
raise_application_error(-20000, 'Benoetige mindestens 2 Spalten');
ELSE
BEGIN
IF geloescht = FALSE THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE UP_MITGLIEDER';
geloescht := TRUE;
END IF;
IF ( (v_line_num = 1 ) AND (UPPER(p_header) = 'MITKOPF') ) THEN
NULL;
------ mit Konto-Daten ------------------ 24 Felder
ELSIF ( UPPER(p_blzkto) = 'MITBLZ' )
THEN
EXECUTE IMMEDIATE 'INSERT INTO UP_MITGLIEDER(
MG_NR
,MG_ZS
,MG_KONTONR
,MG_BLZ
VALUES ( TRIM(:1), TRIM(:2), TRIM(:3), TRIM(:4), TRIM(:5), TRIM(:6), TRIM(:7), TRIM(:8), TRIM(:9), TRIM(:10),
TRIM(:11), TRIM(:12), TRIM(:13), TRIM(:14), TRIM(:15), TRIM(:16), TRIM(:17), TRIM(:18), TRIM(:19), TRIM(:20),
TRIM(:21), TRIM(:22),
TRIM(:23), TRIM(:24) )'
-- VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21, :22 :23 :24 )'
USING
v_field_array(1), v_field_array(2), v_field_array(3), v_field_array(4), v_field_array(5),
v_field_array(6), v_field_array(7), v_field_array(8), v_field_array(9), v_field_array(10),
v_field_array(11), v_field_array(12), v_field_array(13), v_field_array(14), v_field_array(15),
v_field_array(16), v_field_array(17), v_field_array(18), v_field_array(19), v_field_array(20),
v_field_array(21), v_field_array(22), v_field_array(23), v_field_array(24);
------------ ohne Konto-Daten , bis MG_ZS ---- 22 Felder
ELSE
-- EXECUTE IMMEDIATE 'INSERT INTO EINS(LFD,BEM) VALUES(:1,:2)'
EXECUTE IMMEDIATE 'INSERT INTO UP_MITGLIEDER(
MG_NR
,MG_ZS
VALUES ( TRIM(:1), TRIM(:2), TRIM(:3), TRIM(:4), TRIM(:5), TRIM(:6), TRIM(:7), TRIM(:8), TRIM(:9), TRIM(:10),
TRIM(:11), TRIM(:12), TRIM(:13), TRIM(:14), TRIM(:15), TRIM(:16), TRIM(:17), TRIM(:18), TRIM(:19), TRIM(:20),
TRIM(:21), TRIM(:22) )'
-- VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21, :22 )'
USING
v_field_array(1), v_field_array(2), v_field_array(3), v_field_array(4), v_field_array(5),
v_field_array(6), v_field_array(7), v_field_array(8), v_field_array(9), v_field_array(10),
v_field_array(11), v_field_array(12), v_field_array(13), v_field_array(14), v_field_array(15),
v_field_array(16), v_field_array(17), v_field_array(18), v_field_array(19), v_field_array(20),
v_field_array(21), v_field_array(22);
END IF; --- v_line_num = 1 AND p_header
END; --- von Begin im Else-Zweig
END IF;
--INSERT INTO DEBUG_TAB(a)
--VALUES ('P_lines: ' || p_lines(v_line_num));
-- hilfscounter := v_field_array.COUNT;
--INSERT INTO DEBUG_TAB(a)
--VALUES ('v_field_array.count: ' || TO_CHAR(hilfscounter));
-- neue Zeile
v_line_num := v_line_num + 1;
v_start_pos := v_end_pos + v_rec_sep_len;
END LOOP;
DBMS_LOB.freetemporary(v_text_file);
EXCEPTION
WHEN NO_DATA_FOUND THEN
raise_application_error(-20000,
'Datei existiert nicht in my_wwv_flow_files, ist keine Textdatei (text/plain) oder hat die Groesse 0');
WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 400);
raise_application_error(-20011,
'Datei entspricht nicht erwartetem Format ! '
||CHR(13) || CHR(10)||' '||err_msg||CHR (10)|| v_line_num ||CHR (10)|| p_lines(v_line_num));
END get_mitglieder_csv;If the last column e.g. MG_ZS contains NULL-values the import into UP-MITGLIEDER does not work , stops with error
Fehler ORA-20011: Datei entspricht nicht erwartetem Format !Why isn't it possible to import Null values from the last column ?Here is now a general example based on scott.emp
CREATE OR REPLACE PROCEDURE import_emp_csv (p_file_name IN VARCHAR2,
p_rec_sep IN VARCHAR2,
p_header IN VARCHAR2
) IS
TYPE line_tab_type IS TABLE OF VARCHAR2 (4000)
INDEX BY BINARY_INTEGER;
v_binary_file BLOB;
v_text_file CLOB;
-- Conversion Variables
v_dest_offset INTEGER := 1;
v_src_offset INTEGER := 1;
v_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
v_warning INTEGER;
-- Parsing Variables
v_rec_sep_len PLS_INTEGER;
v_start_pos PLS_INTEGER := 1;
v_end_pos PLS_INTEGER := 1;
v_line_num PLS_INTEGER := 1;
v_file_length PLS_INTEGER;
-- Parsing Line Variables
v_field_array wwv_flow_global.vc_arr2;
p_lines line_tab_type;
doszeilen CONSTANT VARCHAR2(2) := CHR(13) || CHR(10);
unixzeilen CONSTANT VARCHAR2(1) := CHR(10);
geloescht BOOLEAN := FALSE;
err_code NUMBER;
err_msg VARCHAR2(400);
BEGIN
IF p_file_name IS NULL THEN
raise_application_error(-20000, 'Dateiname wird benoetigt');
END IF;
IF p_rec_sep IS NULL THEN
raise_application_error(-20000, 'Feldtrenner wird benoetigt');
END IF;
IF (UPPER(p_rec_sep) LIKE '%DOS%') THEN
v_rec_sep_len := LENGTH(doszeilen);
ELSE
v_rec_sep_len := LENGTH(unixzeilen);
END IF;
SELECT blob_content
INTO v_binary_file
FROM my_wwv_flow_files
WHERE my_wwv_flow_files.name = p_file_name
--AND mime_type = 'text/plain'
AND doc_size > 0;
DBMS_LOB.createtemporary(v_text_file, TRUE);
DBMS_LOB.converttoclob(v_text_file,
v_binary_file,
DBMS_LOB.lobmaxsize,
v_dest_offset,
v_src_offset,
DBMS_LOB.default_csid,
v_lang_context,
v_warning);
--INSERT INTO DEBUG_TAB (a) VALUES (v_text_file);
IF v_warning = DBMS_LOB.warn_inconvertible_char THEN -- error converting
raise_application_error(-20000, 'Kann Datei nicht konvertieren');
END IF;
v_file_length := DBMS_LOB.getlength(v_text_file);
--INSERT INTO DEBUG_TAB (a) VALUES (v_file_length);
LOOP
EXIT WHEN v_start_pos > v_file_length;
-- erste Vorkommen von p_rec_sep in v_text_file, starte suche bei v_start_pos
IF (UPPER(p_rec_sep) LIKE '%DOS%') THEN
v_end_pos := DBMS_LOB.INSTR(v_text_file, doszeilen, v_start_pos);
ELSE
v_end_pos := DBMS_LOB.INSTR(v_text_file, unixzeilen, v_start_pos);
END IF;
--INSERT INTO DEBUG_TAB (a,b) VALUES ('p_rec_sep',UPPER(p_rec_sep));
--INSERT INTO DEBUG_TAB (a,b) VALUES ('v_end_pos',v_end_pos);
IF v_end_pos = 0 --- nichts gefunden, leeres v_text_file
THEN
v_end_pos := v_file_length + 1;
END IF;
IF v_end_pos - v_start_pos > 4000 --- mehr als 4000 Zeichen in Zeile
THEN
raise_application_error(-20000, 'Zeile hat mehr als 4000 Zeichen, Dateiformat beachten');
END IF;
--- DBMS_LOB.SUBSTR(source, amount, position)
p_lines(v_line_num) := DBMS_LOB.SUBSTR(v_text_file,
v_end_pos - v_start_pos,
v_start_pos);
--- Change the ',' field delimiter to ':' , to use the built-in string_to_table function
--- optionale Hochkomma " entfernen
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), '"', '');
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ':', ' ');
--- passende Feldtrenner auswaehlen , ; |
p_lines(v_line_num) := REPLACE(p_lines(v_line_num), '|', ':');
-- p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ',', ':');
-- p_lines(v_line_num) := REPLACE(p_lines(v_line_num), ';', ':');
v_field_array := wwv_flow_utilities.string_to_table(p_lines(v_line_num));
IF v_field_array.COUNT <= 1 THEN
raise_application_error(-20000, 'Benoetige mindestens 2 Spalten');
ELSE
BEGIN
IF geloescht = FALSE THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE UP_EMP2';
geloescht := TRUE;
END IF;
IF ( (v_line_num = 1 ) AND (UPPER(p_header) = 'MITKOPF') ) THEN
NULL;
ELSE
EXECUTE IMMEDIATE 'INSERT INTO UP_EMP2(
EMPNO
,ENAME
,JOB
,MGR
,HIREDATE
,SAL
,DEPTNO
,COMM
VALUES ( TRIM(:1), TRIM(:2), TRIM(:3), TRIM(:4), TRIM(:5), TRIM(:6), TRIM(:7), NVL( TRIM(:8), NULL )
USING
v_field_array(1), v_field_array(2), v_field_array(3), v_field_array(4), v_field_array(5),
v_field_array(6), v_field_array(7), v_field_array(8);
END IF; --- v_line_num = 1 AND p_header
END; --- von Begin im Else-Zweig
END IF;
-- neue Zeile
v_line_num := v_line_num + 1;
v_start_pos := v_end_pos + v_rec_sep_len;
END LOOP;
DBMS_LOB.freetemporary(v_text_file);
EXCEPTION
WHEN NO_DATA_FOUND THEN
raise_application_error(-20000,
'Datei existiert nicht in my_wwv_flow_files, ist keine Textdatei (text/plain) oder hat die Groesse 0');
WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 400);
raise_application_error(-20011,
'Datei entspricht nicht erwartetem Format ! '
||CHR(13) || CHR(10)||' '||err_msg||CHR (10)|| v_line_num ||CHR (10)|| p_lines(v_line_num));
END import_emp_csv;Here is my csv test file
7370|"schmid"|"CLERK"|7902|"17.12.1980"||20|20
7500|"ALLENT"|"SALESMAN"|7698|"20.02.1981"|1600|30|
7522|"WART"|"SALESMAN"|7698|"22.02.1981"|1250|30|500The second row is missing the last element (in excel table it is a NULL Value), this causes a NO-DATA-FOUND error.
Any ideas how to solve this problem ? -
Pricing procedure of free goods
Could anyone please tell me the effect of pricing procedure in free godds?And what is the difference between pricing procedure in free goods(IMG->Sales and Distribution->Basic Funcions->Free Goods) and pricing procedure in pricing(IMG->Sales and Distribution->Basic Funcions->Pricing)
Hi Wei Zhang,
When there are more than 2 materials say material A which is of some price, and material B which is Free of cost, then the item category will be different for those. TAN for Mat A and TANN for materail B.
Pricing is depends upon the customer pricing procedure and document pricing procedure along with the Sales Area.
When there are free Goods, Again yu have two conditions
1. Give 100 % discount on free goods.
2. Or charge 0 value for that.
This pricing procedure you can do in free goods priocing procedure.
Hope this will help.
Thanks,
Raja -
Can not select from data dictionary view from a procedure
Hi,
I wonder, which privilege is missing here:
my schema has this roles and privs:
GRANT CONNECT, RESOURCE TO cb ;
GRANT CREATE SESSION TO cb ;
GRANT SELECT_CATALOG_ROLE TO cb ;
GRANT CREATE SYNONYM TO CB;
GRANT CREATE VIEW TO CB;
I create a procedure:
create or replace procedure dd_test as
begin
dbms_output.enable(2000000);
for r in (select table_name from sys.dba_tab_partitions where owner = 'CB') loop
dbms_output.put_line(r.table_name);
end loop;
end;
sho err
4/38 PL/SQL: ORA-00942: table or view does not exist
When I run the core statement form sql prompt, it works !
so what privilege is missing here ???
thanks for any hint, Lao DeHi,
thanks for that reply, after doing that I can not select this DD-view from sql-prompt anymore (which I don't wonder ;-). Can you tell me, what idea you had behind that test ?
I found another instance, where the procedure works and I will compare those privileges, but it's hard to sort out that complex structure of nested roles and sys_privs.
How ever, I will update here, when I found the missing privilege.
regards LaoDe -
Unable to capture the parameter values from a PL/SQL procedure
hi.
i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
Please help me regarding.
i'm using following block for calling the procedure.
declare
err_cd varchar2(1000);
err_txt VARCHAR2(5000);
no_of_recs number;
out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
cntr_var number:=0;
begin
rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
dbms_output.put_line('The error is ' ||err_cd);
dbms_output.put_line('The error is ' ||err_txt);
dbms_output.put_line('The cntr is ' ||cntr_var);
for incr in 1 .. OUT_SIGN_TAB.count
loop
cntr_var := cntr_var + 1 ;
Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
end loop;
end;
Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
Following is some related information.
the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
TYPE "SEARCH_SIGN_TYPE" AS OBJECT
(ref_no VARCHAR2(22),
ciref_no VARCHAR2(352),
ac_no VARCHAR2(22),
txn_type VARCHAR2(301),
objid VARCHAR2(1024))............We don't have your rt843pq procedure, but when commenting that line out, everything works:
SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
2 (ref_no VARCHAR2(22),
3 ciref_no VARCHAR2(352),
4 ac_no VARCHAR2(22),
5 txn_type VARCHAR2(301),
6 objid VARCHAR2(1024))
7 /
Type is aangemaakt.
SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
2 /
Type is aangemaakt.
SQL> declare
2 err_cd varchar2(1000);
3 err_txt VARCHAR2(5000);
4 no_of_recs number;
5 out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
6 cntr_var number:=0;
7 begin
8 -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
9 dbms_output.put_line('The error is ' ||err_cd);
10 dbms_output.put_line('The error is ' ||err_txt);
11 dbms_output.put_line('The cntr is ' ||cntr_var);
12 for incr in 1 .. OUT_SIGN_TAB.count
13 loop
14 cntr_var := cntr_var + 1 ;
15 Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
16 end loop;
17 end;
18 /
The error is
The error is
The cntr is 0
PL/SQL-procedure is geslaagd.Regards,
Rob. -
Get Attribute values from a page and procedure exception handling?
Hi All,
I have created new page with two input attributes not based on any VO. This page is created to capture two values and pass these to an AM method upon pressing OK button. The method in AM will call a procedure with two in parameter expecting the two values captured from the above said page.
I have two questions, first one how to capture the values entered by the page in the controller class and advises me how to handle exceptions when my procedure fails.
I can not use something like this since this page is not based on a VO
String fromName = (String)vo.getCurrentRow().getAttribute("FromName");
Do I have to create a dummy VO like select '' name1, '' name2 from dual?
Thanks for the help.Hi,
Actually you can capture the parameters on the page like this way
String test = (String)pageContext.getParameter("id of the text input bean");
Now in procedure you can take an out parameter which stores the error messages on exception
and return that out parameter in java.
and then you can throw exception on page using OAException class.
Thanks
Gaurav Sharma -
Get variable values from a stored procedure
I am using SQL 2008R2 and I want to replace a view inside a stored procedure with a new stored procedure to return multiple variable values. Currently I am using the code below to get values for 4 different variables. I would rather get the 4 variables
from a stored procedure (which returns all of these 4 values and more) but not sure how to do so. Below is the code for getting the 4 variable values in my current sp.
DECLARE @TotalCarb real;
DECLARE @TotalPro real;
DECLARE @TotalFat real;
DECLARE @TotalLiquid real;
SELECT @TotalCarb = ISNULL(TotCarb,0),
@TotalPro = ISNULL(TotPro,0),
@TotalFat = ISNULL(TotFat,0),
@TotalLiquid = ISNULL(TotLiq,0)
FROM dbo.vw_ActualFoodTotals
WHERE (MealID = @MealID);You can replace the view with inline table valued user-defined function:
http://www.sqlusa.com/bestpractices/training/scripts/userdefinedfunction/
See example: SQL create INLINE table-valued function like a parametrized view
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Pointbase : How can I create a stored procedure with Pointbase database?
Hello,
Excuse me for my english, I'm not anglophone. I try to create a stored procedure.
This is my file SampleExternalMethods.java :
import java.sql.*; //import com.pointbase.jdbc.jdbcInOutDoubleWrapper; public class SampleExternalMethods { // A connection object to allow database callback static Connection conn = null; static Statement l_stmt; static Statement m_stmt; static CallableStatement m_callStmt = null; static ResultSet l_rs = null; public static void main(String[] args) { try { String url = "jdbc:pointbase:server://localhost/pointbaseDB"; String username = "PBPUBLIC"; String password = "PBPUBLIC"; conn = DriverManager.getConnection(url, username, password); doCreateProcedure(); doInvokeProcedure(); } catch (SQLException e) { e.printStackTrace(); } finally { if (m_stmt != null) { try { m_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (m_callStmt != null) { try { m_callStmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void getCountry(String Iso_Code) { try { // Query the database for the country iso code l_stmt = conn.createStatement(); l_rs = l_stmt.executeQuery( "SELECT * FROM countries" + " WHERE country_iso_code ='" + Iso_Code + "'"); //Affichage du résultat de la requête l_rs.next(); System.out.print(l_rs.getString(1) + " - "); System.out.print(l_rs.getString(2) + " - "); System.out.println(l_rs.getString(3)); // Close the result set l_rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { if (l_rs != null) { try { l_rs.close(); } catch (Exception e) { e.printStackTrace(); } } if (l_stmt != null) { try { l_stmt.close(); } catch (Exception e) { e.printStackTrace(); } } } } public static void doCreateProcedure() throws SQLException { // SQL statement to create a stored procedure String SQL_CREATE_PROC = "CREATE PROCEDURE getCountry(IN P1 VARCHAR(30))" + " LANGUAGE JAVA" + " SPECIFIC getCountry" + " NO SQL" + " EXTERNAL NAME \"SampleExternalMethods::getCountry\"" + " PARAMETER STYLE SQL"; // Create a SQL statement m_stmt = conn.createStatement(); // Execute the SQL m_stmt.executeUpdate(SQL_CREATE_PROC); // Close the statement //m_stmt.close(); } public static void doInvokeProcedure() throws SQLException { // Create SQL to invoke stored procedures String SQL_USE_PROC = "{ call getCountry(?) }"; // Create a callable statement with three binding parameters m_callStmt = conn.prepareCall(SQL_USE_PROC); m_callStmt.setString(1, "CA"); m_callStmt.executeQuery(); // Close the callable statement //m_callStmt.close(); } }
Afterwards, I have read this note in a Pointbase document:
To invoke the dateConvert external Java method from a stored function, you must use the
CREATE FUNCTION statement. The dateConvert external Java method is called from the
class, SampleExternalMethods.
In order for the database to access this external Java method, the class SampleExternalMethods
must be included in the database CLASSPATH. For PointBase Embedded - Server Option, it
must be in the Server CLASSPATH, but not in the Client CLASSPATH.
If PointBase Server is run with the Java Security Manager, in the java policy file grant
’com.pointbase.sp.spPermission’ to the class that implements the external Java method.
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
I'm not sure, but I suppose that I must include the class SampleExternalMethods in a .jar file.
The database CLASSPATH could be : C:\Sun\AppServer\pointbase\lib\
These my files in this database CLASSPATH:
pbclient.jar
pbembedded.jar
pbtools.jar
pbupgrade.jar
I have tryed to include the class SampleExternalMethods in pbclient.jar and pbembedded.jar with this command:
jar -uf pbembedded.jar SampleExternalMethods
Afterwards I do that,
1) Start Pointbase
2) Configuration of classpath
set classpath=C:\Sun\AppServer\pointbase\lib\pbclient.jar
set classpath=%classpath%;D:\J2EE\Ch07Code\Ch07_06
I precise that my file SampleExternalMethods is into D:\J2EE\Ch07Code\Ch07_06\Ch07.
Then, I run the program:
D:\J2EE\Ch07Code\Ch07_06>java -Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver Ch07.SampleExternalMethods
But I have an error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Ch07.SampleExternalMethods (wrong name: SampleExternalMethods)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.DefineClass(ClassLoader.java:539)
The problem, I suppose, comes from that the class SampleExternalMethods
must be included in the database CLASSPATH, but there is a pbserver.jar with pointbase normally, but I didn't find it. That's why I use pbembedded.jar or pbclient.jar in order to include the class SampleExternalMethods. May be I must start from C:\Sun\AppServer\pointbase\lib\ instead of D:\J2EE\Ch07Code\Ch07_06\Ch07?
Please, can somebody helps me?
Thank you in advance.
cagou!jschell wrote:
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
>
And I doubt you can recurse like that for embedded java. You must have a class that does the functionality and another class that creates the proc.
Thank you for your response, I have done two classes:
SampleExternalMethods.java:
package Ch07;
import java.sql.*;*
*public class SampleExternalMethods*
*public static void getCountry(String Iso_Code)*
*// A connection object to allow database callback*
*Connection l_conn = null;*
*Statement l_stmt = null;*
*ResultSet l_rs = null;*
*try*
*String url = "jdbc:pointbase:server://localhost/pointbaseDB";*
*String username = "PBPUBLIC";*
*String password = "PBPUBLIC";*
*l_conn = DriverManager.getConnection(url, username, password);*
*// Query the database for the country iso code*
*l_stmt = l_conn.createStatement();*
*l_rs = l_stmt.executeQuery( "SELECT* FROM PBPUBLIC.COUNTRIES"
+" WHERE country_iso_code ='"+ Iso_Code +"'");+
+//Affichage du résultat de la requête+
+l_rs.next();+
+System.out.print(l_rs.getString(1)+ " - ");
System.out.print(l_rs.getString(2) +" - ");+
+System.out.println(l_rs.getString(3));+
+// Close the result set+
+l_rs.close();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (l_rs != null) {+
+try {+
+l_rs.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_stmt != null) {+
+try {+
+l_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (l_conn != null) {+
+try {+
+l_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+}+
CreateMethods.java:
+package Ch07;+
+import java.sql.*;+
+public class CreateMethods+
+{+
+// A connection object to allow database callback+
+static Connection m_conn = null;+
+static Statement m_stmt;+
+static CallableStatement m_callStmt = null;+
+public static void main(String[] args)+
+{+
+try+
+{+
+String url = "jdbc:pointbase:server://localhost/pointbaseDB";+
+String username = "PBPUBLIC";+
+String password = "PBPUBLIC";+
+m_conn = DriverManager.getConnection(url, username, password);+
+doCreateProcedure();+
+doInvokeProcedure();+
+} catch (SQLException e) {+
+e.printStackTrace();+
+} finally {+
+if (m_stmt != null) {+
+try {+
+m_stmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_callStmt != null) {+
+try {+
+m_callStmt.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+if (m_conn != null) {+
+try {+
+m_conn.close();+
+} catch (Exception e) {+
+e.printStackTrace();+
+}+
+}+
+}+
+}+
+public static void doCreateProcedure() throws SQLException {+
+// SQL statement to create a stored procedure+
+String SQL_CREATE_PROC = "CREATE PROCEDURE PBPUBLIC.getCountry(IN P1 VARCHAR(30))"+
" LANGUAGE JAVA"
+" SPECIFIC getCountry"+
" NO SQL"
+" EXTERNAL NAME \"SampleExternalMethods::getCountry\""+
" PARAMETER STYLE SQL";
// Create a SQL statement
m_stmt = m_conn.createStatement();
// Execute the SQL
m_stmt.executeUpdate(SQL_CREATE_PROC);
// Close the statement
//m_stmt.close();
public static void doInvokeProcedure() throws SQLException {
// Create SQL to invoke stored procedures
String SQL_USE_PROC = "{ call getCountry(?) }";
// Create a callable statement with three binding parameters
m_callStmt = m_conn.prepareCall(SQL_USE_PROC);
m_callStmt.setString(2, "CA");
m_callStmt.executeQuery();
// Close the callable statement
//m_callStmt.close();
}But I have the same error message that previously.
I have read this note and I suppose that the problem is linked:
If PointBase Server is run with the Java Security Manager, in the java policy file grant
*com.pointbase.sp.spPermission to the class that implements the external Java method.*
An "spPermission" consists of a class name with no action. The class name is a name of a class
that could be used in creating a Stored Procedure in PointBase. The naming convention follows
the hierarchical property naming convention and that is supported by
*"java.security.BasicPermission". An asterisk may appear by itself, or if immediately preceded*
by ".", may appear at the end of the name, to signify a wildcard match. The name cannot
contain any white spaces.
Can you explain me what I must to do in order to solve this problem of spPermission.
Thanks. -
How to view the returned data from a stored procedure in TOAD?
Hi,
I created ref cursor in the stored procedure to return data. The stored procedure works fine, just want to view the result in TOAD. The BEGIN... EXEC... END can execute the stored procedure, but how to make the result display?
Thanks!Right click the editor and choose
"Prompt For Substitution Variables".
Run for example the following code:
DECLARE
PROCEDURE p (cur OUT sys_refcursor)
AS
BEGIN
OPEN cur FOR
SELECT *
FROM DUAL;
END p;
BEGIN
p (:cur);
END;
The result will display in Toad's Data Grid!
Regards Michael -
Error while running a stored procedure in SBO
Hi all,
i have a stored procedure that i run in my sbo. When i run the stored procedure i get the following error :
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Warning: Null value is eliminated by an aggregate or other SET operation.
'Servicecontracten' (OCTR) 05/10/2011 18:03:36 -1
i launch my sp like this :
exec [spu_DS_HistProjektUserVeldenViewBetalingen] (i pass no parameters while testing. i put them fix in my sp)
my stored procedure looks like this :
USE [def1]
GO
/****** Object: StoredProcedure [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen] Script Date: 10/05/2011 18:03:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery2.sql|8|0|C:\Users\kvanhauwaert\AppData\Local\Temp\~vs2A98.sql
ALTER PROCEDURE [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen]
/* @project_number varchar(20),
@billperiod_type varchar(10) */
AS
BEGIN
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase, isnull(factuurbedrag,0) as factuurbedrag,
isnull(billperiod_type,'') as billperiod_type
INTO #tempDS_HistProjektUserVeldenViewBetalingen
FROM DS_HistProjektUserVeldenViewBetalingen t1
WHERE project_number = '08053A'
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase , isnull(factuurbedrag,0) as factuurbedrag,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where lijnnr <= t1.lijnnr) as lijntotaal,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where lijnnr <= t1.lijnNr and billperiod_type = '110-01' ) as lijntotaalKetting
FROM #tempDS_HistProjektUserVeldenViewBetalingen t1
WHERE fase,'') is not null
ORDER BY t1.fase
DROP TABLE #tempDS_HistProjektUserVeldenViewBetalingen
END
GO
Somebody has a clue what i'm doing wrong ?
thnxThanks Gordon for your reply.
i've changed my sp to :
USE [def1]
GO
/****** Object: StoredProcedure [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen] Script Date: 10/05/2011 18:56:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery2.sql|8|0|C:\Users\kvanhauwaert\AppData\Local\Temp\~vs2A98.sql
CREATE PROCEDURE [dbo].[spu_DS_HistProjektUserVeldenViewBetalingen]
/* @project_number varchar(20),
@billperiod_type varchar(10) */
AS
BEGIN
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase, isnull(factuurbedrag,0) as factuurbedrag,
isnull(billperiod_type,'') as billperiod_type
INTO #tempDS_HistProjektUserVeldenViewBetalingen
FROM DS_HistProjektUserVeldenViewBetalingen t1
WHERE isnull(project_number,'') = '08053A'
SELECT isnull(lijnnr,0) as lijnnr, isnull(fase,'') as fase , isnull(factuurbedrag,0) as factuurbedrag,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where isnull(lijnnr,0) <= isnull(t1.lijnnr,0)) as lijntotaal,
(select sum(isnull(factuurbedrag,0)) from #tempDS_HistProjektUserVeldenViewBetalingen where isnull(lijnnr,0) <= isnull(t1.lijnNr,0) and isnull(billperiod_type,'') = '110-01' ) as lijntotaalKetting
FROM #tempDS_HistProjektUserVeldenViewBetalingen t1
WHERE isnull(fase,'') <> ''
ORDER BY t1.fase
DROP TABLE #tempDS_HistProjektUserVeldenViewBetalingen
END
GO
but that didn't solved my problem. Any other idea's ?
kind regards.
Kurt -
Error while opening two cursors in same procedure...
Hi :
I have written following Procedure:
Declare
procedure pro_canefortnight_master Is
kr_caneperiodid integer;
last_caneperiod_id number(10,0);
kr_forthnightid integer;
last_forthnight_id number(10,0);
ref_caneperiodid integer;
ref_seasonyrid integer;
ctr integer:= 1;
CURSOR comp_cur IS select * from CMS_SEASON_YEAR_MASTER ;
comp_rec comp_cur%ROWTYPE;
BEGIN
OPEN comp_cur;
FETCH comp_cur INTO comp_rec;
WHILE comp_cur%FOUND
LOOP
kr_caneperiodid:= comp_rec.SEASON_YR_ID;
select max(crayom_db.cr_cane_calender.cr_cane_calender_ID) into last_caneperiod_id from crayom_db.cr_cane_calender;
if last_caneperiod_id <> 0 then
last_caneperiod_id:= last_caneperiod_id + 1;
else
last_caneperiod_id:= 1000000;
end if;
insert into crayom_db.CR_CANE_CALENDER(cr_cane_calender_ID,ad_client_id, ad_org_id, isactive, created, createdby, updated, updatedby,CR_CANE_CALENDER_NAME,DESCRIPTION) values(last_caneperiod_id,11,11,comp_rec.current_season,sysdate,100,sysdate,11,comp_rec.DESC_MA,comp_rec.DESC_EN);
COMMIT;
/*insert into crayom_db.CR_IdBackup(kr_cultivationtypeid,cr_cultivationtypeid) values(kr_cultivationtypeid, last_cultivationtype_id);*/
insert into crayom_db.temp(kr_bpartnerid,cr_bpartnerid) values(comp_rec.season_yr_id,last_caneperiod_id);
commit;
FETCH comp_cur INTO comp_rec;
End LOOP;
close comp_cur;
CURSOR comp_cur1 IS select * from CMS_FORTH_NIGHT_MASTER ;
comp_rec1 comp_cur1%ROWTYPE;
OPEN comp_cur1;
FETCH comp_cur1 INTO comp_rec1;
WHILE comp_cur1%FOUND
LOOP
kr_forthnightid:= comp_rec1.forthnight_id;
select max(crayom_db.cr_cane_calender_period.cr_cane_calender_period_ID) into last_forthnight_id from crayom_db.cr_cane_calender_period;
if last_forthnight_id <> 0 then
last_forthnight_id:= last_forthnight_id + 1;
else
last_forthnight_id:= 1000000;
end if;
if ref_seasonyrid <> comp_rec1.season_yr_id then
ref_seasonyrid:= comp_rec1.season_yr_id;
else
ctr:= ctr + 1;
end if;
SELECT cr_bpartnerid into ref_caneperiodid from crayom_db.temp where kr_bpartnerid = comp_rec1.season_yr_id;
dbms_output.put_line(ref_caneperiodid);
insert into crayom_db.CR_CANE_CALENDER_period(cr_cane_calender_period_ID,ad_client_id, ad_org_id, isactive, created, createdby, updated, updatedby,Enddate,name, startdate, cr_cane_calender_id) values(last_forthnight_id,11,11,comp_rec1.current_season,sysdate,100,sysdate,11,comp_rec1.end_date,'ForthNight' || ctr, comp_rec1.start_date,ref_caneperiodid);
commit;
FETCH comp_cur1 INTO comp_rec1;
End LOOP;
close comp_cur1;
END;
BEGIN
pro_canefortnight_master();
END;
But I am getting following Error:
Error report:
ORA-06550: line 429, column 8:
PLS-00103: Encountered the symbol "COMP_CUR1" when expecting one of the following:
:= . ( @ % ;
ORA-06550: line 433, column 1:
PLS-00103: Encountered the symbol "FETCH" when expecting one of the following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor
The symbol "begi
ORA-06550: line 472, column 1:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
ORA-06550: line 477, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Can any body help me?
Thank You.
Edited by: [email protected] on Oct 22, 2009 4:36 AM[email protected] wrote:
CURSOR comp_cur1 IS select * from CMS_FORTH_NIGHT_MASTER ;
comp_rec1 comp_cur1%ROWTYPE;This is probably the issue. All variable definitions, including cursors, must be in the DEFINE section of a procedure (between either DECLARE ... BEGIN or AS/IS ... BEGIN).
In addition I wanted to note the following:
1. When posting it is helpful to identify your Oracle version (e.g. 10.2.0.4).
2. Any code that is posted should be placed between \ tags to improve readability.
3. It looks like the code is doing "slow by slow" processing (a.k.a single record processing). It could probably be made much cleaner, maintainable and better performing by possibly using INSERT .. AS SELECT ... or something along those lines.
Maybe you are looking for
-
ICC Profiles How can I reduce the numbe of ICC profiles shown when I use the drop down Menus for setting up a printer or when soft proofing. I am trying to eliminate all profiles other than those that I use when printing. Edward Ward
-
Dear Consultant When creating a Stock, it gives an error, "Parameter for Plant is not maintained in inventory management" Could you tell me , how to resolve this Regards Aasif
-
Doubt: Filters in Golden Gate Area
Hi All, I'm a ODI Developer (begginer) and have doubt abt Golden Gate. I have the follow scenario: GG -> Staging Area -> Mastersaf Client told me to do not make filters on the first step (GG -> Staging), only at the step Staging Area -> Mastersaf. Is
-
i need to select ship to party ... which table can i use (other than likp)........
-
How do I clear the space on my camera roll? It shows 1.7 Gb when I checked the usage, however I have only a few photos on the camera roll. I tried to sync many times but it does not update correctly. It still shows 1.7Gb...:(