RE: Unix script help

  • From: "Jacques Kilchoer" <Jacques.Kilchoer@xxxxxxxxx>
  • To: <oracle-l@xxxxxxxxxxxxx>
  • Date: Tue, 2 Mar 2004 12:20:01 -0800

How about putting a PL/SQL block between the create and the truncate? something 
like this

whenever sqlerror then exit sql.sqlcode

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

declare
   n pls_integer ;
begin
   select count (*) into n
    from tangram.sw_save where rownum < 2 ;
   if n = 0
   then
      raise_application_error (-20010, 'no rows copied') ;
   end if ;
end ;
/

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;

> -----Original Message-----
> M Rafiq
>
> 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?
>
> 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;


Other related posts: