Not a valid month TO_DATE(inputMONYYYY, 'DD-MM-YYYY) - sql

`I've to accept input as Month name and year and validate condition with date formatted as ‘DD-MM-YYY’.
This is my stored procedure:
create or replace PROCEDURE PROC_REPORT (
v_customer_id IN NUMBER,
v_user_id IN VARCHAR2 DEFAULT NULL,
monthYear IN VARCHAR2 DEFAULT NULL,
solutionType IN VARCHAR2 DEFAULT NULL,
customerAccNo IN VARCHAR2 DEFAULT NULL,
productType IN VARCHAR2 DEFAULT NULL,
output OUT SYS_REFCURSOR
) IS
BEGIN
DECLARE
selectclause CLOB;
whereclause CLOB;
startDate CLOB;
BEGIN
whereclause := ' where 1=1';
startDate := TO_CHAR(TO_DATE(monthYear,'MON YYYY', 'NLS_DATE_LANGUAGE = English'), 'DD-MM-YYYY');
IF monthYear IS NOT NULL THEN
whereclause := whereclause
|| ‘ and sm.activation_date >= ’
|| startDate;
END IF;
selectclause := 'select * from customer_master cm
inner join sim_master sm on sm.customer_id = cm.customer_id
inner join solution_type st on st.id_key = cm.solution_type ' || whereclause;
dbms_output.put_line(selectclause);
OPEN output FOR selectclause;
END;
END PROC_REPORT;
This gives error “not a valid month”. When I hard code monthYear as below, it works well:
startDate := TO_CHAR(TO_DATE('JAN 2023','MON YYYY', 'NLS_DATE_LANGUAGE = English'), 'DD-MM-YYYY');
I've tried converting monthYear to char as:
startDate := TO_CHAR(TO_DATE(TO_CHAR(monthYear),'MON YYYY', 'NLS_DATE_LANGUAGE = English'), 'DD-MM-YYYY');
Please help me understand what am I missing.`

You do not need dynamic SQL and can use OR in the WHERE clause:
create or replace PROCEDURE PROC_REPORT (
v_customer_id IN NUMBER,
v_user_id IN VARCHAR2 DEFAULT NULL,
monthYear IN VARCHAR2 DEFAULT NULL,
solutionType IN VARCHAR2 DEFAULT NULL,
customerAccNo IN VARCHAR2 DEFAULT NULL,
productType IN VARCHAR2 DEFAULT NULL,
output OUT SYS_REFCURSOR
)
IS
BEGIN
OPEN output FOR
SELECT *
FROM customer_master cm
inner join sim_master sm on sm.customer_id = cm.customer_id
inner join solution_type st on st.id_key = cm.solution_type
WHERE ( monthYear IS NULL
OR sm.activation_date >= TO_DATE(monthYear,'MON YYYY', 'NLS_DATE_LANGUAGE = English')
);
END PROC_REPORT;
/
I assume that activation_date is a DATE column; in which case you want to perform the comparison as DATEs (and not as formatted strings, so you do not want to convert back to a string).

Related

Passing column name as parameter in Oracle PL_SQL function

I am trying to pass two input parameters, column name and table name . Then the function should output a string value as defined below :
create or replace function get_id5(in_col_name IN VARCHAR2,in_tbl_name IN VARCHAR2)
return VARCHAR2
is
/*in_col_nm varchar(32) := in_col_name;
/*in_tbl_nm varchar(64) := in_tbl_name; */
integer_part NUMBER ;
integer_part_str VARCHAR2(32) ;
string_part VARCHAR2(32) ;
full_id VARCHAR2(32) ;
out_id VARCHAR(32) ;
BEGIN
/*select MAX(in_col_nm) INTO full_id FROM in_tbl_nm ; */
execute immediate 'select MAX('||in_col_name||') FROM' || in_tbl_name ||'INTO' || full_id;
/*select regexp_replace(full_id , '[^0-9]', '') INTO integer_part_str , regexp_replace(full_id , '[^a-z and ^A-Z]', '') INTO string_part from dual ; */
integer_part_str := regexp_replace(full_id , '[^0-9]', '') ;
string_part := regexp_replace(full_id , '[^a-z and ^A-Z]', '') ;
integer_part := TO_NUMBER(integer_part_str);
integer_part := integer_part + 1 ;
integer_part_str := TO_CHAR(integer_part) ;
out_id := string_part + integer_part_str ;
return out_id;
END;
I have a table named BRANDS in Database and the max value for column BRAND_ID is 'Brand05'. The expected output is 'Brand06'.
However when i run:
select get_id5('BRAND_ID' , 'BRANDS') from dual;
or
DECLARE
a VARCHAR(32) ;
BEGIN
a := get_id5('BRAND_ID' , 'BRANDS');
END;
I am getting the below error:
ORA-00923: FROM keyword not found where expected
You need spaces between the FROM and the table_name and the INTO should be outside of the SQL text:
execute immediate 'select MAX('||in_col_name||') FROM ' || in_tbl_name INTO full_id;
You could also use DBMS_ASSERT:
execute immediate 'select MAX('||DBMS_ASSERT.SIMPLE_SQL_NAME(in_col_name)||') FROM ' || DBMS_ASSERT.SIMPLE_SQL_NAME(in_tbl_name) INTO full_id;
Then you need to use || as the string concatenation operator (rather than +).
Your function could be:
create or replace function get_id5(
in_col_name IN VARCHAR2,
in_tbl_name IN VARCHAR2
) RETURN VARCHAR2
IS
full_id VARCHAR2(32);
BEGIN
execute immediate 'select MAX('||DBMS_ASSERT.SIMPLE_SQL_NAME(in_col_name)||') '
|| 'FROM ' || DBMS_ASSERT.SIMPLE_SQL_NAME(in_tbl_name)
INTO full_id;
return regexp_replace(full_id , '\d+', '')
|| TO_CHAR(regexp_replace(full_id , '\D+', '') + 1);
END;
/
For the sample data:
CREATE TABLE brands (brand_id) AS
SELECT 'BRAND5' FROM DUAL;
Then:
select get_id5('BRAND_ID' , 'BRANDS') AS id from dual;
Outputs:
ID
BRAND6
db<>fiddle here
A better solution
To generate the number, use a SEQUENCE or, from Oracle 12, an IDENTITY column and, if you must have a string prefix then use a virtual column to generate it.
CREATE TABLE brands(
ID NUMBER
GENERATED ALWAYS AS IDENTITY
PRIMARY KEY,
brand_id VARCHAR2(10)
GENERATED ALWAYS
AS (CAST('BRAND' || TO_CHAR(id, 'FM000') AS VARCHAR2(10)))
);
BEGIN
INSERT INTO brands (id) VALUES (DEFAULT);
INSERT INTO brands (id) VALUES (DEFAULT);
INSERT INTO brands (id) VALUES (DEFAULT);
END;
/
SELECT * FROM brands;
Outputs:
ID
BRAND_ID
1
BRAND001
2
BRAND002
3
BRAND003
db<>fiddle here

Oracle PL/SQL ORA-00904: invalid identifier

I'm trying to declare a string and use it in a select statement but it's throwing ORA-00904: invalid identifier.
DECLARE
var_laufi VARCHAR2(20) := 'JEIV';
BEGIN
EXECUTE IMMEDIATE q'[
WITH aux AS (
SELECT DISTINCT
zbuag_id AS ca_dat
FROM
vw_penddv2
WHERE
category = 'Issue'
), aux2 AS (
SELECT DISTINCT
vkont AS ca_lock
FROM
cdc.uap_dfkklocks#rbip
WHERE
laufi = ]'
|| var_laufi
|| q'[
AND tdate >= to_char(sysdate, 'YYYYMMDD')
)
SELECT
*
FROM
aux a
FULL OUTER JOIN aux2 b ON b.ca_lock = a.ca_dat
WHERE
( a.ca_dat IS NULL
OR b.ca_lock IS NULL )
]'
;
END;
However, if I just try to display the variable itself, it works fine.
SET SERVEROUTPUT ON;
DECLARE
var_laufi VARCHAR2(20) := 'JEIV';
BEGIN
dbms_output.put_line(var_laufi);
END;
Result:
JEIV
PL/SQL procedure successfully completed.
I'm missing something here but I can't figure out what is it.
Dynamic SQL is evil if you misuse it. Rule of thumb: never execute it if you didn't check what you're executing! How? Display the statement. Here's how:
DECLARE
var_laufi VARCHAR2 (20) := 'JEIV';
var_str VARCHAR2 (2000);
BEGIN
var_str := q'[
WITH aux AS (
SELECT DISTINCT
zbuag_id AS ca_dat
FROM
vw_penddv2
WHERE
category = 'Issue'
), aux2 AS (
SELECT DISTINCT
vkont AS ca_lock
FROM
cdc.uap_dfkklocks#rbip
WHERE
laufi = ]' || var_laufi || q'[
AND tdate >= to_char(sysdate, 'YYYYMMDD')
)
SELECT
*
FROM
aux a
FULL OUTER JOIN aux2 b ON b.ca_lock = a.ca_dat
WHERE
( a.ca_dat IS NULL
OR b.ca_lock IS NULL )
]';
DBMS_OUTPUT.put_line (var_str);
END;
/
The result (formatted):
WITH
aux
AS
(SELECT DISTINCT zbuag_id AS ca_dat
FROM vw_penddv2
WHERE category = 'Issue'),
aux2
AS
(SELECT DISTINCT vkont AS ca_lock
FROM cdc.uap_dfkklocks#rbip
WHERE laufi = JEIV --> here
AND tdate >= TO_CHAR (SYSDATE, 'YYYYMMDD'))
SELECT *
FROM aux a FULL OUTER JOIN aux2 b ON b.ca_lock = a.ca_dat
WHERE ( a.ca_dat IS NULL
OR b.ca_lock IS NULL)
See the comment? where laufi = JEIV is invalid, should have been enclosed into single quotes.
Also, is tdate really a string? You're comparing it to sysdate represented as a string in specified format. If that's so, bad, BAD idea to store DATE datatype values as strings.
CREATE OR REPLACE PROCEDURE SP_PARENT_PRODUCT_JOINS (V_C_ID in number, c1 out sys_refcursor)
is
V_sql varchar2(2000);
Begin
-----------(STEP_1_JOINS)---------------------
V_sql:=
'
SELECT Country.C_id,Country.C_name,product.C_id
FROM Country
INNER JOIN Product
ON country.C_id = product.C_id
where V_C_ID='||V_C_ID;
EXECUTE IMMEDIATE(V_SQL);
-------------(STEP_2_TRUNCATE DATA)----------------
EXECUTE IMMEDIATE 'TRUNCATE TABLE Product_det';
dbms_output.put_line(V_SQL);
open c1 for V_sql;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(sqlerrm);
End;
error;
ORA-00904: "V_C_ID": invalid identifier

While I call the procedure, it gives me error: ORA-06553: PLS-306: wrong number or types of arguments in call to phone_info

Here is my procedure code:
CREATE OR REPLACE PROCEDURE phone_info (
numar IN order_detail_data.phone_number%TYPE,
process_s OUT VARCHAR2,
type_e OUT VARCHAR2,
status_s OUT VARCHAR2,
acceptor_r OUT VARCHAR2,
donor_r OUT VARCHAR2,
porting_g OUT VARCHAR2,
Idate_e OUT VARCHAR2,
Fdate_e OUT VARCHAR2,
ancom_d OUT VARCHAR2,
status_f OUT VARCHAR2,
error_r OUT VARCHAR2,
creation_n OUT VARCHAR2)
IS
BEGIN
SELECT od.process_type,
NVL (od.subscription_type_fd, od.process_type),
c."STATUS",
od.recipient_id,
od.donor_id,
oda.porting_id,
NVL (od.initial_date, TO_DATE ('31-12-9999', 'DD-MM-YYYY')),
NVL (od.final_date, TO_DATE ('31-12-9999', 'DD-MM-YYYY')),
oi.REG_PORTING_ID,
s.sub_status,
NVL2 (oj.error_description, oj.error_description, s.sub_status),
oda.sys_creation_date
INTO process_s,
type_e,
status_s,
acceptor_r,
donor_r,
porting_g,
Idate_e,
Fdate_e,
ancom_d,
status_f,
error_r,
creation_n
FROM order_data od
LEFT JOIN order_detail_data oda ON od.porting_id = oda.porting_id
LEFT JOIN order_sub_statuses s ON s.id = oda.sub_status_id
LEFT JOIN order_reject_details oj ON oda.porting_id = oj.porting_id
LEFT JOIN order_id oi ON oda.porting_id = oi.porting_id
LEFT JOIN order_bpm_processes bx ON oda.porting_id = bx.porting_id
LEFT JOIN order_detail_statuses c ON c.id = oda.status_id
WHERE oda.phone_number = numar;
-- Afisare dbms_output.put_line('######### DONE #########');
-- dbms_output.put_line('Process: ' || process_s);
-- dbms_output.put_line('TYPE: ' || type_e);
-- dbms_output.put_line('Status: ' || status_s);
-- dbms_output.put_line('Acceptor: ' || acceptor_r);
-- dbms_output.put_line('Donor: ' || donor_r);
-- dbms_output.put_line('Porting: ' || porting_g);
-- dbms_output.put_line('Idate: ' || Idate_e);
-- dbms_output.put_line('Fdate: ' || Fdate_e);
-- dbms_output.put_line('Ancom_ID: ' || ancom_d);
-- dbms_output.put_line('Status_flow: ' || status_f);
-- dbms_output.put_line('Error: ' || error_r);
-- dbms_output.put_line('Creation: ' || creation_n);
-- dbms_output.put_line('######### FINISHED #########');
END;
you have many outputs in your procedure , you can store those data in a table then retrieve them.
Anyway as for your errors :
are you passing the first parameter with varchar or quotes. it should be numbers.
also I noticed parameter Idate_e is varchar however its seems you are passing date values. try as the below
DECLARE
phonenumb NUMBER;
process_s varchar2,
type_e varchar2,
status_s varchar2,
acceptor_r varchar2,
donor_r varchar2,
porting_g varchar2,
Idate_e date,
Fdate_e date,
ancom_d varchar2,
status_f varchar2,
error_r varchar2,
creation_n varchar2
begin
phone_info (1123,process_s,process_s,type_e,status_s,acceptor_r,donor_r,porting_g,Idate_e,Fdate_e,ancom_d,status_f,error_r,creation_n);
end;
/

