set heading off
set define on
whenever sqlerror exit
prompt
prompt Logging on as Oracle Portal owner
prompt
accept connstr prompt 'Enter connection string (e.g. portal30/portal30@orcl) : '
prompt
connect &connstr
prompt
prompt B E G I N   O R A C L E   R E P O R T S   I N S T A L L
prompt
prompt Log file in rwwwvlog.txt
prompt
select '...start: '||to_char(sysdate,'Day DD Month, YYYY HH24:MI:SS') from dual;
whenever sqlerror exit
var l_verstr varchar2(10);
var l_ver    number;
declare
  stmt        varchar2(2000);
  stmt_cursor number;
  dummy number;
begin
  stmt := 'begin :verstr :=wwctx_api.get_product_version; end;';
  stmt_cursor := dbms_sql.open_cursor;
  dbms_sql.parse(stmt_cursor, stmt, dbms_sql.v7);
  dbms_sql.bind_variable(stmt_cursor, ':verstr', :l_verstr, 10);
  dummy := dbms_sql.execute(stmt_cursor);
  dbms_sql.variable_value(stmt_cursor, ':verstr', :l_verstr);
  dbms_sql.close_cursor(stmt_cursor);
exception
  when others then
  begin
    stmt := 'begin :verstr := wwv_standard_util.get_version; end;';
    stmt_cursor := dbms_sql.open_cursor;
    dbms_sql.parse(stmt_cursor, stmt, dbms_sql.v7);
    dbms_sql.bind_variable(stmt_cursor, ':verstr', :l_verstr, 10);
    dummy := dbms_sql.execute(stmt_cursor);
    dbms_sql.variable_value(stmt_cursor, ':verstr', :l_verstr);
    dbms_sql.close_cursor(stmt_cursor);
  end;
end;
/
execute :l_ver := substr(:l_verstr, 1, instr(:l_verstr, '.') - 1);
set define off
spool rwwwvtm1.sql
select decode(:l_ver, 1, 'propmt Need to upgrade WebDB to 2.1 or up before install Oracle Reports Packages', 
                      2, '@2.2/rwwwvvck.sql ' || user, 
                      3, '@3.0/rwwwvfpc30.sql ' || user) from dual;
spool off
set define on
@rwwwvtm1.sql
select '...end: '||to_char(sysdate,'Day DD Month, YYYY HH24:MI:SS') from dual;
prompt
prompt D O N E   I N S T A L L
prompt
quit
