Sending large CLOB message using UTL_MAIL.SEND - oracle

I'm using below code snippet in Oracle 12c procedure.
UTL_MAIL.SEND(SENDER => 'abc#x.com',
RECIPIENTS => 'xyz#x.com',
MIME_TYPE => 'text/html',
SUBJECT => SUBJECT,
MESSAGE => EMAIL_STRING);
EMAIL_STRING is of type CLOB It was working fine before. Now the email string length has been increased (became 62598 which is dynamic) and started giving below error.
Error report -
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "PROCEDURE_NAME", line 67
ORA-06512: at line 1
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.
How to send large CLOB as message body using UTL_MAIL.SEND ?

As #Wernfried Domscheit commented, I followed how to export data from log table to email body in oracle and used below snippet in my procedure to call the newly created package.
MAILING.SendMail(
Subject => SUBJECT,
Message => EMAIL_STRING,
ToMail => VARCHAR_TABLE_TYPE('toEmailid1','toEmailid2'),
FromMail => 'fromEmailId',
FromName => 'fromName');

Related

How to fix ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion

In my pl/sql code i have one parameter 'Error' which is used to display the missing values in table.
Error:= '<b><font color="black">following values are missing:</font></b>'
|| val1||val2||val3||val4;
Here ErrorText is CLOB datatype and each val1,val2,val3,val4 are set to varchar2(2000).
So, I guess when it is unable to display val_results more than the CLOB limit of 'Error', its throwing
ORA-22835.
How can I display 'Error' text only upto CLOB limit?
You have ORA-22835, so it means that it is for conversion from CLOB to CHAR. It looks that the exception is thrown in a different place than you think.

oracle column not allowed here

I got this error:
Error report -
ORA-00984: column not allowed here
ORA-06512: at line 14
00984. 00000 - "column not allowed here"
here is the code. I copy and paste the field name (all in cap). The field name should be correct
set serveroutput on
DECLARE
my_creation_dt date;
mysql varchar2(6000) := '';
BEGIN
select creation_dt into my_creation_dt from role_table where security_role = 'admin';
mysql := 'insert into role_grant_table (PERSON_ID, CREATION_DT, SECURITY_ROLE,
SSS_CREATE_DT, UPDATE_WHO, UPDATE_ON) values (1234, SYSDATE,
"ADMIN",
:my_creation_dt,
"myname",
SYSDATE)'; -- line 14, column not allowed here
execute immediate mysql using (my_creation_dt);
END;
Double-quotes are used to enclose identifiers (usually when they have mixed case or punctuation characters). So Oracle is interpreting "ADMIN" and "myname" as identifiers, which in this context the parser takes to be column names. The error is telling you that referencing a column here is not allowed.
Presumably, you intended those to be the string values to be inserted. Use
single-quotes to enclose string literals, i.e. 'ADMIN' and 'myname'.

error in coverting a clob data to varchar2

