domingo, 25 de marzo de 2012

Apuntes de Instrucciones


[DECLARE]

BEGIN

[EXCEPTION]

END;

declare

mensaje1 varchar2(5):='hola'; // VAriables 
mensaje2 varchar2(5):='mundo';

begin

DBMS_OUTPUT.PUT_LINE(mensaje1||' '||mensaje2); // se imprime Variable

end

************************************************
create table T1(e integer, f integer)
begin
insert into T1 value(1,3);
insertinto T1 value(2,4);
end

declare

a number;
b number;
begin

select ,f INTO a,b
from T1
where e>1;
insert into T1 values(b,a);

end


INSTRUCCION IF

declare
ainteger; //declaramos variable

begin

select COUNT(*) INTO a //contamos
from T1;

if a>1 then//decimos que si hay mas de uno

   DBMS_OUTPUT.PUT_LINE('HAY MAS DE UN REGISTRO');// imprimos
else
  DBMS_OUTPUT.PUT_LINE('HAY MENOS DE UN REGISTRO');

endif;

end



declare
 a integer; --declaramos variable
begin
 select COUNT(*) INTO a      -- contamos
from T1; -- seleccionamos de la tabla 1

if a>1 then
   DBMS_OUTPUT.PUT_LINE('HAY MAS DE UN REGISTRO');
elseif a=1 then
  DBMS_OUTPUT.PUT_LINE('HAY MENOS DE UN REGISTRO');
end if;

end


**************************************************************



declare 
       a number; // declaramos variables
b number;
begin 
 select e,f into a,b from T1 where e>1; 
IF b=1 then
insert into T1 values(b,a);
else
insert into T1 values(b+10, a+10);
end if;
end;

*************************************************************************
begin
for contador in reverse 1..100
loop 
DBMS_OUTPUT.PUT_LINE('hola mundo ' || contador);
end loop;
end

begin
for contador in 1..100
loop 
DBMS_OUTPUT.PUT_LINE('hola mundo ' || contador);
end loop;
end


DECLARE     
contador integer := 1; 
begin
 while contador <=30
 loop
 DBMS_OUTPUT.PUT_LINE('hola mundo ' || contador);
 contador := contador + 1;
 end loop;
 end;

*********************************************************************************
select upper('hola') from dual // pasa las letras a tamaño grande (UPPER).

select lower('hola') from dual // pasa las letras a tamaño pequeño (LOWER)

********************************************************************

select
to_char(to_date('05-dic-1988','dd-mon-yyyy'),'day') 
from dual; --dia del cumpleaños




***********************************************************************

select
to_char(to_date('05-dic-1988','dd-mon-yyyy'),'day') as "fecha de nac"
from dual;                                                                //AS FECHA ES DARLE NOMBRE A LA TABLA



************************************************************************+

select
to_char(sysdate, 'day') --da la fecha
from dual;

to_date('dd - mm -aa', 'dd-mm-yyyy')

--Activar usuario HR PARA TRABAJAR CON LA TABLA EMPLOYEES

select count(*)from employees -- contar cantidad de usuarios

desc employees -- estructura de la tabla

*******************************************


select user from dual -- muestra el usuario.


select to_char(77,'0099')
from dual;





declare

monto1 integer :=77;
monto2 integer:=777;
monto3 integer:=7777;
begin
 dbms_output.put_line('El monto 1 es: '|| to_char(monto1,'0099'));
 dbms_output.put_line('El monto 2 es: '|| to_char(monto2,'0099'));
 dbms_output.put_line('El monto 3 es: '|| to_char(monto3,'0099'));
end

select initcap('leonardo') from dual; --Resultado:  Leonardo


select to_date('12/10/2007','mm/dd/yyyy') from dual; 10/12/07
select to_date('31/10/2007','dd/mm/yyyy') from dual; 31-10-2007

select ascii('@') from dual; -- resultado 64

select instr('hoy voy al estadio','oy')from dual;

select length('fuck') from dual; --cuenta la cantidad de caracteres

select last_day(sysdate) from dual;--muiestra el ultimo dia del mes

select to_char(sysdate,'day') from dual;--muestra que dia es hoy Ejemplo: miercoles

select to_char(add_months(sysdate,6),'day') from dual; -- el dia en 6 meses mas Viernes

select add_months(sysdate,6) from dual;  28/09/12

select round(months_between('21/12/2012', sysdate),2)from dual;--cuanta cuantos mese hay entre la fecha actual y la definida en el codigo

select round(to_date('21/12/2012')- sysdate,1) from dual -- resta la fecha actual y la definida y da resultado la cantidad de dias entre los dos

select next_day(sysdate,'miércoles') from dual; -- muestra que fechas va a ser el proximo miercoles

select chr(64) from dual; -- muestra que caracter es en la tabla ascii

select concat(concat('hola','mundo'),'hola3')from dual-- concatena

select lpad('hola',6,'*') from dual--rellena con asteriscos los espacios vacios

select rpad('hola',5,'*') from dual -- rellena con asteriscos los espacion vacios al lado derecho

select rtrim('hola     aaa','a') from dual -- limpia espacios vacios

No hay comentarios:

Publicar un comentario