RE: Unix script help

  • From: "Guang Mei" <gmei@xxxxxxxxxx>
  • To: <oracle-l@xxxxxxxxxxxxx>
  • Date: Tue, 2 Mar 2004 15:17:59 -0500

You could use pl/sql, using execute immediate 'sql_statement' and use some
variable to row count. Something like:

declare
  cnt   number;
begin

execute immediate
'create table tangram.sw_save nologging
tablespace tangram
as select * from tangram.sw_use_t_h where sut_closed_dt > = (sysdate-10)';

select count(*) into cnt from  tangram.sw_save;

 if cnt > some_number then
   execute immediate 'truncate table tangram.sw_use_t_h';
 end if;

insert into tangram.sw_use_t_h
select * from tangram.sw_save;

commit;

execute immediate 'drop table tangram.sw_save';

end;


Put this code into a file, say test1.sql, then call this script from cron.

HTH.

Guang


-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx
[mailto:oracle-l-bounce@xxxxxxxxxxxxx]On Behalf Of M Rafiq
Sent: Tuesday, March 02, 2004 3:07 PM
To: oracle-l@xxxxxxxxxxxxx
Subject: Unix script help


Hi

I need help for following sql script. I want to put condition before
truncate that table creation must be successful before truncate runs. The
condition may be to check count before and after creation or tracking of any
ORA/warning message but I could not make up my mind. I want to put it in
cron to run it weekly.

Is any body can help to give me some tips/script itself?

Regards
Rafiq


create table tangram.sw_save nologging
tablespace tangram
as select * from tangram.sw_use_t_h where sut_closed_dt > = (sysdate-10);

truncate table tangram.sw_use_t_h;

insert into tangram.sw_use_t_h
select * from tangram.sw_save;

commit;

drop table tangram.sw_save;

_________________________________________________________________
Frustrated with dial-up? Lightning-fast Internet access for as low as
$29.95/month. http://click.atdmt.com/AVE/go/onm00200360ave/direct/01/

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

Other related posts: