INDRA - Introduccion a PL/SQL Practica1 - Variables – Tipos de Datos Eercicio 1 ! "arcar la respuesta correcta
Ejemplo #1:
set serveroutput on; on size 1000000; declare mi_var varchar(20):='hola mundo'; e!in dms_output"put_line(mi_var); ss"dms_output"put_line('$in del pro!rama'); end; % a)
&evuelve
hola mundo $in del pro!rama ) &evuelve error de compilacin Eercicio # ! "arcar la respuesta correcta
Ejemplo #2 E E*+E*,-.- ,/ &E*E +_/-31 /-34E*(562):=10"2; +_/-32 /-34E*(562):=20"1; 4E78/ &43_,-.-".-_8/E(' -3 E: '99,_*(+_/-31+_/-32)); E/&; % &evuelve a) )
-3 E: <06< /o se pueden pasar a * los /-3
c)
/o se puede inicializar en la seccion &E*E6 error de compilacion
Eercicio $ ! "arcar la respuesta correcta
E E*+E*,-.- ,/ &E*E +_$E +&4E"*EE&>?.E; 4E78/ EE *EE& 8/, +_$E $*,3 +&4E; &43_,-.-".-_8/E(' $E &E *E8,/ &E 4E &E &, $-E: '99,_*(+_$E6'&&33????')); E/&; &evuelve d) e)
$E &E *E8,/ &E 4E &E &, @ue 0<05201< Error /o se puede inicializar &4E
Eercicio% ! &'AR
rear un plAsBl Bue de@ina dos variales v_nomre_empleado_1 v_nomre_empleado_2 con el nomre CDuan C " a primera de tipo char de la se!unda de tipo varchar de " 8mprimir amos valores concatenando un FGH al principio " 1) ,cupan lo mismo I J 8mpr imir usando len!th(variale) 2) si!nar a v_nomre_empleado_1 el nomre CDuan manuel 7arciaK <) si!nar a v_nomre_empleado_1 el valor CD7K 5) si!nar a v_nomre_empleado_2 el valor CD7K
Eercicio( ! DATE )beti*o+ poder asi,nar *er ue tipos de datos se pueden su.ar entre si0 Dates nu.bers0
rir el sBlAdeveloper armar un plAsBl Bue car!ue una @echa ssdate en una variale6 arme la @echa de @in de mes en otra variale6 reste las @echas calcule cuantos dLas @altan para @in de mes" 8mprimir la cantidad de dLas Bue @altan para @in de mes" *e@erencias 1) http:%%docs"oracle"com%cd%41M<0_01%appdev"102%1521%datatpes"htm#i5NM0O To fnd just the time portion o a DATE variable, subtract the date portion:date_variable - TRUNC( date_variable).
•
/ota:
@ormatear la @echa
EPE-E 833E&8E 'E* E8,/ E /_&E_$,*3 = QddA3,/AQ '; *e@erencia @uncin : ,_*(date1 R6@mtS);
Fmt: .arameter
ETplanation
?E*
?ear6spelled out alphaeticall
????
5Adi!itear
??? ?? ?
ast <6 26 or 1 di!it(s) o@ ear"
8?? 8? 8
ast <6 26 or 1 di!it(s) o@ 8, ear"
8???
5Adi!it ear ased on the 8, standard
****
ccepts a 2Adi!it ear and returns a 5Adi!it ear" value etUeen 0A5M Uill return a 20TT ear" value etUeen N0AMM Uill return a 1MTT ear"
V
Vuartero@ear(1626<65;D/A3*=1)"
33
3onth(01A12;D/=01)"
3,/
reviatednameo@themonth"
3,/
he name o@ month6 padded Uith lanWs to len!th o@ M characters"
*3
*omannumeralmonth(8AP88;D/=8)"
XX
he UeeW o@ the ear (1AN<) Uhere UeeW 1 starts on the @irst da o@ the ear and continues to the seventh da o@ the ear"
X
he UeeW o@ the month (1AN) Uhere UeeW 1 starts on the @irst da o@ the month and ends on the seventh"
8X
he UeeW o@ ear (1AN2 or 1AN<) ased on the 8, standard"
&
&a o@ the UeeW (1AO)" unda is da 1 Uhen nls_territor is set to '3E*8' ut di@@ers i@ another nls_territor is set (i"e" '-/8E& Y8/7&,3' or '7E*3/?' A in these cases 3onda is 1"
&?
/ameo@theda"
&&
hedao@month(1A<1)"
&&&
hedao@ear(1A<)"
&? D
reviated name o@ the da" (3on6 ue6 Xed6 etc) Dulian da; the numer o@ das since Danuar 16 5O12 4"
ouro@da(1A12)"
12
ouro@da(1A12)"
25
ouro@da(0A2<)"
38
3inute(0ANM)"
econd(0ANM)"
/umer o@ seconds past midni!ht (0AZ
$$
$ractional seconds" -se a value @rom 1 to M a@ter $$ to indicate the numer o@ di!its in the @ractional seconds" $or eTample6 '$$N'"
36 "3"6 .36 or ."3" 3eridian indicator & or "& & indicator 4or4""
4indicator
[&
&ali!ht savin!s identi@ier" $or eTample6 '.'
[
imezonehour"
[3
imezoneminute"
[*
imezonere!ion"
Ejplo: Este ejemplo pasa a date 6 @ormatea lue!o pasa a char con otro @ormato select ,_* (,_&E('02MO'6'33%??')6 '??%33') @rom dual Eercicio ! INSTR - S23STR )beti*o+ introducir las 4unciones de uso de cadenas
rear un varchar2 con la si!uiente cadena de caracteres : CEjemplo de uso de cadenas en pl%sBlK <"a) *ealizar un pl%sBl Bue devuelva los primeros 10 caracteres" /,: controlar el caso de Bue el strin! sea nulo" ( de@inir la variale como /, /- ) <") *ealizar un pl%sBl Bue solicite la cantidad de ultimos caracteres de la cadena" /o controlar el caso de Bue la cantidad sea maor al tama\o de la cadena" <"c) *ealizar un pl%sBl Bue devuelva de la cadena enunciada Fcadenas en pl%sBlH" Es decir usBue con instr la se!unda ocurrencia de la palara FdeH lue!o desde ahL hasta el @inal de la cadena con Substr *e@erencias: INSTR http:%%UUU"techonthenet"com%oracle%@unctions%instr"php
8/*( strin!6 sustrin! R6 start_position R6 nth_appearance S S ) strin!
he strin! to search" string can e *6 +**26 /*6 /+**26 ,46 or /,4" sustrin! he sustrin! to search @or in string" substring can e *6 +**26 /*6 /+**26 ,46 or /,4" start_position ,ptional" he position in string Uhere the search Uill start" 8@ omitted6 it de@aults to 1" he @irst position in the strin! is 1" 8@ the start_position is ne!ative6 the 8/* @unction counts acW start_position numer o@ characters @rom the end o@ stringand then searches toUards the e!innin! o@ string" nth_appearance ,ptional" he nth appearance o@ substring" 8@ omitted6 it de@aults to 1"
S23STR
-4*( strin!6 start_position R6 len!th S )
.arameters or r!uments strin! he source strin!" start_position he startin! position @or eTtraction" he @irst position in the strin! is alUas 1" len!th ,ptional" 8t is the numer o@ characters to eTtract" 8@ this parameter is omitted6 the -4* @unction Uill return the entire strin!" /ote: •
8@ start_position is 06 then the -4* @unction treats start_position as 1 (ie: the @irst position in
•
the strin!)" 8@ start_position is a positive numer6 then the -4* @unction starts @rom the e!innin! o@ the
•
strin!" 8@ start_position is a ne!ative numer6 then the -4* @unction starts @rom the end o@ the strin!
•
and counts acWUards" 8@ len!th is a ne!ative numer6 then the -4* @unction Uill return a /- value"
Eercicio 5 ! Precedencia de operadores
*ealizar un pl%sBl Bue tome la @echa del dia le sume un se!undo" .ara ello tomar la @echa del dia una variale en otra variale asi!narle el valor anterior dividido por 25G0G0" +er@icar la predcedencia de la division con la multiplicacin la asi!nacin" ( ener presente) Table 2–1 Order of Operations )perator )peration ** exponentiation +, - identity, negation *, / multiplication, division +, -, || addition, subtraction, concatenation =, <, >, <=, >=, <>, !=, ~=, ^=, IS NULL, LIKE, BETWEEN, IN
comparison NOT logical negation
AND conjunction OR inclusion
*e@: http:%%UUU"oracle"com%technetUorW%issueAarchive%2012%12Ajan%o12plsBlA150ZN1"html
Eercicio 6! &lausulas adicionales0 - RAN7E
E si!uiente ejemplo de@ine un ran!o de valores6 ejecuta I &E*E di!ito ._8/E7E* */7E 0""M; dos_di!itos ._8/E7E* */7E 10""MM; menos_de_100 ._8/E7E* */7E 0""MM; 4E78/ di!ito := 5; dos_di!itos :=
Eercicio 8! N2"3ER-T)9&'AR // T)9&'AR N2"3ER - &on*ersiones i.plicitas
El dL!ito recuperado en el ejercicio O6 in!resarlo en una variale +**" Es posile I +er conversiones implLcitas en http:%%docs"oracle"com%cd%41M<0_01%appdev"102%1521%datatpes"htm#i52NZ0
Eercicio 1:! &on*ersion de SI"PLE9INTE7ER a 3INAR;
DECLARE a SIMPLE_INTEGER := 1; b PLS_INTEGER := NULL; BEGIN a := b; END; / Eercicio 11! Esto es correcto < &E*E acct_id 8/E7E*(5) /, /- ; e!in &43_,-.-".-_8/E( acct_id ) ; end; %