Пример использования пакета BTRV_UTL
-- This sample displays
all accounts from tutorial database
-- All necessary files are uncluded in btrvutl.zip
set serveroutput on size 64000
declare
files_path varchar2(100):='/opt/PVSWpsql/btrutil/samples/data/';
filename varchar2(20);
account varchar2(141):=rpad(' ',141);
employee varchar2(141):=rpad(' ',141);
customer varchar2(141):=rpad(' ',141);
status pls_integer:=0;
counter pls_integer:=0;
str varchar2(200);
begin
filename:='account.btr';
status:=btrv_utl.Open(account,files_path||filename);
if status=0 then
dbms_output.put_line('Open
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Open
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
filename:='employee.btr';
status:=btrv_utl.Open(employee,files_path||filename);
if status=0 then
dbms_output.put_line('Open
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Open
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
filename:='customer.btr';
status:=btrv_utl.Open(customer,files_path||filename);
if status=0 then
dbms_output.put_line('Open
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Open
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
dbms_output.put_line('Id
'||chr(9)||rpad('Account',20)||chr(9)||rpad('DateOpen',10)||chr(9)||
rpad('Balance',14)||chr(9)||'Activity'||chr(9)||rpad('Open by',25)||chr(9)||'Customer');
dbms_output.put_line(rpad('-',150,'-'));
counter:=0;
btrv_utl.StepFirst(account);
while btrv_utl.GetStatus=0 loop
btrv_utl.AddKeyShort(employee,btrv_utl.GetShort(account,36));
btrv_utl.GetEq(employee);
if btrv_utl.GetStatus!=0 then
dbms_output.put_line('Error: code='||to_char(btrv_utl.GetStatus)||'
'||btrv_utl.GetMessage);
dbms_output.put_line('Can not find id='||to_char(btrv_utl.GetShort(account,36))||
' in employee.btr');
dbms_output.put_line('Extracting aborted!');
exit;
end if;
btrv_utl.AddKeyLong(customer,btrv_utl.GetLong(account,38));
btrv_utl.GetEq(customer);
if btrv_utl.GetStatus!=0 then
dbms_output.put_line('Error: code='||to_char(btrv_utl.GetStatus)||' '||
btrv_utl.GetMessage);
dbms_output.put_line('Can not find id='||to_char(btrv_utl.GetShort(account,38))||
' in customer.btr');
dbms_output.put_line('Extracting aborted!');
exit;
end if;
if
btrv_utl.GetString(account,42,1)=chr(1) then
str:=' ';
else
str:='closed ';
end if;
dbms_output.put_line(
to_char(btrv_utl.GetLong(account,0),'9999')||chr(9)||
btrv_utl.GetString(account,4,20)||chr(9)||
to_char(btrv_utl.GetDate(account,24),'dd/mm/yyyy')||chr(9)||
to_char(btrv_utl.GetDouble(account,28),'999,999,990.00')||chr(9)||
str||chr(9)||
rpad(btrv_utl.GetString(employee,2,40),25)||chr(9)||
btrv_utl.GetString(customer,4,40) );
counter:=counter+1;
btrv_utl.StepNext(account);
end loop;
dbms_output.put_line(rpad('-',150,'-'));
dbms_output.put_line('The file contains
'||to_char(counter)||' records');
filename:='account.btr';
status:=btrv_utl.Close(account);
if status=0 then
dbms_output.put_line('Close
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Close
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
filename:='employee.btr';
status:=btrv_utl.Close(employee);
if status=0 then
dbms_output.put_line('Close
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Close
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
filename:='customer.btr';
status:=btrv_utl.Close(customer);
if status=0 then
dbms_output.put_line('Close
'||filename||chr(9)||'[OK]');
else
dbms_output.put_line('Close
'||filename||chr(9)||'[failed] code='||to_char(status));
return;
end if;
end; /