TO_DATE to insert in DB
Hi everybody
I need insert the date and time to Data Base with TO_DATE, but I don´t know if is functioning TO_DATE to insert the time or only the date.
Can someone help me?
Thanks.
Paul.
Hi Paul
Do it using Graphical mapping
Check DATE/TIME datatypes and Oracle Database
Thanks
Gaurav
Similar Messages
-
ORA-01840 error on inserting row trough object browser
Dear Oracle Community,
I'm getting the ORA-01840: Input value not long enough for date format error when I try to insert a row with the date value 24-MAY-10 with my object browser.
This is the problem column:
Column Name | Data Type| Nullable| Default | Primary Key
SIGNUPDATE |DATE |No | - | -
Now this will look like I'm using the wrong date format so I have googled and found that I should use the following query to check for the correct date format my database uses.
select * from nls_session_parameters where parameter = 'NLS_DATE_FORMAT';
This returns the DD-MON-RR format so I think I'm inserting the correct date format here.
What am I doing wrong?
I have already tried inserting with the following formats and tried replacing the - sign with the / sign.
DD-MON-RR
DD-MON-YY
DD-MON-YYYY
I have also tried using the SYSDATE is in the DD-MON-RR format trough the SQL commandline.
I'm feeling like an idiot this should be simple right?
Please help me out here this is frustrating, many thanks in advance.
J Nijmanusing the SYSDATE is in the DD-MON-RR format trough the SQL commandlineIn sqlplus try:
insert into <tablename> ( <date columnname> [, ... ] ) values ( sysdate [, ...] );
To get a sysdate date value added. Or specify the format string with a to_date expression:
insert into <tablename> ( <date columnname> [, ... ] ) values ( to_date( '24-may-10', 'dd-mon-yy') [, ... ] );
The engine isn't picky about separators agreeing with the format string, most any character in place of the '-' dash is acceptable.
Now to get an ora-1840 out of the object browser (Table/Data/Insert Row), I'm not having any luck trying to duplicate that. With the default nls_date_format 'DD-MON-YY' even trying bad dates (i.e. 30-feb-10 or 30-feb-2010, or even 31-apr-10) it either does an ora-1839: date not valid for month specified, or with a four digit year it gives an ora-1830: date format picture ends before converting entire input string.
Any RDBMS presents programmers with date and datetime challenges, its not just an oracle-frustration thing ;) -
Need to make function out of SQL
It is always taxinig for me to write DDL? I have come up with a method but it requires that I know each fieldname of the table. Here is the DDL I've come up with:
--------- CREATE A TABLE
CREATE TABLE "MY_INV_MAIN"
"STOREID" NUMBER NOT NULL
, "BUSI_DATE" DATE NOT NULL
, "PRIMARY_KEY" NUMBER NOT NULL
, "CONF_NUMB1" NUMBER NOT NULL
, ONF_NUMB2" NUMBER NOT NULL
--=== INSERT DATA INV_MAIN
- -- Dates should be To_date functions
INSERT INTO MY_INV_MAIN VALUES(141,'27-AUG-08',64143,12599.68,12599.68);
INSERT INTO MY_INV_MAIN VALUES(141,'28-AUG-08',64160,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'29-AUG-08',64222,3691.59,3691.59);
INSERT INTO MY_INV_MAIN VALUES(141,'30-AUG-08',64224,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'31-AUG-08',64273,22103.69,22103.69);
INSERT INTO MY_INV_MAIN VALUES(141,'01-SEP-08',64322,3836,3836);
INSERT INTO MY_INV_MAIN VALUES(141,'04-SEP-08',64380,5296.4,5296.4);
INSERT INTO MY_INV_MAIN VALUES(141,'05-SEP-08',64410,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'07-SEP-08',64496,22627.74,22627.74);
INSERT INTO MY_INV_MAIN VALUES(141,'08-SEP-08',64559,10376.61,10376.61);
INSERT INTO MY_INV_MAIN VALUES(141,'09-SEP-08',64575,2644.62,2644.62);
INSERT INTO MY_INV_MAIN VALUES(141,'11-SEP-08',64627,5983.33,5983.33);
INSERT INTO MY_INV_MAIN VALUES(141,'13-SEP-08',64677,7573.21,7573.21);
INSERT INTO MY_INV_MAIN VALUES(141,'14-SEP-08',64743,22839.3,22839.3);
INSERT INTO MY_INV_MAIN VALUES(141,'17-SEP-08',64817,11593.69,11593.69);
INSERT INTO MY_INV_MAIN VALUES(141,'18-SEP-08',64835,2958.97,2958.97);
INSERT INTO MY_INV_MAIN VALUES(141,'19-SEP-08',64869,3570.74,3570.74);
INSERT INTO MY_INV_MAIN VALUES(141,'20-SEP-08',64896,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'21-SEP-08',64984,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'21-SEP-08',64992,21372.82,21372.82);
INSERT INTO MY_INV_MAIN VALUES(141,'22-SEP-08',64995,2927.13,2927.13);
INSERT INTO MY_INV_MAIN VALUES(141,'23-SEP-08',65021,2712.38,2712.38);
INSERT INTO MY_INV_MAIN VALUES(141,'24-SEP-08',65038,0,0);
INSERT INTO MY_INV_MAIN VALUES(141,'26-SEP-08',65091,6763.8,6763.8);
INSERT INTO MY_INV_MAIN VALUES(141,'27-SEP-08',65130,4985.73,4985.73);
INSERT INTO MY_INV_MAIN VALUES(141,'28-SEP-08',65197,24950.45,24950.45);
INSERT INTO MY_INV_MAIN VALUES(141,'28-SEP-08',65199,4648.38,4648.38);
INSERT INTO MY_INV_MAIN VALUES(141,'30-AUG-09',74146,18081.37,18081.37);
INSERT INTO MY_INV_MAIN VALUES(141,'06-SEP-09',74253,17183.25,17183.25);
INSERT INTO MY_INV_MAIN VALUES(141,'13-SEP-09',74454,17688.41,17688.41);
INSERT INTO MY_INV_MAIN VALUES(141,'20-SEP-09',74599,18211.29,18211.29);
INSERT INTO MY_INV_MAIN VALUES(141,'27-SEP-09',74722,16809.21,16809.21);
--=== GENERATE INSERT STATEMENTS
WITH MyTableColumns AS
SELECT TNAME as tablename
, CNAME as columnname
FROM COL
where tNAME in ('MY_INV_MAIN')
ORDER BY TNAME
, Pivoted_Table as
( select tablename
, MAX(DECODE(columnname, 'STOREID', columnname, 0 )) STOREID
, MAX(DECODE(columnname, 'BUSI_DATE', columnname, 0 )) BUSI_DATE
, MAX(DECODE(columnname, 'PRIMARY_KEY', columnname, 0 )) PRIMARY_KEY
, MAX(DECODE(columnname, 'CONF_NUMB1', columnname, 0 )) CONF_NUMB1
, MAX(DECODE(columnname, 'CONF_NUMB2', columnname, 0 )) CONF_NUMB2
FROM MyTableColumns
group by tablename
, MyInsertStatments as
(SELECT 'INSERT INTO ' ||
tablename ||
' VALUES (' ||
STOREID || ',' ||
BUSI_DATE || ',' ||
PRIMARY_KEY || ',' ||
CONF_NUMB1 || ',' ||
CONF_NUMB2 || ') FROM ' || tablename || ';' as INSERT_CLAUSE
FROM Pivoted_table;
END FUNCTION1) How can I write this code as a function
FUNCTION ReturnInsertStatements(tablename in varchar2,
delimitedStringOfColumns in varchar2 default null) as varchar2
-- Reads columns of the table like in above SQL
-- Generate Inserts
And return a string of 'Create Table Code " & InsertStatements in a format (INSERT INTO MY_INV_MAIN VALUES(141,'27-SEP-09',74722,16809.21,16809.21);TheHTMLDJ wrote:
Tubby wrote:
Why would you want pl/sql code to do this? There are much more efficient tools with which to move data between databases.
1. I was trying to flex my new knowledge of pivots.
2) I found this one which seems pretty good except line wraps and makes inserts messy:
http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml
Nothing i tried would prevent the problem. CAn you fix or do you have a suggestion on some other free tool. In the rare occasion i need to move data in this fashion (typically i'd be looking at data pump, imp/exp, database links, etc...) i just use [SQL Developer|http://www.oracle.com/technology/software/products/sql/index.html] which is free and actually pretty good (developer wise).
>
>
Also as a tip, you should always specify the columns you're using in the INSERT.
I don't see why that's necessary when you are populating all fields with data.Because if you create code to do this, how do you know the order of the columns in the table? At best you get lucky and get an ORA error (like trying to put a date in to a number field), at worst you put the wrong columns data into another column and it goes unnoticed. -
Hi,
I am trying to execute the following query on toad.
INSERT INTO BATCH_REQ(BATCH_TARGET, BO_TYPE, TRANSACTION_ID, TRANSACTION_DATA, TIMESTAMP, CHKSUM_FIELDVALU, SEQUENCE_ID)Values
('BATCH TARGET','BUSINESSOBJEXT','TRANSACTIONID','DATA','07/15/2010 02:47:46 PM','4','Sequence_ID')
this query is dynamically created by TIBCO to get the date time format as needed by oracle. I have executed in toad and tibco i am getting the same error.
ERROR:
BW-JDBC-100014 Job-192000 Error in [Batch Request Handler/Unit Test/Process Definition (1).process/SQL Direct]
"JDBC error reported: (SQLState = HY000) - java.sql.SQLException: [tibcosoftwareinc][Oracle JDBC Driver][Oracle]ORA-01843: not a valid month
caused by: java.sql.SQLException: [tibcosoftwareinc][Oracle JDBC Driver][Oracle]ORA-01843: not a valid month
I do understand by some reason, Oracle is not accepting the month, but when I see the date I am sending i feel its a valid month. ('07/15/2010 02:47:46 PM')
MM/dd/yyyy HH:mm:ss AM/PM
some where its wrong but i am unable to figure it out.
Any help is much appreciated.
ThanksYou (and your tool) really want to use a date value rather than a string when you do the insert. Relying on implicit data type conversion is going to be problematic.
The simplest option would be to use the TO_DATE function
INSERT INTO BATCH_REQ(BATCH_TARGET, BO_TYPE, TRANSACTION_ID, TRANSACTION_DATA, TIMESTAMP, CHKSUM_FIELDVALU, SEQUENCE_ID)Values
('BATCH TARGET','BUSINESSOBJEXT','TRANSACTIONID','DATA',to_date('07/15/2010 02:47:46 PM', 'MM/DD/YYYY HH:MI:SS AM'),'4','Sequence_ID')You could also change the NLS_DATE_FORMAT of the session (this needs to be done for each session)
ALTER SESSION SET nls_date_format = 'MM/DD/YYYY HH:MI:SS AM'That should cause the implicit conversion to do what you want. But if you have other scripts that depend on a different date format, those scripts would now break.
Justin -
Need help in query..for a select / update on multiple rows
DROP TABLE TEST;
CREATE TABLE TEST (ACCOUNT_NUMBER VARCHAR2(30), TIER_NUMBER NUMBER, FROM_DATE DATE, TO_DATE DATE)
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 1, '28-FEB-11','28-FEB-11');
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 2, '28-FEB-11','28-FEB-11');
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 3, '28-FEB-11','01-MAR-11');
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 1, '01-MAR-11','01-MAR-11');
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 2, '01-MAR-11','01-MAR-11');
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 1, '02-MAR-11',NULL);
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 2, '02-MAR-11',NULL);
INSERT INTO TEST(ACCOUNT_NUMBER, TIER_NUMBER, FROM_DATE, TO_DATE) VALUES ('11111', 3, '02-MAR-11',NULL);
in this table, for each FROM_DATE, the TO_DATE value should be same for all tiers.
In the above data, for FROM_DATE = 28-Feb-11, there are 3 rows with TIER_NUMBER = 1, 2, 3.
TIER_NUMBER = 1,2 --> TO_DATE = 28-FEB-11
But for TIER_NUMBER = 3 --> TO_DATE = 01-MAR-11 (this occurred due to some incorrect logic).
Any help on how to identify such records with wrong data?
And how to update the TIER_NUMBER=3 row with TO_DATE = 28-FEB-11 (whatever we have in TO_DATE for TIER_NUMBER = 1 as that is the minimum tier)?
The table would contain millions of accounts and atleast 6 rows for each account.
Thanks.Hi,
I think this should solve your problem
Declare
todate date;
differenc number;
CURSOR myCursor IS
select to_date, FIRST_VALUE(TO_DATE) over
(partition by account_number, from_date order by tier_number) - to_date as differ from test
FOR UPDATE of to_date;
BEGIN
FOR idx IN myCursor LOOP
todate :=idx.to_date;
differenc := idx.differ;
UPDATE test
SET to_date = todate + differenc
WHERE CURRENT OF myCursor;
END LOOP;
COMMIT;
END;
/It both finds and updates rows that doesn't have correct to_date value -
Why between for date is not returning data for this query ?
Hello,
i have a table with this structure and i am writing this query for fetching some rows based on some condition , but this query is not returning any data . Can you please tell why ?
ID DT
003 11/8/2011
002 10/8/2011
001 9/8/2011
And the query is :
SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy');
Edited by: bootstrap on Aug 13, 2011 7:10 AM>
>
but what is the problem with that, why that date is not matched when i am providing the date format ?Which part don't you understand? You did not use TO_DATE while inserting data and default date format was mm/dd/yyyy, right? Same default date format is used if you issue:
SELECT * FROM TABLE_NAME Your original post states the above select returns:
ID DT
003 11/8/2011
002 10/8/2011
001 9/8/2011So dates you inserted are November 8, 2011, October 8 2011 and September 8 2011. Now TO_DATE('08/08/2011','dd/mm/yyyy') is August 8 2011 and TO_DATE('12/08/2011','dd/mm/yyyy') is August 12 2011. So obviously:
SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy');will not return any rows. Bottome line - never write code that uses implicit date conversions since your code becomes client NLS settings dependent and might work for one client and fail or produce wrong results for other client.
SY. -
Export sql insert generates to_date('1987-04-19','DD-MON-RR')
export sql insert generates buggy dates :
Scott --> Tables --> EMP --> export --> sql inserts
Columns --> ALL
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7788,'SCOTT','ANALYST',7566,to_date('1987-04-19','DD-MON-RR'),3000,null,20);
the to_date is invalid.
this bug happens only when selecting ALL columns
cheers
LaurentHi Sue,
I have version 1.0.0.15.57 Linux x86 (downloaded last week).
Is there a way to produce trace files or additional info so that we can debug this one?
$ env
PATH=/bin:/usr/bin
LANG=en_US.UTF-8
HOME=/home/lsc
DISPLAY=:0.0
_=/usr/bin/env
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (i586)
VERSION = 10
$ /home/lsc/sqldeveloper/sqldeveloper
Oracle SQL Developer 1.0
Copyright (c) 2005 Oracle Corporation. All Rights Reserved.
Working directory is /home/lsc/sqldeveloper/jdev/bin
Assert: Initializing.. [email protected]
Assert: Unknown Node:8: USER
Assert: Unknown Node:8: SHARED QUERIES
Assert: Unknown Node:8: TABLE EDITORS
Assert: Unknown Node:8: VIEWS
Assert: Unknown Node:8: MVIEWS
Assert: Unknown Node:8: SYNONYM
Assert: Unknown Node:8: SEQ
Assert: Unknown Node:8: Recycle Bin
Assert: Unknown Node:8: DB Link
Assert: Unknown Node:8: MVIEW LOG
Assert: Unknown Node:8: PLSQL
Assert: Unknown Node:8: TRigger
Assert: Unknown Node:8: INDEX
Assert: SQLView initedAssert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#text
Assert: Folder:Unsupported node in report.xml:#textexpand "connections "
expand "LSC02"
expand "Tables"
select "EMP"
right-click EMP
chose EXPORT--SQL INSERT
Format=INSERT Output=File TABLE=EMP File=/home/lsc/EMP.sql Columns=ALL
Click apply
$ cat EMP.sql
-- INSERTING into EMP
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7369,'SMITH','CLERK',7902,to_date('1980-12-17','DD-MON-RR'),800,null,20);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7499,'ALLEN','SALESMAN',7698,to_date('1981-02-20','DD-MON-RR'),1600,300,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7521,'WARD','SALESMAN',7698,to_date('1981-02-22','DD-MON-RR'),1250,500,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7566,'JONES','MANAGER',7839,to_date('1981-04-02','DD-MON-RR'),2975,null,20);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7654,'MARTIN','SALESMAN',7698,to_date('1981-09-28','DD-MON-RR'),1250,1400,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7698,'BLAKE','MANAGER',7839,to_date('1981-05-01','DD-MON-RR'),2850,null,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7782,'CLARK','MANAGER',7839,to_date('1981-06-09','DD-MON-RR'),2450,null,10);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7788,'SCOTT','ANALYST',7566,to_date('1987-04-19','DD-MON-RR'),3800,null,20);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7839,'KING','PRESIDENT',null,to_date('1981-11-17','DD-MON-RR'),5000,null,10);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7844,'TURNER','SALESMAN',7698,to_date('1981-09-08','DD-MON-RR'),1500,0,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7876,'ADAMS','CLERK',7788,to_date('1987-05-23','DD-MON-RR'),1100,null,20);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7900,'JAMES','CLERK',7698,to_date('1981-12-03','DD-MON-RR'),950,null,30);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7902,'FORD','ANALYST',7566,to_date('1981-12-03','DD-MON-RR'),3000,null,20);
Insert into "EMP" ("EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO") values (7934,'MILLER','CLERK',7782,to_date('1982-01-23','DD-MON-RR'),1300,null,10); -
Inserting dates using TO_DATE and getDateTime with preparedStatement
Hi
I have this code here but its giving error msg, *"Cannot find symbol" Symbol: method TO_DATE(...)* . Can someone point to me what is wrong??
public static void pstmtQry(Connection con) {
try{
queryTable1 =" INSERT INTO Table1 "
+ "(DATE, ID) "
+ " VALUES (?, ?)";
pstmtTable1 = con.prepareStatement(queryTable1);
catch.......{
method1() {
try {
pstmtTable1.setString(1,*TO_DATE*(getDateTime("dd/MM/yyyy"), "DD/MM/YYYY"));
pstmtTable1.setString(2,ID);
RS = pstmtTable1.executeQuery();Thanks
Edited by: okun on Jun 9, 2010 9:02 PM
Edited by: okun on Jun 9, 2010 9:03 PMBelow is the query i would like to change to a preparedStatement:
query = " INSERT INTO Table1 "
+ "(DATE, ID) "
+ " VALUES ( TO_DATE('"
+ getDateTime("dd/MM/yyyy") + "','DD/MM/YYYY') "', '"
+ ID + "')";{code} -
** How to use TO_DATE function in Stored Proc. for JDBC in ABAP-XSL mapping
Hi friends,
I use ABAP-XSL mapping to insert records in Oracle table. My Sender is File and receiver is JDBC. We use Oracle 10g database. All fields in table are VARCHAR2 except one field; this is having type 'DATE'.
I use Stored procedure to update the records in table. I have converted my string into date using the Oracle TO_DATE function. But, when I use this format, it throws an error in the Receiver CC. (But, the message is processed successfully in SXMB_MONI).
The input format I formed like below:
<X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">
Value in Payload is like below.
<X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">TO_DATE('18-11-1991','DD-MM-YYYY')</X_EMP_START_DT>
Error in CC comes as below:
Error processing request in sax parser: Error when executing statement for table/stored proc. 'SP_EMP_DETAILS' (structure 'STATEMENT'): java.lang.NumberFormatException: For input string: "TO_DATE('18"
Friends, I have tried, but unable to find the correct solution to insert.
Kindly help me to solve this issue.
Kind Regards,
Jegathees P.
(But, the same is working fine if we use direct method in ABAP-XSL ie. not thru Stored Procedure)Hi Sinha,
Thanks for your reply.
I used the syntax
<xsl:call-template name="date:format-date">
<xsl:with-param name="date-time" select="string" />
<xsl:with-param name="pattern" select="string" />
</xsl:call-template>
in my Abap XSL. But, its not working correctly. The problem is 'href' function to import "date.xsl" in my XSLT is not able to do that. The system throws an error. Moreover, it is not able to write the command 'extension-element-prefixes' in my <xsl:stylesheet namespace>
May be I am not able to understand how to use this.
Anyway, I solved this problem by handling date conversion inside Oracle Stored Procedure. Now, its working fine.
Thank you. -
How to insert the sysdate time into the database
hi all,
when i execute the following query,
insert into table_name
(date_field)
values
(to_date(sysdate, 'yyyy/mm/dd hh24:mi:ss'));
The value is inserted as 08-02-12 12:00:00. In this query, it always stores the default time as 12 a.m.
But i need to insert the original system time not the default one.
please help me how to rectify it.I do not understand as to why you are using the to_date function on sysdate since sysdate is already in date format.
If date_field is of the data type date, then the following dml should work.
insert into table_name(date_field) values (sysdate);
In case date_field is a varchar2 field and you want to store the date and time in a string format, then the following statement should work.
insert into table_name (date_field)
values (to_char(sysdate, 'yyyy/mm/dd hh24:mi:ss')); -
Insert old missing data from one table to another(databaase trigger)
Hello,
i want to do two things
1)I want to insert old missing data from one table to another through a database trigger but it can't be executed that way i don't know what should i do in case of replacing old data in table_1 into table_2
2)what should i use :NEW. OR :OLD. instead.
3) what should i do if i have records exising between the two dates
i want to surpress the existing records.
the following code is what i have but no effect occured.
CREATE OR REPLACE TRIGGER ATTENDANCEE_FOLLOWS
AFTER INSERT ON ACCESSLOG
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
V_COUNT NUMBER(2);
V_TIME_OUT DATE;
V_DATE_IN DATE;
V_DATE_OUT DATE;
V_TIME_IN DATE;
V_ATT_FLAG VARCHAR2(3);
V_EMP_ID NUMBER(11);
CURSOR EMP_FOLLOWS IS
SELECT EMPLOYEEID , LOGDATE , LOGTIME , INOUT
FROM ACCESSLOG
WHERE LOGDATE
BETWEEN TO_DATE('18/12/2008','dd/mm/rrrr')
AND TO_DATE('19/12/2008','dd/mm/rrrr');
BEGIN
FOR EMP IN EMP_FOLLOWS LOOP
SELECT COUNT(*)
INTO V_COUNT
FROM EMP_ATTENDANCEE
WHERE EMP_ID = EMP.EMPLOYEEID
AND DATE_IN = EMP.LOGDATE
AND ATT_FLAG = 'I';
IF V_COUNT = 0 THEN
INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT
,TIME_IN ,TIME_OUT,ATT_FLAG)
VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_IN
NULL,
TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_IN
NULL ,'I');
ELSIF V_COUNT > 0 THEN
UPDATE EMP_ATTENDANCEE
SET DATE_OUT = TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
TIME_OUT = TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_OUT
ATT_FLAG = 'O'
WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
AND DATE_IN <= (SELECT MAX (DATE_IN )
FROM EMP_ATTENDANCEE
WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
AND DATE_OUT IS NULL
AND TIME_OUT IS NULL )
AND DATE_OUT IS NULL
AND TIME_OUT IS NULL ;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN RAISE;
END ATTENDANCEE_FOLLOWS ;
Regards,
Abdetu..INSERT INTO SALES_MASTER
( NO
, Name
, PINCODE )
SELECT SALESMANNO
, SALESMANNAME
, PINCODE
FROM SALESMAN_MASTER;Regards,
Christian Balz -
Unable to insert date and time when using date datatype
Hi
I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
Thanksuser633278 wrote:
Hi
I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
ThanksYou most certainly can save the time. A DATE column, by definition stores date and time. What you describe is a presentation problem, and setting nls_date_format at the system as an init parm is the weakest of all settings as it is overridden by several other locations.
without seeing the exact sql that produced the error (not just your description of what you think you were doing) it is impossible to say for sure.
However, I'd suggest you read http://edstevensdba.wordpress.com/2011/04/07/nls_date_format/ -
CREATE OR REPLACE
PACKAGE BODY xxcsi_ib_data_ob_ecs_pkg
v_update_date DATE := SYSDATE;
PROCEDURE print_log(
i_message IN VARCHAR2)
IS
BEGIN
-- dbms_output.put_line('Log '||TO_CHAR(sysdate,'DD-MON-YYYY HH24:MI:SS :')||i_message);
fnd_file.put_line(fnd_file.LOG,'Log '||TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS :')||i_message);
EXCEPTION
WHEN no_data_found THEN
NULL;
WHEN OTHERS THEN
NULL;
END;
PROCEDURE main_prc(
o_chr_errbuff OUT VARCHAR2 ,
o_num_retcode OUT NUMBER ,
i_org_id IN NUMBER)
IS
CURSOR cur_get_parent_ib_rec(c_from DATE ,c_to DATE)
IS
SELECT
/*+ index(a CSI_ITEM_INSTANCES_X3)*/
---CREATE MODE ITEM
A.creation_date ,
A.last_update_date ,
A.last_oe_order_line_id line_id ,
A.inventory_item_id ,
A.instance_id ,
A.instance_type_code ,
msib.segment1
FROM csi_item_instances A ,
mtl_system_items_b msib
WHERE 1=1
-- AND a.instance_id = 33371916
--AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
AND msib.inventory_item_id=A.inventory_item_id
AND msib.organization_id =
(SELECT mp.organization_id
FROM mtl_parameters mp
WHERE mp.organization_code = 'IMO'
-- AND msib.organization_id = 85
-- and msib.segment1 like '475%'
--AND msib.segment1 like 'TREX%'
AND EXISTS
(SELECT 1
FROM fnd_lookup_values
WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
AND language = 'US'
AND lookup_code = msib.segment1
--and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
UNION
SELECT
/*+ index(a CSI_ITEM_INSTANCES_X3)*/
---CREATE MODE SEARCH
A.creation_date ,
A.last_update_date ,
A.last_oe_order_line_id line_id ,
A.inventory_item_id ,
A.instance_id ,
A.instance_type_code ,
msib.segment1
FROM csi_item_instances A ,
mtl_system_items_b msib
WHERE 1=1
--AND a.instance_id = 33371916
--AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
AND msib.inventory_item_id=A.inventory_item_id
AND msib.organization_id =
(SELECT mp.organization_id
FROM mtl_parameters mp
WHERE mp.organization_code = 'IMO'
-- AND msib.organization_id = 85
-- and msib.segment1 like '475%'
--AND msib.segment1 like 'TREX%'
AND EXISTS
(SELECT 1
FROM fnd_lookup_values
WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
AND language = 'US'
AND tag ='ALL TREX ITEMS'
AND SUBSTR(lookup_code,1,4) = SUBSTR(msib.segment1,1,4)
--and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
UNION
SELECT
/*+ index(a CSI_ITEM_INSTANCES_X3)*/
---UPDATE MODE ITEM
A.creation_date ,
A.last_update_date ,
A.last_oe_order_line_id line_id ,
A.inventory_item_id ,
A.instance_id ,
A.instance_type_code ,
msib.segment1
FROM csi_item_instances A ,
mtl_system_items_b msib
WHERE 1=1
--AND a.instance_id = 33371916
--AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
AND msib.inventory_item_id=A.inventory_item_id
AND msib.organization_id =
(SELECT mp.organization_id
FROM mtl_parameters mp
WHERE mp.organization_code = 'IMO'
-- AND msib.organization_id = 85
-- and msib.segment1 like '475%'
--AND msib.segment1 like 'TREX%'
AND EXISTS
(SELECT 1
FROM fnd_lookup_values
WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
AND language = 'US'
AND lookup_code = msib.segment1
--and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
AND EXISTS
(SELECT
/*+ index(ct CSI_TRANSACTIONS_U01)*/
1
FROM csi_item_instances_h h ,
csi_transactions ct
WHERE 1 =1
AND ct.transaction_type_id IN (1)
AND ct.transaction_id = h.transaction_id
AND ct.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
AND A.instance_id =h.instance_id
UNION
SELECT
/*+ index(a CSI_ITEM_INSTANCES_X3)*/
---UPDATE MODE SEARCH
A.creation_date ,
A.last_update_date ,
A.last_oe_order_line_id line_id ,
A.inventory_item_id ,
A.instance_id ,
A.instance_type_code ,
msib.segment1
FROM csi_item_instances A ,
mtl_system_items_b msib
WHERE 1=1
--AND a.instance_id = 33371916
--AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
AND msib.inventory_item_id=A.inventory_item_id
AND msib.organization_id =
(SELECT mp.organization_id
FROM mtl_parameters mp
WHERE mp.organization_code = 'IMO'
-- AND msib.organization_id = 85
-- and msib.segment1 like '475%'
--AND msib.segment1 like 'TREX%'
AND EXISTS
(SELECT 1
FROM fnd_lookup_values
WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
AND language = 'US'
AND tag ='ALL TREX ITEMS'
AND SUBSTR(lookup_code,1,4) = SUBSTR(msib.segment1,1,4)
--and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
AND EXISTS
(SELECT
/*+ index(ct CSI_TRANSACTIONS_U01)*/
1
FROM csi_item_instances_h h ,
csi_transactions ct
WHERE 1 =1
AND ct.transaction_type_id IN (1)
AND ct.transaction_id = h.transaction_id
AND ct.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
AND A.instance_id =h.instance_id
ORDER BY 1 DESC,
2 ;
CURSOR cur_get_child_ib_rec(c_instance_id NUMBER)
IS
SELECT cir.subject_id
FROM csi.csi_ii_relationships cir
WHERE cir.object_id = c_instance_id;
CURSOR cur_get_outbound_data(c_instance_id NUMBER)
IS
SELECT cii.instance_id instance_id,
cii.instance_number instance_number,
cii.inventory_item_id inventory_item_id,
msi.segment1 segment1, --CONCATENATED_SEGMENTS,
msi.description description, --DESCRIPTION,
cii.inv_master_organization_id master_organization_id,
cii.serial_number serial_number,
cii.system_id system_id,
cst.NAME system_name,
cii.quantity quantity,
cii.unit_of_measure uom,
cii.active_start_date active_start_date,
cii.active_end_date active_end_date,
cii.install_date install_date,
cii.object_version_number object_version_number,
cii.last_vld_organization_id,
hou.NAME pre_registration_location,
looh.header_id last_header_id,
looh.order_number emerson_order_number,
cii.last_oe_order_line_id order_line_id,
NVL(lool.actual_shipment_date, lool.fulfillment_date) actual_shipment_date,
(SELECT DISTINCT pap.email_address
FROM fnd_user fu ,
per_all_people_f pap
WHERE fu.employee_id = pap.person_id
and sysdate between pap.effective_start_date and nvl(pap.effective_end_date, sysdate)
AND fu.user_id = NVL(wdd.created_by,lool.created_by)
) email_address,
(SELECT DISTINCT hp.party_name
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "Bill_To_company_name",--------------------------CH-ID-1.1 STARTS-----------
(SELECT DISTINCT hps.party_site_id
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_party_SITE_ID",
(SELECT DISTINCT hl.state
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_STATE",
(SELECT DISTINCT hl.country
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_COUNTRY",
(SELECT DISTINCT hl.city
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_CITY",
(SELECT DISTINCT hl.address1
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_LOCATION",
(SELECT DISTINCT hp.party_name
FROM hz_parties hp,
hz_party_sites hps,
hz_party_site_uses hpsu,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.ship_to_address = hcsua.site_use_id
) AS "Ship_to_company_name",
(SELECT DISTINCT hps.party_site_id
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_party_SITE_ID",
(SELECT DISTINCT hl.state
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_STATE",
(SELECT DISTINCT hl.country
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_COUNTRY",
(SELECT DISTINCT hl.city
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_CITY",
(SELECT DISTINCT hl.address1
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_LOCATION",
(SELECT DISTINCT hl.postal_code
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "SHIP_TO_PIN_CODE",
(SELECT DISTINCT hl.postal_code
FROM hz_parties hp,
hz_party_sites hps ,
hz_party_site_uses hpsu ,
hz_locations hl
WHERE hp.party_id = hps.party_id
AND hps.location_id = hl.location_id
AND hps.party_site_id = hpsu.party_site_id(+)
AND hps.party_site_id =
(SELECT hcasa.party_site_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) AS "BILL_TO_PIN_CODE",
(SELECT hcsua.LOCATION
FROM apps.hz_cust_site_uses_all hcsua
WHERE cia.ship_to_address = hcsua.site_use_id
) "SHIP_TO_NUMBER",
(SELECT hcsua.LOCATION
FROM apps.hz_cust_site_uses_all hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
) "BILL_TO_NUMBER",
(SELECT DISTINCT hca.account_number
FROM hz_cust_accounts hca
WHERE hca.cust_account_id =
(SELECT hcasa.cust_account_id
FROM apps.hz_cust_acct_sites hcasa
WHERE hcasa.cust_acct_site_id =
(SELECT hcsua.cust_acct_site_id
FROM apps.hz_cust_site_uses hcsua
WHERE cia.bill_to_address = hcsua.site_use_id
)AS "CUSTOMER_NUMBER", --------------------------CH-ID-1.1 ENDS -----------
(SELECT civ.attribute_value
FROM csi_iea_values civ,
csi_i_extended_attribs ciea
WHERE civ.attribute_id = ciea.attribute_id
AND ciea.attribute_code = '011 LICENSE NUMBER'
AND civ.instance_id = cii.instance_id
) AS "EA_LICENSE_NUMBER",
(SELECT civ.attribute_value
FROM csi_iea_values civ,
csi_i_extended_attribs ciea
WHERE civ.attribute_id = ciea.attribute_id
AND ciea.attribute_code = 'VA_SALES_ORDER_NUMBER'
AND civ.instance_id = cii.instance_id
) AS "EA_VA_SALES_ORDER_NUM",
(SELECT NAME
FROM hr_all_organization_units
WHERE organization_id = cii.inv_master_organization_id
) master_organization_name
FROM csi_item_instances cii,
csi_systems_tl cst,
-- MTL_SYSTEM_ITEMS_VL MSIKFV,
-- MTL_SYSTEM_ITEMS MSI,
mtl_system_items_b msi,
hr_all_organization_units hou,
oe_order_lines lool,
oe_order_headers looh,
wsh_delivery_details wdd,
csi_i_parties cip,
csi_ip_accounts cia
WHERE cii.last_vld_organization_id = msi.organization_id
AND cii.inventory_item_id = msi.inventory_item_id
-- AND CII.LAST_VLD_ORGANIZATION_ID = MSIKFV.ORGANIZATION_ID
-- AND CII.INVENTORY_ITEM_ID = MSIKFV.INVENTORY_ITEM_ID
AND hou.organization_id(+) = cii.last_vld_organization_id
AND cii.last_oe_order_line_id = lool.line_id
AND lool.header_id = looh.header_id
AND cii.last_oe_order_line_id = wdd.source_line_id
-- AND WDD.SOURCE_LINE_ID = LOOL.LINE_ID
-- AND WDD.SOURCE_HEADER_ID = LOOH.HEADER_ID
AND cii.instance_id = cip.instance_id
AND cii.system_id = cst.system_id(+)
AND cip.party_source_table = 'HZ_PARTIES'
AND cip.relationship_type_code = 'OWNER'
AND cip.instance_party_id = cia.instance_party_id
AND cia.relationship_type_code(+) = 'OWNER'
AND cii.instance_status_id = 1052
AND cst.language(+) = 'US'
AND cii.instance_id = c_instance_id;
CURSOR cur_get_ib_warranty (c_instance_id NUMBER)
IS
SELECT kh.contract_number,
kh.scs_code,
kh.start_date,
kh.end_date,
(kh.end_date-kh.start_date) duration,
clet.NAME coverage_name,
clet.item_description coverage_desc,
b.segment1 service_name,
t.description service_desc
FROM okc_k_headers_b kh,
okc_k_lines_b kl,
okc_k_items ki,
csi_item_instances c,
mtl_system_items_b i,
okc_k_lines_b cleb,
okc_k_lines_tl clet,
okc_k_items ki1,
mtl_system_items_b_kfv b,
mtl_system_items_tl t
WHERE kh.contract_number_modifier IS NULL
AND kh.ID = kl.dnz_chr_id
AND kh.ID = ki.dnz_chr_id
AND kl.ID = ki.cle_id
AND ki.jtot_object1_code IN ('OKX_CUSTPROD')
AND c.last_vld_organization_id = i.organization_id
AND ki.object1_id1 = TO_CHAR(c.instance_id)
AND c.inventory_item_id = i.inventory_item_id
AND kl.cle_id = cleb.cle_id
AND cleb.ID = clet.ID
AND clet.language = userenv('LANG')
AND cleb.lse_id IN (2,15,20)
AND cleb.cle_id = ki1.cle_id
AND b.inventory_item_id = t.inventory_item_id
AND b.organization_id = t.organization_id
AND t.language = userenv('LANG')
AND to_number(ki1.object1_id1) = b.inventory_item_id
AND to_number(ki1.object1_id2) = b.organization_id
AND c.instance_id = c_instance_id;
--v1.2 comment ends
CURSOR cur_get_to_date( c_req_id NUMBER,c_conc_prog_id NUMBER)
IS
SELECT requested_start_date
FROM fnd_concurrent_requests
WHERE request_id = c_req_id
AND concurrent_program_id = c_conc_prog_id;
/*Record Type Declaration*/
TYPE ib_ecs_dat_record
IS
record
instance_id csi_item_instances.instance_id%TYPE,
instance_number csi_item_instances.instance_number%TYPE,
inventory_item_id csi_item_instances.inventory_item_id%TYPE,
segment1 mtl_system_items_b.segment1%TYPE,
description mtl_system_items_b.description%TYPE,
master_organization_id csi_item_instances.inv_master_organization_id%TYPE,
serial_number csi_item_instances.serial_number%TYPE,
system_id csi_item_instances.system_id%TYPE,
system_name csi_systems_tl.NAME%TYPE,
quantity csi_item_instances.quantity%TYPE,
uom csi_item_instances.unit_of_measure%TYPE,
active_start_date csi_item_instances.active_start_date%TYPE,
active_end_date csi_item_instances.active_end_date%TYPE,
install_date csi_item_instances.install_date%TYPE,
obj_version_num csi_item_instances.object_version_number%TYPE,
last_vld_organization_id csi_item_instances.last_vld_organization_id%TYPE,
pre_registration_location VARCHAR2(500),
order_header_id oe_order_headers_all.header_id%TYPE,
order_number oe_order_headers_all.order_number%TYPE,
order_line_id csi_item_instances.last_oe_order_line_id%TYPE,
actual_shipment_date oe_order_lines_all.actual_shipment_date%TYPE,
email_address per_all_people_f.email_address%TYPE,
bill_to_company_name hz_parties.party_name%TYPE,
bill_to_site_id hz_party_sites.party_site_id%TYPE,
bill_to_state hz_locations.state%TYPE,
bill_to_country hz_locations.country%TYPE,
bill_to_city hz_locations.city%TYPE,
bill_to_location hz_locations.address1%TYPE,
ship_to_company_name hz_parties.party_name%TYPE,
ship_to_site_id hz_party_sites.party_site_id%TYPE,
ship_to_state hz_locations.state%TYPE,
ship_to_country hz_locations.country%TYPE,
ship_to_city hz_locations.city%TYPE,
ship_to_location hz_locations.address1%TYPE,
ship_to_pin_code hz_locations.postal_code%TYPE,
bill_to_pin_code hz_locations.postal_code%TYPE,
ship_to_number hz_cust_site_uses_all.LOCATION%TYPE,
bill_to_number hz_cust_site_uses_all.LOCATION%TYPE,
customer_number hz_cust_accounts.account_number%TYPE,
ea_license_number csi_iea_values.attribute_value%TYPE,
ea_va_sales_order_num csi_iea_values.attribute_value%TYPE,
master_organization_name hr_all_organization_units.NAME%TYPE );
TYPE tab_typ_ib_ecs_dat
IS
TABLE OF ib_ecs_dat_record INDEX BY binary_integer;
TYPE ib_parent_dat_record
IS
record
creation_date DATE,
last_update_date DATE,
order_line_id csi_item_instances.last_oe_order_line_id%TYPE,
inventory_item_id csi_item_instances.inventory_item_id%TYPE,
instance_id csi_item_instances.instance_id%TYPE,
instance_type_code csi_item_instances.instance_type_code%TYPE,
segment1 mtl_system_items_b.segment1%TYPE );
TYPE tab_typ_ib_parent_dat
IS
TABLE OF ib_parent_dat_record INDEX BY binary_integer;
--/*Record Type Declaration*/
-- TYPE parent_ib_record IS RECORD (
-- creation_date csi_item_instances.creation_date%TYPE,
-- last_update_date csi_item_instances.last_update_date%TYPE,
-- inventory_item_id csi_item_instances.inventory_item_id%TYPE,
-- instance_id csi_item_instances.instance_id%TYPE,
-- instance_type_code csi_item_instances.instance_type_code%TYPE,
-- segment1 mtl_system_items_b.segment1%type
-- TYPE tab_typ_par_ib_collection IS TABLE OF parent_ib_record
-- INDEX BY BINARY_INTEGER;
-- tab_par_ib_rec tab_typ_par_ib_collection;
v_segment1 mtl_system_items_b.segment1%TYPE;
v_request_id NUMBER := fnd_global.conc_request_id;
v_conc_prog_id NUMBER := fnd_global.conc_program_id;
v_created_by NUMBER := fnd_profile.VALUE('USER_ID');
v_last_update_login NUMBER := fnd_global.login_id;
v_to DATE := SYSDATE;
v_from DATE := SYSDATE-100;
v_count NUMBER := NULL;
-- v_header_id NUMBER := NULL;
-- v_line_id NUMBER := NULL;
-- v_org_id NUMBER := NULL;
-- v_ship_from_org_id NUMBER := NULL;
--v1.2 begin
-- v_master_org_id NUMBER := NULL;
-- v_item_type VARCHAR2(100) := null;
-- v_top_model_line_id NUMBER := NULL;
-- v_serial_tag_number VARCHAR2(100) := null;
TYPE tbl_req_start_date_type
IS
TABLE OF DATE INDEX BY pls_integer;
tbl_req_start_date tbl_req_start_date_type;
--v1.2 ends
--v1.3 starts
-- v_flow_status_code VARCHAR2(100) := null;
-- v_line_number NUMBER := NULL;
-- v_shipment_number NUMBER := NULL;
-- v_option_number NUMBER := NULL;
-- v_component_number NUMBER := NULL;
-- v_service_number NUMBER := NULL;
--v1.3 ends
-- v_model_string VARCHAR2(100) := NULL;
-- v_end_cust NUMBER := NULL;
-- v_end_cust_site_id NUMBER := NULL;
-- v_location_type_code VARCHAR2(100) := null;
-- v_location_id NUMBER := NULL;
-- v_tag VARCHAR2(100) := NULL;
-- v_inventory_item_status VARCHAR2(100) := NULL;
-- v_serial_number VARCHAR2(100) := NULL;
-- v_serial_return VARCHAR2(200) := NULL;
--rec_ext_attr Rec_Ext_Attr_type ;
v_ret_error_message VARCHAR2(2000):= NULL;
v_ret_error_flag VARCHAR2(1) := NULL;
v_error_message VARCHAR2(2000):= NULL;
v_error_flag VARCHAR2(1) := NULL;
v_error_at VARCHAR2(100) := NULL;
-- v_to1 DATE := sysdate;
-- v_from1 DATE := sysdate-45;
tab_ib_parent_dat tab_typ_ib_parent_dat;
tab_ib_ecs_dat tab_typ_ib_ecs_dat;
tab_ib_ecs_dat_c tab_typ_ib_ecs_dat;
BEGIN
print_log('*********************************************************************');
print_log('print log message 01');
print_log('Process Starts... : '||to_date(SYSDATE,'DD-MON-YYYY HH24:MI:SS'));
v_error_at := 'Start of the process';
fnd_client_info.set_org_context(i_org_id);
-- v1.2 begins, to get from date ----==----
BEGIN
print_log('print log message 02');
--OPEN get_from_date( v_request_id,v_conc_prog_id);
--FETCH get_from_date INTO v_from;
--CLOSE get_from_date;
v_error_at := 'main Process/ before from ';
-- v_from := Sysdate-15;
v_from := SYSDATE-45;
--Added v1.4 ,AND ARGUMENT1 = i_org_id
SELECT
/*+ index(a FND_CONCURRENT_REQUESTS_N6) index(a FND_CONCURRENT_REQUESTS_N7)*/
requested_start_date BULK COLLECT
INTO tbl_req_start_date
FROM fnd_concurrent_requests
WHERE request_id < v_request_id
AND concurrent_program_id = v_conc_prog_id
AND argument1 = i_org_id
AND status_code ='C'
AND phase_code ='C';
v_error_at := 'main Process/ after from selection ';
IF tbl_req_start_date.count >0 THEN
FOR i IN tbl_req_start_date.FIRST .. tbl_req_start_date.LAST
LOOP
IF v_from < tbl_req_start_date(i) THEN
v_from := tbl_req_start_date(i);
print_log( 'Tabel Req StartDate : '||tbl_req_start_date(i));
print_log( 'In the Loop VFrom : '||v_from);
END IF;
END LOOP;
END IF;
v_error_at := 'main Process/ after from Loop ';
print_log( 'Out the loop v_from is : '||v_from);
EXCEPTION
WHEN no_data_found THEN
print_log('Error in from_date process exception : '||sqlerrm);
print_log('Error at : '||v_error_at);
v_from := NULL;
WHEN OTHERS THEN
print_log('Error in from_date process exception : '||sqlerrm);
print_log('Error at : '||v_error_at);
v_from := NULL;
END;
-- v1.2 ends---==----
print_log('print log message 03');
BEGIN
OPEN cur_get_to_date ( v_request_id,v_conc_prog_id);
FETCH cur_get_to_date INTO v_to;
CLOSE cur_get_to_date;
--v1.3 starts
v_update_date := v_to -(1/86400);
--v1.3 ends
v_error_at := 'main Process/ after from and to date';
print_log('v_from1... : '||TO_CHAR(v_from,'DD-MON-YYYY HH24:MI:SS'));
print_log('v_to1 ... : '||TO_CHAR(v_to ,'DD-MON-YYYY HH24:MI:SS'));
--v1.3 starts
print_log('Updated v_to ... : '||TO_CHAR(v_update_date ,'DD-MON-YYYY HH24:MI:SS'));
--v1.3 ends
EXCEPTION
WHEN no_data_found THEN
print_log('Error in main process1 : '||sqlerrm);
print_log('Error at : '||v_error_at);
WHEN OTHERS THEN
print_log('Error in main process1 : '||sqlerrm);
print_log('Error at : '||v_error_at);
END;
BEGIN
print_log('print log message 04');
OPEN cur_get_parent_ib_rec(v_from ,v_to);
LOOP
print_log('After Loop Get Records v_from... : '||TO_CHAR(v_from,'DD-MON-YYYY HH24:MI:SS'));
print_log('After Loop Get Records v_to ... : '||TO_CHAR(v_to ,'DD-MON-YYYY HH24:MI:SS'));
FETCH cur_get_parent_ib_rec BULK COLLECT INTO tab_ib_parent_dat;
print_log('Parent Instance first : ');
-- FOR i IN 1 .. tab_ib_parent_dat.COUNT
print_log('print log message 05');
FOR i IN tab_ib_parent_dat.FIRST .. tab_ib_parent_dat.LAST
LOOP
BEGIN
print_log('Parent Instance : '||tab_ib_parent_dat(i).instance_id);
print_log('====================================================================');
v_error_at := 'main Process/ start of the loop';
v_ret_error_flag := NULL;
v_segment1 := NULL;
EXCEPTION
WHEN no_data_found THEN
print_log('Error in main process exception1 : '||sqlerrm);
print_log('Error at : '||v_error_at);
WHEN OTHERS THEN
print_log('Error in main process exception1 : '||sqlerrm);
print_log('Error at : '||v_error_at);
END;
OPEN cur_get_outbound_data(tab_ib_parent_dat(i).instance_id);
LOOP
FETCH cur_get_outbound_data BULK COLLECT INTO tab_ib_ecs_dat;
--FOR j IN 1 .. tab_ib_ecs_dat.COUNT
FOR j IN tab_ib_ecs_dat.FIRST .. tab_ib_ecs_dat.LAST
LOOP
BEGIN
BEGIN
SELECT COUNT(1)
INTO v_count
FROM apps.xxcsi_trex_ob_ecs_mhm
WHERE instance_id = NVL(tab_ib_ecs_dat_c(j).instance_id,'');
EXCEPTION
WHEN OTHERS THEN
v_count := 0;
END;
print_log('v_count : '||v_count);
IF v_count = 0 THEN
-- print_log('PARENT_DAT: '||NVL(tab_ib_ecs_dat(j).instance_id);
print_log('print log message 06');
INSERT
INTO xxcsi_trex_ob_ecs_mhm
instance_id,
instance_number,
inventory_item_id,
unit,
unit_name,
master_organization_id,
serial_number,
quantity,
uom,
active_start_date,
active_end_date,
install_date,
object_version_number,
last_vld_organization_id,
pre_registration_location,
order_header_id,
order_number,
order_line_id,
pre_registration_date,
pre_registration_operator,
bill_to_customer_name,
bill_to_site_id ,
bill_to_state ,
bill_to_country ,
bill_to_city ,
bill_to_location ,
ship_to_customer_name,
ship_to_site_id ,
ship_to_state ,
ship_to_country ,
ship_to_city ,
ship_to_location,
ship_to_pin_code,
bill_to_pin_code,
ship_to_number,
bill_to_number,
customer_number,
ea_license_number,
ea_va_sales_order_number,
parent_instance_id,
parent_y_n,
process_flag,
error_code,
error_details,
request_id,
created_by,
creation_date,
last_updated_by,
last_update_date,
last_update_login,
eai_process_flag,
master_organization_name,
system_id,
system_name
VALUES
NVL(tab_ib_ecs_dat(j).instance_id,''),
NVL(tab_ib_ecs_dat(j).instance_number,''),
NVL(tab_ib_ecs_dat(j).inventory_item_id,''),
NVL(tab_ib_ecs_dat(j).segment1,''),
NVL(tab_ib_ecs_dat(j).description,''),
NVL(tab_ib_ecs_dat(j).master_organization_id,''),
NVL(tab_ib_ecs_dat(j).serial_number,''),
NVL(tab_ib_ecs_dat(j).quantity,''),
NVL(tab_ib_ecs_dat(j).uom,''),
NVL(tab_ib_ecs_dat(j).active_start_date,''),
NVL(tab_ib_ecs_dat(j).active_end_date,''),
NVL(tab_ib_ecs_dat(j).install_date,''),
NVL(tab_ib_ecs_dat(j).obj_version_num,''),
NVL(tab_ib_ecs_dat(j).last_vld_organization_id,''),
NVL(tab_ib_ecs_dat(j).pre_registration_location,''),
NVL(tab_ib_ecs_dat(j).order_header_id,''),
NVL(tab_ib_ecs_dat(j).order_number,''),
NVL(tab_ib_ecs_dat(j).order_line_id,''),
NVL(tab_ib_ecs_dat(j).actual_shipment_date,''),
NVL(tab_ib_ecs_dat(j).email_address,''),
NVL(tab_ib_ecs_dat(j).bill_to_company_name,''),
NVL(tab_ib_ecs_dat(j).bill_to_site_id,''),
NVL(tab_ib_ecs_dat(j).bill_to_state,''),
NVL(tab_ib_ecs_dat(j).bill_to_country,''),
NVL(tab_ib_ecs_dat(j).bill_to_city,''),
NVL(tab_ib_ecs_dat(j).bill_to_location,''),
NVL(tab_ib_ecs_dat(j).ship_to_company_name,''),
NVL(tab_ib_ecs_dat(j).ship_to_site_id,''),
NVL(tab_ib_ecs_dat(j).ship_to_state,''),
NVL(tab_ib_ecs_dat(j).ship_to_country,''),
NVL(tab_ib_ecs_dat(j).ship_to_city,''),
NVL(tab_ib_ecs_dat(j).ship_to_location,''),
NVL(tab_ib_ecs_dat(j).ship_to_pin_code,''),
NVL(tab_ib_ecs_dat(j).bill_to_pin_code,''),
NVL(tab_ib_ecs_dat(j).ship_to_number,''),
NVL(tab_ib_ecs_dat(j).bill_to_number,''),
NVL(tab_ib_ecs_dat(j).customer_number,''),
NVL(tab_ib_ecs_dat(j).ea_license_number,''),
NVL(tab_ib_ecs_dat(j).ea_va_sales_order_num,''),
NULL,
'P',
'N',
NULL,
NULL,
v_request_id,
v_created_by,
SYSDATE,
v_created_by,
SYSDATE,
v_last_update_login,
'N',
NVL(tab_ib_ecs_dat(j).master_organization_name,''),
NVL(tab_ib_ecs_dat(j).system_id,''),
NVL(tab_ib_ecs_dat(j).system_name,'')
ELSE
Update apps.xxcsi_trex_ob_ecs_mhm set
instance_id=NVL(tab_ib_ecs_dat_c(j).instance_id,''),
instance_number= NVL(tab_ib_ecs_dat_c(j).instance_number,''),
inventory_item_id= NVL(tab_ib_ecs_dat_c(j).inventory_item_id,''),
unit = NVL(tab_ib_ecs_dat_c(j).segment1,''),
unit_name = NVL(tab_ib_ecs_dat_c(j).description,''),
master_organization_id=NVL(tab_ib_ecs_dat_c(j).master_organization_id,''),
--serial_number=NVL(tab_ib_ecs_dat_c(j).serial_number,''),
quantity= NVL(tab_ib_ecs_dat_c(j).quantity,''),
uom=NVL(tab_ib_ecs_dat_c(j).uom,''),
active_start_date= NVL(tab_ib_ecs_dat_c(j).active_start_date,''),
active_end_date= NVL(tab_ib_ecs_dat_c(j).active_end_date,''),
install_date= NVL(tab_ib_ecs_dat_c(j).install_date,''),
object_version_number=NVL(tab_ib_ecs_dat_c(j).obj_version_num,''),
last_vld_organization_id= NVL(tab_ib_ecs_dat_c(j).last_vld_organization_id,''),
pre_registration_location=NVL(tab_ib_ecs_dat_c(j).pre_registration_location,''),
order_header_id=NVL(tab_ib_ecs_dat_c(j).order_header_id,''),
order_number= NVL(tab_ib_ecs_dat_c(j).order_number,''),
order_line_id=NVL(tab_ib_ecs_dat_c(j).order_line_id,''),
pre_registration_date= NVL(tab_ib_ecs_dat_c(j).actual_shipment_date,''),
pre_registration_operator= NVL(tab_ib_ecs_dat_c(j).email_address,''),
bill_to_customer_name=NVL(tab_ib_ecs_dat_c(j).bill_to_company_name,''),
bill_to_site_id = NVL(tab_ib_ecs_dat_c(j).bill_to_site_id,''),
bill_to_state = NVL(tab_ib_ecs_dat_c(j).bill_to_state,''),
bill_to_country =NVL(tab_ib_ecs_dat_c(j).bill_to_country,''),
bill_to_city = NVL(tab_ib_ecs_dat_c(j).bill_to_city,''),
bill_to_location = NVL(tab_ib_ecs_dat_c(j).bill_to_location,''),
ship_to_customer_name=NVL(tab_ib_ecs_dat_c(j).ship_to_company_name,''),
ship_to_site_id = NVL(tab_ib_ecs_dat_c(j).ship_to_site_id,''),
ship_to_state =NVL(tab_ib_ecs_dat_c(j).ship_to_state,''),
ship_to_country=NVL(tab_ib_ecs_dat_c(j).ship_to_country,''),
ship_to_city =NVL(tab_ib_ecs_dat_c(j).ship_to_city,''),
ship_to_location= NVL(tab_ib_ecs_dat_c(j).ship_to_location,''),
ship_to_pin_code= NVL(tab_ib_ecs_dat_c(j).ship_to_pin_code,''),
bill_to_pin_code=NVL(tab_ib_ecs_dat_c(j).bill_to_pin_code,''),
ship_to_number=NVL(tab_ib_ecs_dat_c(j).ship_to_number,''),
bill_to_number= NVL(tab_ib_ecs_dat_c(j).bill_to_number,''),
customer_number= NVL(tab_ib_ecs_dat_c(j).customer_number,''),
ea_license_number= NVL(tab_ib_ecs_dat_c(j).ea_license_number,''),
ea_va_sales_order_number= NVL(tab_ib_ecs_dat_c(j).ea_va_sales_order_num,''),
parent_instance_id=NVL(tab_ib_parent_dat(i).instance_id,''),
parent_y_n='C',
process_flag='N',
error_code= NULL,
error_details= NULL,
request_id=v_request_id,
created_by=v_created_by,
creation_date= SYSDATE,
last_updated_by=v_created_by,
last_update_date=SYSDATE,
last_update_login= v_last_update_login,
eai_process_flag='Y',
master_organization_name=NVL(tab_ib_ecs_dat_c(j).master_organization_name,''),
system_id= NVL(tab_ib_ecs_dat_c(j).system_id,''),
system_name= NVL(tab_ib_ecs_dat_c(j).system_name,'')
WHERE instance_id = NVL(tab_ib_ecs_dat_c(j).instance_id,'');
END IF; --V_COUNT
EXCEPTION
WHEN no_data_found THEN
print_log('Error in inserting Parent Instance : '||tab_ib_ecs_dat(j).instance_id||': '||sqlerrm);
WHEN OTHERS THEN
print_log('Error in inserting Parent Instance : '||tab_ib_ecs_dat(j).instance_id||': '||sqlerrm);
END;
-- END LOOP;
END LOOP;
EXIT
WHEN cur_get_outbound_data%notfound;
END LOOP;
CLOSE cur_get_outbound_data;
print_log('print log message 07');
BEGIN
FOR rec_get_child_ib_rec IN cur_get_child_ib_rec
tab_ib_parent_dat(i).instance_id
LOOP
print_log
'cur_get_child_ib_rec : '||tab_ib_parent_dat(i).instance_id
OPEN cur_get_outbound_data(rec_get_child_ib_rec.subject_id);
LOOP
FETCH cur_get_outbound_data BULK COLLECT INTO tab_ib_ecs_dat_c;
-- tab_ib_ecs_dat_c1 := tab_ib_ecs_dat_c;
-- FOR k IN 1 .. tab_ib_ecs_dat_c.COUNT
FOR k IN tab_ib_ecs_dat_c.FIRST .. tab_ib_ecs_dat_c.LAST
LOOP
print_log('Child Instance : '||tab_ib_ecs_dat_c(k).instance_id);
-- BEGIN
BEGIN
SELECT COUNT(1)
INTO v_count
FROM apps.xxcsi_trex_ob_ecs_mhm
WHERE instance_id = NVL(tab_ib_ecs_dat_c(k).instance_id,'');
EXCEPTION
WHEN OTHERS THEN
v_count := 0;
END;
print_log('v_count : '||v_count);
IF v_count = 0 THEN
BEGIN
INSERT
INTO xxcsi_trex_ob_ecs_mhm
instance_id,
instance_number,
inventory_item_id,
unit,
unit_name,
master_organization_id,
serial_number,
quantity,
uom,
active_start_date,
active_end_date,
install_date,
object_version_number,
last_vld_organization_id,
pre_registration_location,
order_header_id,
order_number,
order_line_id,
pre_registration_date,
pre_registration_operator,
bill_to_customer_name,
bill_to_site_id ,
bill_to_state ,
bill_to_country ,
bill_to_city ,
bill_to_location ,
ship_to_customer_name,
ship_to_site_id ,
ship_to_state ,
ship_to_country ,
ship_to_city ,
ship_to_location ,
ship_to_pin_code,
bill_to_pin_code,
ship_to_number,
bill_to_number,
customer_number,
ea_license_number,
ea_va_sales_order_number,
parent_instance_id,
parent_y_n,
process_flag,
error_code,
error_details,
request_id,
created_by,
creation_date,
last_updated_by,
last_update_date,
last_update_login,
eai_process_flag,
master_organization_name,
system_id,
system_name
VALUES
NVL(tab_ib_ecs_dat_c(k).instance_id,''),
NVL(tab_ib_ecs_dat_c(k).instance_number,''),
NVL(tab_ib_ecs_dat_c(k).inventory_item_id,''),
NVL(tab_ib_ecs_dat_c(k).segment1,''),
NVL(tab_ib_ecs_dat_c(k).description,''),
NVL(tab_ib_ecs_dat_c(k).master_organization_id,''),
NVL(tab_ib_ecs_dat_c(k).serial_number,''),
NVL(tab_ib_ecs_dat_c(k).quantity,''),
NVL(tab_ib_ecs_dat_c(k).uom,''),
NVL(tab_ib_ecs_dat_c(k).active_start_date,''),
NVL(tab_ib_ecs_dat_c(k).active_end_date,''),
NVL(tab_ib_ecs_dat_c(k).install_date,''),
NVL(tab_ib_ecs_dat_c(k).obj_version_num,''),
NVL(tab_ib_ecs_dat_c(k).last_vld_organization_id,''),
NVL(tab_ib_ecs_dat_c(k).pre_registration_location,''),
NVL(tab_ib_ecs_dat_c(k).order_header_id,''),
NVL(tab_ib_ecs_dat_c(k).order_number,''),
NVL(tab_ib_ecs_dat_c(k).order_line_id,''),
NVL(tab_ib_ecs_dat_c(k).actual_shipment_date,''),
NVL(tab_ib_ecs_dat_c(k).email_address,''),
NVL(tab_ib_ecs_dat_c(k).bill_to_company_name,''),
NVL(tab_ib_ecs_dat_c(k).bill_to_site_id,''),
NVL(tab_ib_ecs_dat_c(k).bill_to_state,''),
NVL(tab_ib_ecs_dat_c(k).bill_to_counThe logic is:
1. Create any new lookup table rows that may be needed
2. Create new data rows that reference the lookup table
All you did was post a buch of code. You didn't post ANYTHING that shows how you executed that code or what the result was.
You need to SHOW US (not tell us):
1. WHAT you do
2. HOW you do it
3. WHAT results you get
4. WHAT results you expected to get
The code you posted has some SERIOUS ISSUES. Here are just three of them
1. You are using BULK COLLECT without a LIMIT clause
2. You are using unnecessary IF . . .COUNT statements to test collections for values. The FOR clause will simply NOT execute if the collection is empty so the IF statements add unnecessary clutter.
3. The first loop iterates a collection but sets a single SCALAR value - making that loop totally USELESS
LOOP
IF v_from < tbl_req_start_date(i) THEN
v_from := tbl_req_start_date(i);
print_log( 'Tabel Req StartDate : '||tbl_req_start_date(i));
print_log( 'In the Loop VFrom : '||v_from);
END IF;
END LOOP;
That checks EVERY row in the collection and appears to save the MAX value of 'tbl_req_state_date' into the 'v_from' variable.
What is the point of that? -
Inserting to a new table from a remote connection
I am having difficulties with selecting records from a remote database and inserting them into a current table. The following
statement is what I am using:
insert into sme_lc (WTN, BTN, BTNNAME, PICCODE, PICDATE, CRDDDST)
select a.wtn_cd as WTN,
a.old_btn_cd as BTN,
a.old_billing_nm as BTNName,
'LC LOSS' as PICCode,
a.event_dt as PICDate,
b.crd||b.ddst_cd as CRDDDST
from [email protected] a, [email protected] b
where a.old_btn_cd = b.btn_cd
and a.old_btn_cust_cd = b.cust_cd_suf
and b.crd in ('ASM','AMM')
and a.status_cd = 'L'
and a.status_type_cd = 'A'
and a.region_cd = 'O'
and a.event_dt between to_date('02-04-01','yy-mm-dd') and to_date('02-04-30','yy-mm-dd')
and (a.old_btn_cd, a.old_btn_cust_cd, a.wtn_cd) not in
(select old_btn_cd, old_btn_cust_cd, wtn_cd from [email protected] c
where c.old_btn_cd = a.old_btn_cd and c.old_btn_cust_cd = a.old_btn_cust_cd
and c.wtn_cd = a.wtn_cd
and c.status_cd = 'W' and a.status_cd = 'L' and c.event_dt > a.event_dt);
It returns an error of
and a.event_dt between to_date('02-04-01','yy-mm-dd') and to_date('02-04-30','yy-mm-dd')
ERROR at line 15:
ORA-00920: invalid relational operator
ORA-02063: preceding line from EIA.WORLD
If I remove the insert statement and simply run a select query, it runs fine. Does anyone have any ideas? Your help is much
appreciated!Try the following:
insert into sme_lc
(WTN, BTN, BTNNAME,
PICCODE, PICDATE, CRDDDST)
select a.wtn_cd, a.old_btn_cd , a.old_billing_nm,
'LC LOSS', a.event_dt, b.crd||b.ddst_cd
from [email protected] a, [email protected] b
where a.old_btn_cd = b.btn_cd
and a.old_btn_cust_cd = b.cust_cd_suf
and b.crd in ('ASM','AMM')
and a.status_cd = 'L'
and a.status_type_cd = 'A'
and a.region_cd = 'O'
and (a.event_dt between to_date('02-04-01','yy-mm-dd') and to_date('02-04-30','yy-mm-dd') )
and NOT EXISTS
(select 1
from [email protected] c
where c.old_btn_cd = a.old_btn_cd
and c.old_btn_cust_cd = a.old_btn_cust_cd
and c.wtn_cd = a.wtn_cd
and c.status_cd = 'W'
and c.event_dt > a.event_dt); -
Strange result from insert into...select query
Hello guys,
I need your preciuos help for a question maybe simple, but that I can't explain by myself!
I have a query of "insert into...select" that, as I have explained in the title, returns a strange result. In facts, If I execute ONLY the SELECT statement the query returns the expected result (so 2 rows); instead If I execute the entire statement, that is the "insert into...select", the query returns 0 rows inserted!!
Following an example of the query:
INSERT
INTO TITOLI_ORI
COD_TITOLO_RICCONS ,
D_ESTRAZIONE ,
COD_SOCIETA ,
COD_PIANO_CONTABILE ,
COD_CONTO_CONTABILE ,
COD_RUBRICATO_STATISTICO_1 ,
COD_NDG ,
NUM_ESEGUITO ,
CUR_IMPORTO_RICCONS ,
CUR_IMPORTO_BICO ,
FLG_MODIFICATO ,
CUR_NON_ASSEGNATO ,
FLG_QUOTATO ,
COD_CATEG ,
TIP_COPERTURA ,
TIPTAS_TITOLO
SELECT NEWID,
'28-feb-2111',
COD_SOCIETA,
COD_PIANO_CONTABILE,
COD_CONTO_CONTABILE,
COD_RUBRICATO_STATISTICO_1,
COD_NDG,
NUM_ESEGUITO,
CUR_VAL_IMPEGNI,
'ABC' as CUR_IMPORTO_BICO,
0 as FLG_MODIFICATO,
NULL as CUR_NON_ASSEGNATO,
FLG_QUOTATO,
COD_CATEG,
TIP_COPERTURA,
TIP_TASSO
FROM
(SELECT S.COD_SOC AS COD_SOCIETA,
S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
TRC.COD_NDG AS COD_NDG,
TRC.COD_ESEG AS NUM_ESEGUITO,
CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
TRC.TIP_QUOTAZ AS FLG_QUOTATO,
TRC.COD_CAT_TIT AS COD_CATEG,
TIP_COP AS TIP_COPERTURA,
T.TIP_TASSO AS TIP_TASSO
FROM S_SLD_CNTB S
INNER JOIN
(SELECT DISTINCT COD_SOC,
TIP_PIANO_CNTB,
COD_CONTO_CNTB,
COD_RUBR_STAT ,
COD_INTER_TIT AS COD_INTER
FROM S_COLLEG_CONTO_CNTB_TIT
WHERE COD_SOC = 'ME'
) CCC
ON S.COD_SOC = CCC.COD_SOC
AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
INNER JOIN S_TIT_RICCONS TRC
ON CCC.COD_INTER = TRC.COD_INTER_TIT
AND CCC.COD_SOC = TRC.COD_SOC
AND TRC.COD_RAGGR_IAS = RTRIM('VALUE1 ')
AND TRC.COD_RAGGR_IAS NOT IN ('VALUE2')
AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('VALUE3')
AND TRC.DES_MOV_TIT = RTRIM('VALUE4 ')
AND TRC.COD_CAT_TIT = RTRIM('VALUE4 ')
AND TRC.COD_INTER_TIT = RTRIM('VALUE5')
AND '28-feb-2011' = TRC.DAT_RIF
LEFT JOIN S_TIT T
ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
AND T.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = T.DAT_RIF
INNER JOIN S_ANAG_SOGG AG
ON TRC.COD_NDG = AG.COD_NDG
AND AG.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = AG.DAT_RIF
WHERE S.DAT_RIF = '28-feb-2011'
AND (S.FLG_ANULL_BICO = 0
OR S.FLG_ANULL_BICO IS NULL)
AND S.COD_SOC = 'V6'
AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
AND S.TIP_PIANO_CNTB = 'V7'
AND TRC.IMP_PLUS_MINUS_VAL < 0
AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('VALUE8 '))
Thanks a lotRight, I have executed this steps:
- I have changed the query with the select count(*)
- Changed the insert into with the select count(*)
- Executed the insert into
These are the result:
SQL> select count(*) from TITOLI_ORI2;
COUNT(*)
1
BUT:
SQL> select * from TITOLI_ORI2;
A
0
The insert into that I've modified is this:
INSERT INTO bsc.TITOLI_ORI2
select count(*)
FROM
(SELECT bsc.NEWID,
TO_DATE('28-feb-2111','DD-MON-YYYY') as data,
COD_SOCIETA,
COD_PIANO_CONTABILE,
COD_CONTO_CONTABILE,
COD_RUBRICATO_STATISTICO_1,
COD_NDG,
NUM_ESEGUITO,
CUR_VAL_IMPEGNI,
'ABC' AS CUR_IMPORTO_BICO,
0 AS FLG_MODIFICATO,
NULL CUR_NON_ASSEGNATO,
FLG_QUOTATO,
COD_CATEG,
TIP_COPERTURA,
TIP_TASSO
FROM
(SELECT S.COD_SOC AS COD_SOCIETA,
S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
TRC.COD_NDG AS COD_NDG,
TRC.COD_ESEG AS NUM_ESEGUITO,
CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
TRC.TIP_QUOTAZ AS FLG_QUOTATO,
TRC.COD_CAT_TIT AS COD_CATEG,
TIP_COP AS TIP_COPERTURA,
T.TIP_TASSO AS TIP_TASSO
FROM bsc.S_SLD_CNTB S
INNER JOIN
(SELECT DISTINCT COD_SOC,
TIP_PIANO_CNTB,
COD_CONTO_CNTB,
COD_RUBR_STAT ,
COD_INTER_TIT AS COD_INTER
FROM bsc.S_COLLEG_CONTO_CNTB_TIT
WHERE COD_SOC = 'ME'
) CCC
ON S.COD_SOC = CCC.COD_SOC
AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
INNER JOIN bsc.S_TIT_RICCONS TRC
ON CCC.COD_INTER = TRC.COD_INTER_TIT
AND CCC.COD_SOC = TRC.COD_SOC
AND TRC.COD_RAGGR_IAS = RTRIM('HFT ')
AND TRC.COD_RAGGR_IAS NOT IN ('GPO')
AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('DISPONIBILI')
AND TRC.DES_MOV_TIT = RTRIM('CONSEGNARE ')
AND TRC.COD_CAT_TIT = RTRIM('OBBLIGAZIONE ')
AND TRC.COD_INTER_TIT = RTRIM('334058')
AND '28-feb-2011' = TRC.DAT_RIF
LEFT JOIN bsc.S_TIT T
ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
AND T.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = T.DAT_RIF
INNER JOIN bsc.S_ANAG_SOGG AG
ON TRC.COD_NDG = AG.COD_NDG
AND AG.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = AG.DAT_RIF
WHERE S.DAT_RIF = '28-feb-2011'
AND (S.FLG_ANULL_BICO = 0
OR S.FLG_ANULL_BICO IS NULL)
AND S.COD_SOC = 'ME'
AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
AND S.TIP_PIANO_CNTB = 'IS'
AND TRC.IMP_PLUS_MINUS_VAL < 0
AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('P044C11 '))
Another time the strange result returns!!
And I've created the table TITOLI_ORI2 as create table TITOLI_ORI2 (a number); to contain the number result of the query.
Maybe you are looking for
-
Can't download the Adobe Flash Professional CC free trial
When I click on the link to download, it says: "You are running an operating system that Flash Professional no longer supports. Refer to the system requirements for a full list of supported platforms." What should I do? I can't find the system requir
-
AS2 setup -- AS2Receive Pipeline
Hi, We have AS2 set up for communicating with some parties. For receiving the AS2 messages a HTTP receive location is configured, it uses AS2Receive and AS2Send pipeline. I want to know how does AS2Receive pipeline decrypts the incoming message? How
-
I was able to use my laptop last night and shut down, then when i tried to turn it on the next day it gets stuck with the hp logo on the screen and seems like it is trying to load/open but remains stuck that way. It will do that for a few seconds the
-
Printing to PDF=lose tags
When I print to the Adobe PDF Printer I lose tages in the PDF and cannot copy/paste text. This causes the text in my Kindle books and in the Amazon.com 'Look Inside' feature for KIndle and Paperback to show all text as symbols, numbers... Publisher r
-
Trying to collect CPU's status by using Win32_processor WMI. In this, one of the processor CPU status always shows ideal (4) but logical processor usage is more than 20% when checking in Task manger. Is there any reason behind CPU status (Win32_proc