PL/SQL: ORA-00917 Compilation failed, line 49 (11:56:09) The line numbers associated with

create or replace TRIGGER R_TRACKER_TRI
before insert on R_TRACKER
for each row
declare
v_number varchar2(15);
begin
if inserting then
:NEW.PROJECT_ID := PROJECT_ID(1);
:NEW.PRO_CREATED := LOCALTIMESTAMP;
:NEW.PRO_CREATED_BY := nvl(v('APP_USER'),USER);
IF :NEW.RECRUITMENT_TYPE= 'New' THEN
SELECT ('NEW/'||TO_CHAR(SYSDATE,'YY') || '/' || (NVL(MAX(SUBSTRB(PROJECT_ID,8)),10000)+1)) into v_number
FROM R_TRACKER
WHERE SUBSTRB(PROJECT_ID,1,3) = 'NEW';
:NEW.PROJECT_ID := v_number;
elsif :NEW.RECRUITMENT_TYPE= 'Replacement' THEN
SELECT ('REP/'||TO_CHAR(SYSDATE,'YY') || '/' || (NVL(MAX(SUBSTRB(PROJECT_ID,8)),10000)+1)) into v_number
FROM R_TRACKER
WHERE SUBSTRB(PROJECT_ID,1,3) = 'REP';
:NEW.PROJECT_ID := v_number;
end if;
INSERT INTO R_TRACKER
(
PROJECT_ID,
PRO_LOC,
DESIGNATION,
NO_OF_POSITION,
VACANCY_SINCE,
STATUS,
REMARKS,
UPLOAD,
RECRUITMENT_TYPE,
APPROVAL,
ACTION
)
VALUES
(
:NEW.PROJECT_ID,
:NEW.PRO_LOC,
:NEW.DESIGNATION,
:NEW.NO_OF_POSITION,
:NEW.VACANCY_SINCE,
:NEW.STATUS,
:NEW.REMARKS
:NEW.UPLOAD,
:NEW.RECRUITMENT_TYPE,
:NEW.APPROVAL,
:NEW.ACTION
);
end if;
end;
Looking at your code one can make out that you need to understand the use of Trigger. Please read it. In brief I wanted to tell that trigger is an event on a table. It is created to automate insertion/updation/deletion of column value of that table. In your case you are creating trigger on table R_TRACKER and then again at below inserting into it. This is wrong. See how you can do it.
--Table
CREATE TABLE R_TRACKER
(
PROJECT_ID VARCHAR2 (50),
PRO_LOC VARCHAR2 (50),
DESIGNATION VARCHAR2 (50),
NO_OF_POSITION VARCHAR2 (50),
VACANCY_SINCE VARCHAR2 (50),
STATUS VARCHAR2 (50),
REMARKS VARCHAR2 (50),
UPLOAD VARCHAR2 (50),
RECRUITMENT_TYPE VARCHAR2 (50),
APPROVAL VARCHAR2 (50),
ACTION VARCHAR2 (50)
);
--Trigger on table
CREATE OR REPLACE TRIGGER R_TRACKER_TRI
BEFORE INSERT ON R_TRACKER
FOR EACH ROW
DECLARE
v_number VARCHAR2 (15);
BEGIN
IF INSERTING
THEN
:NEW.PROJECT_ID := '1';--PROJECT_ID(1) -- This seems to be a function in your case;
--:NEW.PRO_CREATED := LOCALTIMESTAMP;
-- :NEW.PRO_CREATED_BY := NVL('APP_USER', USER);
IF :NEW.RECRUITMENT_TYPE = 'New'
THEN
SELECT ( 'NEW/'
|| TO_CHAR (SYSDATE, 'YY')
|| '/'
|| (NVL (MAX (SUBSTRB (PROJECT_ID, 8)), 10000) + 1))
INTO v_number
FROM R_TRACKER
WHERE SUBSTRB (PROJECT_ID, 1, 3) = 'NEW';
:NEW.PROJECT_ID := v_number;
ELSIF :NEW.RECRUITMENT_TYPE = 'Replacement'
THEN
SELECT ( 'REP/'
|| TO_CHAR (SYSDATE, 'YY')
|| '/'
|| (NVL (MAX (SUBSTRB (PROJECT_ID, 8)), 10000) + 1))
INTO v_number
FROM R_TRACKER
WHERE SUBSTRB (PROJECT_ID, 1, 3) = 'REP';
:NEW.PROJECT_ID := v_number;
END IF;
END IF;
END;

