Q

Date format causing filename problem in procedure

I have a problem with the filename field in the following procedure:

 
CREATE OR REPLACE  PROCEDURE "TSAST_ODB"."SCHEDULE" 
         AS
   l_job  number;
 begin
    dbms_job.submit( l_job,
                     'run_dump_csv(JOB);',
                     trunc(sysdate)+1+2/24,
                     'trunc(sysdate)+1+2/24');
    commit;
    insert into
dump_csv_parameters(job_id,query,separator,dir,filename)
    values(l_job,'select * from billing_record where
 insert_time >= trunc(sysdate-2) and insert_time < 
trunc(sysdate-1);',',','/tmp','tas.csv');
    commit;
    TAS;
    end;
The problem is that I need the filename to be in the following format: 'YYYYMONDD.csv'. The procedure will not accept the following string:
 
(to_char((sysdate-2),'YYYYMONDD')||'.csv')
I have to call another procedure, TAS, to do this formating:
 
CREATE OR REPLACE  PROCEDURE "TSAST_ODB"."TAS" 
  as
     x VARCHAR2(100);
  Begin
  update dump_csv_parameters
  set  FILENAME=
 (to_char((sysdate-2),'YYYYMONDD')||'.csv')
  where job_id = (select max(job_id) from
 dump_csv_parameters);
  commit;
 end;
 
This procedure, however, is not giving the correct format date, as it dates the file as sysdate-3 instead of sysdate-2. I would be most grateful for any suggestions.

If the INSERT statement is having a problem with the TO_CHAR function, then why not perform this before the INSERT statement? I'd declare a VARCHAR2 variable (we'll call it 'filenm') and use that. Something like the following should work:

filnm:=TO_CHAR(sysdate-2,'YYYYMONDD');
INSERT INTO dump_csv_parameters
(job_id,query,separator,dir,filename)
VALUES(l_job,'select * from billing_record where
insert_time >= trunc(sysdate-2) and insert_time <
trunc(sysdate-1);',',','/tmp',filenm);
COMMIT;
Notice how I used a variable in the INSERT statement instead.

For More Information


This was last published in March 2003

Dig Deeper on Oracle database design and architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close