Minuta clase Sabado 10-12-2011

0 views
Skip to first unread message

HECTOR CALLEJAS

unread,
Dec 10, 2011, 11:10:18 AM12/10/11
to Fundamentos de Oracle
Minuta realizada por Hector Callejas

10 diciembre 2011

se comienza a ver PL/Sql

dado que que no se publicaron tarea en el grupo a traves del blog se
reitera que este debe ser a travez de este medio.

ESTRUCTURA GENERAL DE UN BLOQUE EN PL/SQL


- Definicion de variables y constantes

- se realiza un pequeño programa que esta en ppt subida al portal


drop table T1; // Se elimina la tabla en caso que exista, si no existe
da un error, pero no importa
CREATE TABLE T1(
e INTEGER,
f INTEGER
);
Begin
DELETE FROM T1;
INSERT INTO T1 VALUES(1, 3);
INSERT INTO T1 VALUES(2, 4);
End

select * from t1
/* Lo de arriba es SQL; debajo es el programa PL/SQL */
DECLARE
a NUMBER;
b NUMBER;
BEGIN
SELECT e,f INTO a,b
FROM T1
WHERE e>1;// Este select asigna el atributo e->a y f->b, de todos
aquellos registros cuyo atributo e > 1
INSERT INTO T1 VALUES(b,a);

nota importante:
pagina 7 ppt los comentarios son -- para una linea y /* para varias
lineas (verificar en programa)

- este programa es un cursor implicito y como restriccion el resultado
entrega solo una tupla

- se explica instrucciones de control de pl/sql

- If then
else
end if

para imprimir en pantalla

begin
DBMS_OUTPUT.PUT_LINE('Hola Mundo');
end;

ejemplo If

declare
precio integer:=10;
begin
if precio>=15 then
DBMS_OUTPUT.PUT_LINE('El precio es : ' || Precio)
end if;
end;

SE APRENDE

el uso del IF,

Concatenar '||'

y dbms_output

otro ejemplo

declare
precio integer:=15;
texto varchar2(5);
begin
if precio>=10 then
texto:='mayor';
else
texto:='menor';
end if;
DBMS_OUTPUT.PUT_LINE('El precio es : ' || texto || ' y es ' ||
precio);
end;

INSTRUCCION LOOP

LOPP

{.STATEMENTS.}
END LOOP

ejemplo

declare
I integer;
begin
I:=1;
LOOP
DBMS_OUTPUT.PUT_LINE('Hola Mundo ' || I);
I:=I+1;
exit when I >10;
end loop;
end;


Reply all
Reply to author
Forward
0 new messages