Stored procedure stopped working

I have a problem concerning a stored procedure. The stored procedure i programmed permits a third party provider to insert data into my database. It always worked fin up to 5 days ago when no data gets anymore inserted. I am really a complete rooky with respect to SQL so i do not know where to start investigating what could be the error. Any help, insights and advices are highly appreciated. Thanks in advance. Attached is the code.
create or replace PROCEDURE "GET_DROP_COPY"
(
P_BEGINSTRING IN VARCHAR2
, P_BODYLENGTH IN VARCHAR2
, P_MSGTYPE IN VARCHAR2
, P_MSGSEQNUM IN VARCHAR2
, P_SENDERCOMPID IN VARCHAR2
, P_SENDINGTIME IN VARCHAR2
, P_TARGETCOMPID IN VARCHAR2
, P_TARGETSUBID IN VARCHAR2
, P_AVGPX IN VARCHAR2
, P_CLORDID IN VARCHAR2
, P_CUMQTY IN VARCHAR2
, P_CURRENCY IN CHAR
, P_EXECID IN VARCHAR2
, P_SECURITYIDSOURCE IN NUMBER
, P_LASTPX IN NUMBER
, P_LASTQTY IN NUMBER
, P_ORDERID IN VARCHAR2
, P_ORDERQTY IN NUMBER
, P_ORDSTATUS IN VARCHAR2
, P_PRICE IN NUMBER
, P_ORDTYPE IN VARCHAR2
, P_SECURITYID IN VARCHAR2
, P_SIDE IN VARCHAR2
, P_FIELD55 IN VARCHAR2
, P_TIMEINFORCE IN VARCHAR2
, P_TRANSACTTIME IN VARCHAR2
, P_SETTLTYPE IN VARCHAR2
, P_TRADEDATE IN VARCHAR2
, P_EXDESTINATION IN VARCHAR2
, P_EXECTYPE IN VARCHAR2
, P_LEAVESQTY IN VARCHAR2
, P_SECURITYTYPE IN VARCHAR2
, P_SECONDARYORDERID IN VARCHAR2
, P_SECURITYEXCHANGE IN VARCHAR2
, P_ROUNDLOTBOOK IN NUMBER
, P_COPYMSGINDICATOR IN VARCHAR2
, P_REPEATING_GROUP IN NUMBER
, P_PARTY_ID IN VARCHAR2
, P_PARTYIDSOURCE IN VARCHAR2
, P_PARTYROLE IN NUMBER
, P_PARTYID2 IN VARCHAR2
, P_PARTYIDSOURCE2 IN VARCHAR2
, P_PARTYROLE2 IN NUMBER
, P_PARTYID3 IN VARCHAR2
, P_PARTYIDSOURCE3 IN VARCHAR2
, P_PARTYROLE3 IN NUMBER
, P_CHECKSUM IN NUMBER
) AS
l_count NUMBER;
l_modpor NUMBER(1,0);
l_logid NUMBER;
err_num NUMBER;
err_msg VARCHAR2(100);
BEGIN
SELECT NVL(MAX(ID),0) INTO l_logid
FROM LOG_PROCEDURE;
IF l_logid = 0 THEN
l_logid := 1;
ELSE
l_logid := l_logid + 1;
END IF;
INSERT INTO LOG_PROCEDURE (ID, ETL, INICIO, TRAZA, TABLA)
VALUES(l_logid, 'GET_DROP_COPY', SYSDATE, 'INSERT RECORD. ',
'DROP_COPY');
COMMIT;
INSERT INTO DROP_COPY (BEGINSTRING, BODYLENGTH, MSGTYPE, MSGSEQNUM,
SENDERCOMPID, SENDINGTIME, TARGETCOMPID, TARGETSUBID, AVGPX, CLORDID,
CUMQTY, CURRENCY, EXECID, SECURITYIDSOURCE, LASTPX, LASTQTY, ORDERID,
ORDERQTY, ORDSTATUS, PRICE, ORDTYPE, SECURITYID, SIDE, FIELD55,
TIMEINFORCE, TRANSACTTIME, SETTLTYPE, TRADEDATE, EXDESTINATION,
EXECTYPE, LEAVESQTY, SECURITYTYPE, SECONDARYORDERID, SECURITYEXCHANGE,
ROUNDLOTBOOK, COPYMSGINDICATOR, REPEATING_GROUP, PARTY_ID,
PARTYIDSOURCE, PARTYROLE, PARTYID2, PARTYIDSOURCE2, PARTYROLE2,
PARTYID3, PARTYIDSOURCE3, PARTYROLE3, CHECKSUM)
VALUES(P_BEGINSTRING, P_BODYLENGTH, P_MSGTYPE, P_MSGSEQNUM,
P_SENDERCOMPID, P_SENDINGTIME, P_TARGETCOMPID, P_TARGETSUBID, P_AVGPX,
P_CLORDID, P_CUMQTY, P_CURRENCY, P_EXECID, P_SECURITYIDSOURCE, P_LASTPX,
P_LASTQTY, P_ORDERID, P_ORDERQTY, P_ORDSTATUS, P_PRICE, P_ORDTYPE,
P_SECURITYID, P_SIDE, P_FIELD55, P_TIMEINFORCE, P_TRANSACTTIME,
P_SETTLTYPE, P_TRADEDATE, P_EXDESTINATION, P_EXECTYPE, P_LEAVESQTY,
P_SECURITYTYPE, P_SECONDARYORDERID, P_SECURITYEXCHANGE, P_ROUNDLOTBOOK,
P_COPYMSGINDICATOR, P_REPEATING_GROUP, P_PARTY_ID, P_PARTYIDSOURCE,
P_PARTYROLE, P_PARTYID2, P_PARTYIDSOURCE2, P_PARTYROLE2, P_PARTYID3,
P_PARTYIDSOURCE3, P_PARTYROLE3, P_CHECKSUM);
l_count := TO_CHAR(SQL%ROWCOUNT);
UPDATE LOG_PROCEDURE
SET FIN = SYSDATE,
ESTADO = 'OK',
TRAZA = TRAZA || l_count || ' REGISTRO(s) INSERTADO(s).'
WHERE ID = l_logid;
COMMIT;
IF (P_PARTY_ID IN ('009', '036', '016', '003') OR P_PARTYID2 IN ('009', '036', '016', '003') OR P_PARTYID3 IN ('009', '036', '016', '003')) AND (P_ORDERID NOT LIKE'%SER%') THEN
IF ( P_EXECTYPE NOT IN ('0', '4') AND ((P_PARTYROLE = 7 AND P_PARTY_ID = '058') OR (P_PARTYROLE2 = 7 AND P_PARTYID2 = '058') OR (P_PARTYROLE3 = 7 AND P_PARTYID3 = '058'))) THEN
l_modpor := 1;
ELSE
l_modpor := 0;
END IF;
INSERT INTO EQUITY_PORTFOLIO_DCMOV
( BEGINSTRING, BODYLENGTH, MSGTYPE, MSGSEQNUM, SENDERCOMPID, SENDINGTIME, TARGETCOMPID, TARGETSUBID, AVGPX, CLORDID,
CUMQTY, CURRENCY, EXECID, SECURITYIDSOURCE, LASTPX, LASTQTY, ORDERID, ORDERQTY, ORDSTATUS, PRICE, ORDTYPE, SECURITYID, SIDE, FIELD55,
TIMEINFORCE, TRANSACTTIME, SETTLTYPE, TRADEDATE, EXDESTINATION, EXECTYPE, LEAVESQTY, SECURITYTYPE, SECONDARYORDERID, SECURITYEXCHANGE,
ROUNDLOTBOOK, COPYMSGINDICATOR, REPEATING_GROUP, PARTY_ID, PARTYIDSOURCE, PARTYROLE, PARTYID2, PARTYIDSOURCE2, PARTYROLE2,
PARTYID3, PARTYIDSOURCE3, PARTYROLE3, CHECKSUM, ORIGEN, MODPOR
)
VALUES( P_BEGINSTRING, P_BODYLENGTH, P_MSGTYPE, P_MSGSEQNUM, P_SENDERCOMPID, TO_TIMESTAMP(P_SENDINGTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), P_TARGETCOMPID, P_TARGETSUBID, P_AVGPX,
P_CLORDID, P_CUMQTY, TRIM(P_CURRENCY), P_EXECID, P_SECURITYIDSOURCE, P_LASTPX, P_LASTQTY, P_ORDERID, P_ORDERQTY, P_ORDSTATUS, P_PRICE, P_ORDTYPE,
P_SECURITYID, P_SIDE, P_FIELD55, P_TIMEINFORCE, TO_TIMESTAMP(P_TRANSACTTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), P_SETTLTYPE, P_TRADEDATE, P_EXDESTINATION, P_EXECTYPE, P_LEAVESQTY,
P_SECURITYTYPE, P_SECONDARYORDERID, TRIM(P_SECURITYEXCHANGE), P_ROUNDLOTBOOK, TRIM(P_COPYMSGINDICATOR), P_REPEATING_GROUP, P_PARTY_ID, P_PARTYIDSOURCE,
P_PARTYROLE, P_PARTYID2, P_PARTYIDSOURCE2, P_PARTYROLE2, P_PARTYID3, P_PARTYIDSOURCE3, P_PARTYROLE3, P_CHECKSUM, 'LOCAL', l_modpor
);
SELECT COUNT(*) INTO l_count
FROM EQUITY_PORTFOLIO
WHERE SECURITYID = P_SECURITYID;
IF l_count >= 1 AND l_modpor = 1 THEN
ACTUALIZA_EQUITY_PORTFOLIO (P_ORDERID, P_SECURITYID, P_PRICE, P_ORDERQTY, P_EXECTYPE, P_ORDSTATUS, P_SIDE, TO_TIMESTAMP(P_SENDINGTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), TO_TIMESTAMP(P_TRANSACTTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), P_TRADEDATE, P_LASTPX, P_LASTQTY, l_modpor);
ELSE
IF l_count = 0 THEN
INSERT INTO EQUITY_PORTFOLIO(SECURITYID, SECURITY_ID, ID_ISIN, POSITION, POSITION_INI, AAAAMMDD, CURRENCY)
SELECT P_SECURITYID, EQDES.BLOOMBERG_TICKER, EQDES.ID_ISIN, 0, 0, P_TRADEDATE, CURRENCY
FROM EQUITY_DESCRIPTOR EQDES
WHERE ID_EXCH_SYMBOL = P_SECURITYID;
COMMIT;
ACTUALIZA_EQUITY_PORTFOLIO (P_ORDERID, P_SECURITYID, P_PRICE, P_ORDERQTY, P_EXECTYPE, P_ORDSTATUS, P_SIDE, TO_TIMESTAMP(P_SENDINGTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), TO_TIMESTAMP(P_TRANSACTTIME, 'YYYYMMDD-HH24:MI:SS.FF3'), P_TRADEDATE, P_LASTPX, P_LASTQTY, l_modpor);
END IF;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
err_num := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 100);
INSERT INTO DROP_COPY_ERROR (BEGINSTRING, BODYLENGTH, MSGTYPE, MSGSEQNUM,
SENDERCOMPID, SENDINGTIME, TARGETCOMPID, TARGETSUBID, AVGPX, CLORDID,
CUMQTY, CURRENCY, EXECID, SECURITYIDSOURCE, LASTPX, LASTQTY, ORDERID,
ORDERQTY, ORDSTATUS, PRICE, ORDTYPE, SECURITYID, SIDE, FIELD55,
TIMEINFORCE, TRANSACTTIME, SETTLTYPE, TRADEDATE, EXDESTINATION,
EXECTYPE, LEAVESQTY, SECURITYTYPE, SECONDARYORDERID, SECURITYEXCHANGE,
ROUNDLOTBOOK, COPYMSGINDICATOR, REPEATING_GROUP, PARTY_ID,
PARTYIDSOURCE, PARTYROLE, PARTYID2, PARTYIDSOURCE2, PARTYROLE2,
PARTYID3, PARTYIDSOURCE3, PARTYROLE3, CHECKSUM, LOGID)
VALUES(P_BEGINSTRING, P_BODYLENGTH, P_MSGTYPE, P_MSGSEQNUM,
P_SENDERCOMPID, P_SENDINGTIME, P_TARGETCOMPID, P_TARGETSUBID, P_AVGPX,
P_CLORDID, P_CUMQTY, P_CURRENCY, P_EXECID, P_SECURITYIDSOURCE, P_LASTPX,
P_LASTQTY, P_ORDERID, P_ORDERQTY, P_ORDSTATUS, P_PRICE, P_ORDTYPE,
P_SECURITYID, P_SIDE, P_FIELD55, P_TIMEINFORCE, P_TRANSACTTIME,
P_SETTLTYPE, P_TRADEDATE, P_EXDESTINATION, P_EXECTYPE, P_LEAVESQTY,
P_SECURITYTYPE, P_SECONDARYORDERID, P_SECURITYEXCHANGE, P_ROUNDLOTBOOK,
P_COPYMSGINDICATOR, P_REPEATING_GROUP, P_PARTY_ID, P_PARTYIDSOURCE,
P_PARTYROLE, P_PARTYID2, P_PARTYIDSOURCE2, P_PARTYROLE2, P_PARTYID3,
P_PARTYIDSOURCE3, P_PARTYROLE3, P_CHECKSUM, l_logid);
UPDATE LOG_PROCEDURE
SET FIN = SYSDATE,
ESTADO = 'ERROR',
CODERR = err_num,
MSGERR = err_msg
WHERE ID = l_logid;
COMMIT;
END GET_DROP_COPY;
This is the output when i run the procedure:
Connecting to the database CLBCB_TRADER.
ORA-01400: cannot insert NULL into ("CLBCBTRADER"."DROP_COPY_ERROR"."SENDINGTIME")
ORA-06512: at "CLBCBTRADER.GET_DROP_COPY", line 155
ORA-01400: cannot insert NULL into ("CLBCBTRADER"."DROP_COPY"."SENDINGTIME")
ORA-06512: at line 98
Process exited.
Disconnecting from the database CLBCB_TRADER.
Additionally, I should mention that the "SENDINGTIME" variable always looks like this so i dont see a problem: "20141110-13:30:03.394"
Looking at the error message, it seems that parameter P_SENDINGTIME is passed as a NULL value, and this is not a value allowed in your schema definition.
It seems that your third party provider changed something in the last days.
If that parameter was just a timestamp, you could set a default value to it running your script to alter the procedure by setting a default value:
create or replace PROCEDURE "GET_DROP_COPY" (
//...first part definition of script here
, P_SENDINGTIME IN VARCHAR2 := ''
//...rest definition of script here
)
//... body of script here
END GET_DROP_COPY;
Please note that:
you should first of all ask the provider whether they changed
anything
it may be a risky approach if you aren't sure of what that value should be
you may use sysdate to get a proper timestamp value - eg:
...
, P_SENDINGTIME IN VARCHAR2 := TO_CHAR(SYSDATE, 'MM.DD.YYYY HH24:MI:SS')
...
The error is telling you that you are trying to insert a NULL value into the SENDINGTIME field of GET_DROP_COPY. The field does not allow NULL values.
Either:
Insert an actual value
Allow nulls in your column.
You should probably look to the first option as there is probably a reason for the column not allowing nulls.