I'm busy with a little PL/SQL program and i got stuck when i got the error "numeric or value error"
I'm trying to convert a varchar2 that consists of only numbers to a number using TO_NUMBER().
I'm relatively new to PL/SQL, so i'm thinking it's something really dumb :)
This is my code:
set serveroutput on
DECLARE
vRearranged varchar(50);
iNumber number(38);
BEGIN
vRearranged := 3214282912345698765432161100;
iNumber := To_Number(vRearranged, 50);
dbms_output.put_line(iNumber);
END;
could anyone help me?
The second argument of To_number() is the format picture, which should be a string.
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions211.htm#SQLRF06140
DECLARE
vRearranged varchar2(50);
iNumber number(38);
BEGIN
vRearranged := 3214282912345698765432161100;
iNumber := To_Number(vRearranged);
dbms_output.put_line(iNumber);
END;
Related
I am running DBMS_OUTPUT.PUT_LINE to send a message from a procedure and I am trying to display the debug information of what a type variable contains BFILE
create or replace PROCEDURE P_FILEUPLOAD_XML IS
v_dir gzvcatg.gzvcatg_desc11%TYPE;
l_dir VARCHAR2(35);
l_fil VARCHAR2(30) := 'ES0000251446027471.xml';
l_loc BFILE;
BEGIN
l_loc := BFILENAME(v_dir,l_fil);
DBMS_OUTPUT.PUT_LINE(l_loc);
END;
At the moment of executing my procedure and waiting for a response from the log:
Anyone know why the error is due and how to correct it.
UPDATE:
Following the recommendation in the MT0 response making use of DBMS_LOB.READ, try the following:
create or replace PROCEDURE P_FILEUPLOAD_XML IS
v_dir gzvcatg.gzvcatg_desc11%TYPE;
l_dir VARCHAR2(35);
l_fil VARCHAR2(30) := 'ES0000251446027471.xml';
l_loc BFILE;
BEGIN
l_loc := BFILENAME(v_dir,l_fil);
DBMS_LOB.READ(l_loc IN BFILE);
END;
But executing it generates the following error:
Anyone know why the error is due
l_loc is a BFILE.
DBMS_OUTPUT.PUT_LINE( item IN VARCHAR2 ) takes a VARCHAR2 data type as its argument.
You cannot implicitly cast a BFILE to a VARCHAR2 so the procedure call raise an exception as it is the wrong type of argument to call the function with.
and how to correct it.
Read the file using DBMS_LOB.READ and use UTL_RAW.CAST_TO_VARCHAR2 to convert the RAW value you get from the LOB to a string so you can print it.
I tried to convert pls_integer to varchar2 using to_char but it is not working.
I also tried pls_integer to number and number to varchar2 using to_number and to_char methods, but that also not working. I am getting an error :
Pls00306 - wrong number or types of arguments in call 'to_number'.
Can you please help.
There's no need to do anything special just assign. Oracle allows implicit data type conversion between pls_integer and varchar2. See table 3-10 at the bottom of this page
declare
l_number pls_integer;
l_varchar varchar2(1);
begin
l_number := 8;
l_varchar := l_number;
end;
Hi getting below error
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error
occurred. For example, this error occurs if an attempt is made to
assign the value NULL to a variable declared NOT NULL, or if an
attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so
that values do not violate constraints.
when i run the following pl-sql code
DECLARE
type c_list is varray (6000) of varchar2(50);
name_list c_list := c_list();
counter integer :=0;
n number;
ADDHDR VARCHAR2(5000);
new_envelope clob:=NULL;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
FOR n in 1..1000 LOOP
counter := counter + 1;
name_list.extend;
name_list(counter) := 'ABCNDFHDDJJ';
dbms_output.put_line('Customer('||counter ||'):'||name_list(counter));
END LOOP;
for i in name_list.first .. name_list.last loop
ADDHDR := CONCAT(ADDHDR,'<ADDITIONAL_START>');
ADDHDR := CONCAT(ADDHDR, CONCAT('<START>', CONCAT('ADDR-KYC-ABCD-PRD-LDB-SMS-OR-START', '</START>')));
ADDHDR := CONCAT(ADDHDR, CONCAT('<ENDED>', CONCAT(name_list(i), '</ENDED>')));
ADDHDR := CONCAT(ADDHDR, '</ADDITIONAL_START>');
dbms_output.put_line('PROCESSING');
new_envelope := new_envelope || ADDHDR;
ADDHDR:=''
end loop;
dbms_output.put_line(new_envelope);
END;
/
please help me to concat string(value greater than 4000 characters) to a clob data
Thanks in advance
Problem is this line dbms_output.put_line(new_envelope);
You cannot output such large strings. I assume this is just for debugging, i.e. actually not needed.
If you really need dbms_output.put_line then do it line by line.
I have an example which input number in form of oracle sql plus, and here is my code :
DECLARE
WK_INPUT NUMBER := &NUMBER;
BEGIN
IF WK_INPUT IS NOT NUMBER THEN
DBMS_OUTPUT.PUT_LINE('IS NOT NUMBER')
ELSE
DBMS_OUTPUT.PUT_LINE(WK_INPUT ||' IS NUMBER')
END IF;
END;
When I execute it has error:
Encounter the symbol 'Number' when expecting the of the flow.
how can I check the input is number or not ?
Thank you.
There is no "NUMBER" function in Oracle. You don't really need it here, however, because when you declare the variable WK_INPUT to be of type NUMBER, you can only assign a number to it or else you'll get an exception. You could write this:
DECLARE
wk_input NUMBER;
BEGIN
wk_input := '&NUMBER';
DBMS_OUTPUT.PUT_LINE(wk_input||' is a number');
EXCEPTION
WHEN VALUE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('&NUMBER is not a number');
END;
May I know how to pass a record type value to a function argument?
Below is my attempt. I'm getting "wrong number or types of arguments in call..." error
I've searched but couldn't seem to find definite answer that will help me.
Hope someone can answer.
DECLARE
TYPE attribute_type_record IS RECORD
(
name VARCHAR2(100)
,value VARCHAR2(400)
,ind integer
);
type attribute_type is table of attribute_type_record index by binary_integer;
sid_att attribute_type;
ret varchar2(3000);
BEGIN
sid_att(1).name := 'SID_ATTRIBUTES.REFERENCE1';
sid_att(1).value := 'SID_ATTRIBUTES.REFERENCE1';
sid_att(1).ind := '1';
--v_row := sid_attributes_table('SID_ATTRIBUTES.REFERENCE1');
ret := SC$DATA_ENTRY.ins_sid_attributes(sid_att(1).name,
sid_att(1).value,
sid_att(1).ind,
'594191176',
'TEST');
END;
FUNCTION ins_sid_attributes (
p_sid_attributes_table sc$data_entry_utilities.attribute_table,
p_sid_id sid_attributes.sid_id%TYPE,
p_user IN VARCHAR2
)
RETURN VARCHAR2
IS
error_message VARCHAR2 (2000);
v_row sc$data_entry_utilities.attribute_type;
empty_row sc$data_entry_utilities.attribute_type;
v_order INTEGER := 0;
v_name VARCHAR2 (2000);
cat_table pkg_utilities.number_table;
-- I did not post the rest of the code of this function since i believe it is irrelevant to the error and to keep it short.
Thanks in advance!
noth
Assuming that the INS_SID_ATTRIBUTES procedure shown above is the one you're actually trying to call, the message seems reasonable to me. INS_SID_ATTRIBUTES, as shown above, wants three parameters:
A SC$DATA_ENTRY_UTILITIES.ATTRIBUTE_TABLE
A SID_ATTRIBUTES.SID_ID%TYPE
A VARCHAR2
But in the call you're passing it:
A VARCHAR2
A VARCHAR2
An INTEGER
A VARCHAR2
A VARCHAR2
So you're passing five arguments to a procedure that only accepts three, and the values you're passing are of the wrong types.
Share and enjoy.