Oracle - Bucle "for" en plsql con parámetros de entrada

 
Vista:
sin imagen de perfil

Bucle "for" en plsql con parámetros de entrada

Publicado por Abby (1 intervención) el 07/12/2016 16:26:29
Hola muy buenas comunidad!
Estoy intentando hacer un script bash para hacer un "INSERT" masivo en base de datos (plsql).
Para ello, el usuario introduce unos parámetros de entrada y, después, con un bucle "FOR" se deberían generar los inserts. El Código es tal que así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
 
#MENÚ PARA INTRODUCIR LOS DATOS NECESARIOS PARA EL INSERT
while :
do
echo " Choose an option "
echo "1. Enter a date interval to be inserted into de data base as holidays"
echo "2. Exit"
echo -n "Choose an option [1 - 2] "
read option
case $option in
1)	echo "---> Regions are: US, GB, SG, AU, JP, DE";
	echo "---> Date format: Day -> DD Month --> MMM Year --> YYYY";
        # init_day Y fin_day son los números que delimitarán las iteraciones del FOR más abajo
	echo "Introduce initial day: ";
	read init_day
	echo "Introduce a month, i.e, JAN: ";
	read month
	echo "Introduce final day: ";
	read fin_day
 
 
	if [[ $month == "APR" ]] || [[ $month == "JUN" ]] || [[ $month == "SEP" ]] || [[ $month == "NOV" ]] && [[ $fin_day == "31" ]]
		then
			echo "Invalid day, indicated month only have 30 days, please insert other final day: "
			read fin_day
	elif [[ $month == "FEB" ]] && [[ $fin_day == "31" ]] || [[ $fin_day == "30" ]]
		then
			echo "Invalid day, indicated month only have 28 days, please insert other final day: "
			read fin_day
	else
		echo "Introduce a year, i.e, 2016: "
	fi
 
	read year
	echo "introduce a regions, i.e, US: ";
	read region
 
	interval=$init_day-$month-$year
	interval2=$fin_day-$month-$year
 
	echo "Holidays will be inserted from $interval to $interval2";
 
	sqlplus $DBUSERNAME/$DBPASSWORD@$ORACLE_SID  << EOF
	SET HEADING OFF
        SET FEEDBACK OFF
        SET VERIFY OFF
        SET TRIMSPOOL ON
        SET ECHO OFF
        BEGIN
                --Este es el FOR
		FOR Lcntr IN $init_day .. $fin_day LOOP
#Este es el insert que se debería generar con cad auna de las iteraciones del bucle FOR		
INSERT INTO user_owner.table VALUES ($region, '$init_day-$month-$year'	, 'Manual',	'holiday'	, 'HOLIDAY', 	'Y', 	'Y', 	'Y', '23-NOV-16 16.23.02');
        END LOOP;
        END
exit;
EOF
	echo "Holidays between $interval and $interval2 were inserted";;
 
 
2)	echo "Ok, application will be closed, bye bye";
	exit 1;;
esac
done

Mi problema es que:
1.- No se cómo saber si realmente está populando bien el INSERT, uno por cada iteración del bucle FOR. He intentado hacer un SPOOL pero solamente me saca la primera iteración de esta forma:
1
INSERT INTO user_owner.table VALUES ( US, '01-JAN-2016' , 'Manual', 'holiday' , 'HOLIDAY', 'Y', 'Y', 'Y', '23-NOV-16 16.23.02');
La cual cosa está bien, pero no se si itera.

2.- Sí, podría hacer commit; y un select, pero antes de hacer commit; quiero saber si se está haciendo bien, si realmente se está haciendo el bucle FOR.

Muchas gracias de antemano, espero esté claro, sino, me lo dicen. Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder