Anda di halaman 1dari 4

SQL-> lenguajes DML (lenguaje de manipulacion de datos){Select, insert, update, delete} ,DDL(lenguaje de definicin de datos) {drop, truncate, create},

DCL (lenguaje de control de datos) {grant, revoque,commit, rollback} COMANDOS //desbloquear un usuario Alter user hr account unlock //cambiar clave de un usuario Alter user hr identified by calse

//crea usuarios create user prueba identified by ramt //da permisos de lectura y escritura grant connect, resource to prueba //mira todas las tablas select * from tab //describe una tabla desc nombre_tabla

Select: pide informacin de los datos que estn almacenados en la base de datos, ej: Select nombre_columna from nombre_tabla Select *from nombre_tabla //es para mostrar toda la informacin de las tablas //seleccionar varias columnas de una tabla Select first_name, last_name, salary from employees //para cambiar dar un nombre alternative a una columna Select first_name PRIMER NOMBRE, last_name, APELLIDO, salary Salario from employees //ordena segun se le indica en modo decendente Order by last_name, salary desc //para aumentar restar multiplicar dividir valores o alguna otra cosa que se te ocurra XD Select first_name, last_name, salary+100 from employees //concatenacion de cadenas de texto con datos de la base y ocultar los commandos select 'El empleado '||first_name||' '|| last_name||' tiene un sueldo de '||salary descripcion from employees //el comando distinct enumera una sola vez un tipo de dato select distinct department_id "DEPARTAMENTOS" from employees //PARA ENLISTAR INFORMACION DE LA BASE DE DATOS FILTRADO DE UNA COLUMNA DE LA BASE DE DATOS select last_name APELLIDO, first_name NOMBRE, department_id "ID DEL DEPARTAMENTO" from employees where department_id = 10 NOTA: PARA FILTRAR POR MEDIO DE UNA CADENA TOCA PONER DE LA MISMA PUTA FORMA EN QUE EL DESGRACIADO A ESCRITO GRACIAS, = LIKE

COMPARADORES >,<,>=,<=,<>, IN, LIKE, BETWEEN NOTA: LIKE SIRVE PARA BUSCAR CADENAS , % SIRVE PARA ESPECIFICAR QUE LO DEMAS NO IMPORTA EJ: where last_name like 'A%' EJERCICIOS EN CLASE 1) LISTAR TODOS LOS EMPLEADOS QUE TENGAN EL SALARIO MAYOR A 2000 Y PERTENESCAN AL DEPARTAMENTO 90 Select first_name NOMBRE, last_name APELLIDO, department_id DEPARTAMENTO, salary Salario from employees where salary >= 2000 and department_id= 90 2) LISTAR TODOS LOS EMPLEADOS QUE PERTENECEN AL DEPARTAMENTO 10 30 O 90 Select first_name NOMBRE, last_name APELLIDO, department_id DEPARTAMENTO from employees where department_id in(10,30,90) 3) LISTAR TODOS LOS EMPLEADOS QUE TIENEN SALARIOS ENTRE 2000 Y 9000 Select first_name NOMBRE, last_name APELLIDO, salary SALARIO from employees where salary between 2000 AND 9000 4) ENLISTAR TODOS LOS EMPLEADOS CUYOS APELLIDOS EMPIESAN CON LA LETRA A Select first_name NOMBRE, last_name APELLIDO from employees where last_name like 'A%' 5) LISTAR TODOS LOS EMPLEADOS QUE ENTRARON EN EL AO 95 Select first_name NOMBRE, last_name APELLIDO, hire_date from employees where hire_date like '%95' 6) LISTAR TODOS LOS EMPLEADOS QUE NO TIENEN JEFES Select first_name NOMBRE, last_name APELLIDO, manager_id JEFE from employees where manager_id is null 7) LISTAR TODOS LOS EMPLEADOS QUE SUS PUESTOS DE TRABAJO NO SON PROG CLEARK REP Select first_name NOMBRE, last_name APELLIDO, job_id "PUESTO DE TRABAJO" from employees where job_id not like '%PROG' and job_id not like '%CLERK' and job_id not like '%REP' FUNCTION CONCAT (,) La function concatenar varios datos select concat('hola mi nombre es ',first_name) INFO from employees FUNCION SUBSTR(CADENA,inicio,fin) Indica que de una cadena despliegue las letras indicadas por inicio y fin select first_name NOMBRE, last_name APELLIDO, concat(substr(first_name,1,1),substr(last_name,1,1)) INICIALES from employees Length(cadena) Devuelve el numero de letras que tiene la cadena select first_name NOMBRE, last_name APELLIDO, length(first_name) "NUMERO DE LETRAS NOMBRE", length(LAST_name) "NUMERO DE LETRAS APELLIDO" from employees

ROUND(VALOR NUMERICO, N) Sirve para redondear valores a un n nmero de decimales Trunc(valor numrico, n) Sirve para seleccionar la cantidad de valores en decimales seleccionados Mod(valor1,valor2) Residuo? Sysdate Datos de la fecha del sistema select sysdate from dual

select first_name NOMBRE, last_name APELLIDO, department_id DEPARTAMENTO, hire_date "FECHA DE ENTRADA", trunc((sysdate-hire_date)/360,2) "TIEMPO DE TRABAJO" from employees WHERE department_id = 90 MONTHS_BETWEEN(FECHA1,FECHA2) Calcula la diferencia de meses que hay entre las dos fechas ADD_MONTHS(FECHA,N) Aade el numero de meses a la fecha seleccionada INSERTAR DATOS EN UNA TABLA Para insertar se debe seguir la siguiente secuencia Insert into nombre_tabla values(val1,,valn) Ej: Insert into tab employees Values(25,unidad,01/10/2012) ACTUALIZACION DE DATOS Update table set colx = new_val, coly=new_vol2 Where condicion Ej: Actualizar update employees set salary = salary + 30 update employees set job_id = 'SA_MAN' where job_id like 'IT_PROG' GRABADO DE DATOS commit; nota: una vez ejecutado el el commit no se puede deshacer los cambios realizados nota2: el Oracle trabaja con autocommit desmarcar esa opcin para trabajar con actualizaciones ELIMINACION DE LOS CAMBIOS REALIZADOS HASTA UN ANTERIOR COMMIT Rollback;

ELIMINACIN DE DATOS Delete from tabla Where condicin Nota: se puede deshacer con el rollback ELIMINACIN TOTAL DE LOS DATOS Y TABLAS Drop tabla Nota: no se puede deshacer con el rollback

Anda mungkin juga menyukai