Skip to Main Content

Oracle Database Express Edition (XE)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error drop and create MVs when running script from dbms_scheduler. Not reproduceable when run from CMD

myluismMar 24 2025 — edited Mar 24 2025

Hi. This is happing when testing on Oracle XE 21c.

I have a bat script that drops and recreates some MVs. If I run this script from CMD works as intented.

I have created this Job run from SqlDeveloper:

DECLARE
v_count NUMBER;
BEGIN
-- Check if the job already exists
SELECT COUNT(*)
INTO v_count
FROM USER_SCHEDULER_JOBS
WHERE JOB_NAME = 'JOB_REFRESH_BI_VENTAS';

IF v_count = 0 THEN
-- Create the job if it doesn't exist
DBMS_SCHEDULER.create_job (
job_name => 'JOB_REFRESH_BI_VENTAS',
job_type => 'EXECUTABLE',
job_action => 'C:\\Windows\\System32\\cmd.exe',
number_of_arguments => 1,
credential_name => 'WIN_CREDENTIAL',
enabled => FALSE
);

   DBMS\_SCHEDULER.set\_job\_argument\_value(  
       job\_name        => 'JOB\_REFRESH\_BI\_VENTAS',  
       argument\_position => 1,  
       argument\_value  => '/c C:\\\\webFIGO\\\\scripts\\\\refrescar\_mv.bat'  
   );

   DBMS\_SCHEDULER.enable('JOB\_REFRESH\_BI\_VENTAS');

   DBMS\_OUTPUT.PUT\_LINE('Job created successfully.');  

ELSE
DBMS_OUTPUT.PUT_LINE('Job already exists. Running the job now.');
END IF;

-- Run the job
DBMS_SCHEDULER.RUN_JOB('JOB_REFRESH_BI_VENTAS');

END;
And output example is this:

SQL> DROP MATERIALIZED VIEW BIFIGO.MV36_VENTA_VENDEDOR_CLIENTE ;

Vista materializada borrada.

When I tried to recreate it:

create materialized view mv36_venta_vendedor_cliente BUILD IMMEDIATE REFRESH FORCE AS
2 --
3 --
4 select to_char(pej.fe_inicio_periodo,'YYYY-MM') co_periodo_ejercicio
5 ,pej.nb_periodo_ejercicio
6 ,emp.co_empresa
7 ,emp.nb_empresa
8 ,esu.co_sucursal

etc, etc

I get this error:

ERROR en línea 170:
ORA-12006: la vista materializada o el mapa de zona
"BIFIGO"."MV36_VENTA_VENDEDOR_CLIENTE" ya existe

SQL>
SQL> create index i36_vtavendcli_pej on mv36_venta_vendedor_cliente(co_periodo_ejercicio);
create index i36_vtavendcli_pej on mv36_venta_vendedor_cliente(co_periodo_ejercicio)
*
ERROR en línea 1:
ORA-00955: este nombre ya lo está utilizando otro objeto existente

SQL> create index i36_vtavendcli_cli on mv36_venta_vendedor_cliente(co_cliente);
create index i36_vtavendcli_cli on mv36_venta_vendedor_cliente(co_cliente)
*
ERROR en línea 1:
ORA-00955: este nombre ya lo está utilizando otro objeto existente

SQL> create index i36_vtavendcli_vend on mv36_venta_vendedor_cliente(co_vendedor);
create index i36_vtavendcli_vend on mv36_venta_vendedor_cliente(co_vendedor)
*
ERROR en línea 1:
ORA-00955: este nombre ya lo está utilizando otro objeto existente

SQL> create index i36_vtavendcli_clscl on mv36_venta_vendedor_cliente(co_clase_cliente);
create index i36_vtavendcli_clscl on mv36_venta_vendedor_cliente(co_clase_cliente)
*
ERROR en línea 1:
ORA-00955: este nombre ya lo está utilizando otro objeto existente

I can´t find and explanation for this. Have tried several options, but not being able to make it work from dbms_scheduler.

Is this a bug? Am I doing something wrong?

Thanks in advance!!!

Comments
Post Details
Added on Mar 24 2025
1 comment
148 views