I tried to convert a clob datatype to varchar2 datatype using the dbms_lob command, but im getting error as shown below
ERROR:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
table structure:
desc test_default_settings
Name Null Type
------------- ---- -------------
DEFAULT_KEY VARCHAR2(100)
DEFAULT_VALUE CLOB
Table Content:
Default_key Default_Value
====================== ==================
EMAIL_TEMPLATE_NAME Invitation Email Template
EMAIL_TEMPLATE_FROM admin#xxx.com
EMAIL_TEMPLATE_SUBJECT Welcome to test company!!!
EMAIL_TEMPLATE_EXP_DAYS 2
EMAIL_TEMPLATE_MSG <html><p>Dear {First_Name}, {Last_Name}<span id="selectionBoundary_1496237162220_4685507087412435" class="rangySelectionBoundary"></span></p><p>...
..................</html>
Since the value of the EMAIL_TEMPLATE_MSG is too long to display, for reference I have marked as "...."
query used :
SELECT e.default_key,
TO_CHAR(DBMS_LOB.SUBSTR(e.default_value,5000, 1)) AS DEFAULT_VALUE
FROM test_default_settings e;
Note:
I can extact all the contents of data , except for EMAIL_TEMPLATE_MSG data
eg:
SELECT e.default_key,
TO_CHAR(DBMS_LOB.SUBSTR(e.default_value,5000, 1)) AS DEFAULT_VALUE
FROM test_default_settings e where default_key= 'EMAIL_TEMPLATE_NAME';
DEFAULT_KEY DEFAULT_VALUE
-------------- ----------------
EMAIL_TEMPLATE_NAME Invitation Email Template
but when i do the same to extract the html content, im getting error
SELECT e.default_key,
TO_CHAR(DBMS_LOB.SUBSTR(e.default_value,5000, 1)) AS DEFAULT_VALUE
FROM test_default_settings e where default_key= 'EMAIL_TEMPLATE_MSG';
output:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1
when i tried to increase the value of dbms_lob parameter to 80000, im getting the value as null.
Can you please help
DBMS_LOB.SUBSTR and SUBSTR work different. DBMS_LOB.SUBSTR(amount,offset) , SUBSTR(offset,amount).
Example
select DBMS_LOB.SUBSTR('1234567890',5,1),substr('1234567890',5,1),
DBMS_LOB.SUBSTR('1234567890',1,5)
from dw_mailing;
In your query dbms_lob.SUBSTR for long CLOB is extracting 5000 bytes and try to convert this byte to varchar2. But varchar2 max size in sql is 4000.

Cannot convert String to date in Oracle 11g

I'm trying to insert Date into table from user input but something doesn't work.
I have the following Query :
INSERT INTO DOCTORS.TREATMENTS
(START_OF_TREATMENT, END_OF_TREATMENT, DOCTORS_ID,PACIENTS_ID, DIAGNOSIS_ID)
VALUES (TO_DATE(&startdate, 'yyyy/mm/dd'), TO_DATE(&enddate, 'yyyy/mm/dd'), 3, 1, 1);
For start date I set :
2000/10/01
And for end date I set :
2000/11/01
It seem ok for me but I've got the following error :
Error report -
ORA-01858: a non-numeric character was found where a numeric was expected
ORA-06512: at "SYS.STANDARD", line 167
ORA-06512: at line 2
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
Any one can explain to me why this error occurred.
Best regards,
Petar.
The value of the first parameter passed to TO_DATE must be a string. After substitution with the value you've given your code will look like
TO_DATE(2000/10/01, 'yyyy/mm/dd')
which fails as shown.
The solution is to put the parameter usage in single-quotes to make the substituted value a string, as in
TO_DATE('&startdate', 'yyyy/mm/dd')
This way, when &startdate is substituted you'll get
TO_DATE('2000/10/01', 'yyyy/mm/dd')
which will work as expected.
Do the same for &enddate.
Best of luck.

oracle cannot insert values into a nested table field

I have the sample CUSTOMERS table.
I exported the values from table as INSERT script.
I took one row, modified the value from PK and re-executed the insert.
Insert into oe.customers (CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_ADDRESS,
PHONE_NUMBERS,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL,
CREDIT_CARDS)
values ( oe.customer_seq.nextval,
'Donald',
'Hunter',
OE.CUST_ADDRESS_TYP('5122 Sinclair Ln','21206','Baltimore','MD','US'),
OE.PHONE_LIST_TYP('+1 410 123 4795'),
'us',
'AMERICA',
2600,
'Donald.Hunter#CHACHALACA.EXAMPLE.COM',
145,
MDSYS.SDO_GEOMETRY(2001,8307,MDSYS.SDO_POINT_TYPE(-76.545732,39.322775,NULL),NULL,NULL),
to_date('20-JAN-60','DD-MON-RR'),
'married',
'M',
'G: 130,000 - 149,999',
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
and I have the following error message:
Error at Command Line : 32 Column : 29 Error report - SQL Error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
which refers to line:
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
The definition of types are:
create or replace type typ_cr_card as object
( card_type VARCHAR2(25)
, card_num NUMBER);
create or replace type typ_cr_card_nst as table of typ_cr_card;
Can someone tell me, please, what is wrong with this insert line as it is the one provided by SQL DEVELOPER?
NOTE: Also, I tried to use a procedure which inserts values in this table and the error refers to TYP_CR_CARD_NST datatype.

Resources