SlideShare una empresa de Scribd logo
1 de 16
COMANDOS
DE SQL*Plus
 ORACLE
CAP I             El Método / Enfoque Relacional

        Filas                            Columnas


   Tabla PERSONAL

   PERS_COD   PERS_DATOS           PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD
   --------   -------------------- --------- ------------------- --------- --------
       101    JORGE ITURRALDE                          05-JAN-00      1500     00
       102    CAROLINA JOFRE             101           21-JAN-00      1000     00
       155    SEBASTIAN CAPQUIQUE        153           30-JAN-00               05
       104    GERMAN ARAUJO              101           20-FEB-00               00
       159    OMAR FIGUEROA              150           27-FEB-00               05
       109    ROBERTO GUZMAN             107           25-MAY-00               01
       157    FRANCISCO MAYTA            156           28-MAY-00               05
       111    JAVIER NERI                107           28-JUN-00       150     01
       152    ALBERTO ARANCIBIA          150           25-AUG-00               05
       154    RIGOBERTO CHUQUIMIA        153           28-SEP-00       500     05
       108    TERESA MOLLINEDO           107           25-NOV-00       200     01
       105    YOVANA FERNADEZ            102           26-JAN-01       500     00
       153    DANILO FERRUFINO           150           27-JAN-01               05
       156    BERNARDO GUZMAN            150           27-JAN-01               05
       150    ALEJANDRO TORRES           102           21-MAR-01      1000     05
Tabla DEPARTAMENTO

El Método                        REGIONAL DEPA_COD DEPA_NOMBRE
                                 -------- -------- ------------------------

Relacional                            00       00 GERENCIA GENERAL
                                      01       00 GERENCIA REGIONAL
                                      01       01 CONTABILIDAD
                                      01       02 RECURSOS HUMANOS
                                      01       03 TECNOLOGIA
                                      01       04 VENTAS
                                      01       05 ALMACENES
                                      01       06 COMPRAS
                                      01       07 TRANSPORTE
                                      02       00 GERENCIA REGIONAL

  Tabla PERSONAL

  PERS_COD   PERS_DATOS           PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD
  --------   -------------------- --------- ------------------- --------- --------
      101    JORGE ITURRALDE                          05-JAN-00      1500     00
      102    CAROLINA JOFRE             101           21-JAN-00      1000     00
      155    SEBASTIAN CAPQUIQUE        153           30-JAN-00               05
      104    GERMAN ARAUJO              101           20-FEB-00               00
      159    OMAR FIGUEROA              150           27-FEB-00               05
      109    ROBERTO GUZMAN             107           25-MAY-00               01
      157    FRANCISCO MAYTA            156           28-MAY-00               05
      111    JAVIER NERI                107           28-JUN-00       150     01
      152    ALBERTO ARANCIBIA          150           25-AUG-00               05
      154    RIGOBERTO CHUQUIMIA        153           28-SEP-00       500     05
      108    TERESA MOLLINEDO           107           25-NOV-00       200     01
      105    YOVANA FERNADEZ            102           26-JAN-01       500     00
      153    DANILO FERRUFINO           150           27-JAN-01               05
      156    BERNARDO GUZMAN            150           27-JAN-01               05
      150    ALEJANDRO TORRES           102           21-MAR-01      1000     05
SQL*Plus es una herramienta diseñada por/para ORACLE, la cual
extiende las capacidades del SQL ANSI estándard.
                                                  Servidor




                                                                                   PERS_COD   PERS_DATOS
                                                                                   --------   --------------------
                                                                                       101    JORGE ITURRALDE
                                                                                       102    CAROLINA JOFRE
                                                                                       155    SEBASTIAN CAPQUIQUE
                                                                                       104    GERMAN ARAUJO
                                                                                       159    OMAR FIGUEROA
                                                                                       109    ROBERTO GUZMAN
                                                                                       157    FRANCISCO MAYTA

                         SQL                                                           111
                                                                                       152
                                                                                              JAVIER NERI
                                                                                              ALBERTO ARANCIBIA




 SQL versus SQL*Plus                         SQL * Plus
SQL        Un lenguaje consistente de comandos para almacenar, recuperar, mantener y regular el acceso a la base de
           datos.

SQL*Plus   Una aplicación que reorganiza y executa comandos SQL que por Ej. permite personalizar reportes,
           proveyendo de ayuda, facilidades de edición y mantenimiento a variables del sistema
Manipulación y recuperación de datos, y creación y modificación
de las estructuras de datos con comandos SQL

 Funciones de los                 Comandos SQL
 Comandos SQL
                              •    ALTER     •    DROP       •   REVOKE
  •   Consultas               •    AUDIT     •    GRANT      •   ROLLBACK
  •   Manipulation de Datos   •    COMMENT   •    INSERT     •   SELECT
                              •    COMMIT    •    LOCK       •   UPDATE
  •   Definition de Datos
                              •    CREATE    •    NO AUDIT   •   VALIDATE
  •   Control de Datos
                              •    DELETE    •    RENAME

      SQL Buffer


               Comando
               SQL                                SQL
                                                 Buffer
Se escriben comandos SQL*Plus para
               manipular comandos SQL
Funciones de los Comandos
                                                 Comandos SQL* Plus
SQL*Plus
                                             •    $         •   COPY         •   QUIT
• Ingresar, editar, recuperar y correr
                                             •    /         •   DESCRIBE     •   REMARK
  comandos SQL.                              •    ACCEPT    •   DISCONNECT   •   RUN
• Formatear, realizar calculos en el alma-   •    APPEND    •   EDIT         •   SAVE
  cenamiento, e imprimir resultados de       •    BREAK     •   EXIT         •   SET
                                             •    BTITLE    •   GET          •   SHOW
  consultas en forma de reportes.            •    CHANGE    •   HELP         •   SPOOL
• Listar definiciones de columnas para       •    CLEAR     •   HOST         •   SQLPLUS
  cualquier tabla.                           •    COLUMN    •   INPUT        •   START
                                             •    COMPUTE   •   LIST         •   TIMING
• Accesar y copiar entre bases de datos.                                     •
                                             •    CONNECT   •   NEWPAGE          TTITLE
• Enviar mensajes y aceptar respuestas                                       •   UNDEFINE
  desde un usuario final.


                      Comandos
                      SQL*Plus                                   SQL
 SQL Buffer                                                     Buffer
INICIANDO UNA SESION SQL
El primer paso para una sesión de SQL, es ingresar a SQL*Plus
                sqlplus <ENTER>
    Ingreso
    (Log in)
                                  Enter user_name: Usuario1 <ENTER>
                                  Enter Password: ****** <ENTER>




                    SQL> exit <ENTER>
    Salida
    (Log off)
Tabla DEPARTAMENTO
SENTENCIA SELECT                                        REGIONAL DEPA_COD DEPA_NOMBRE
                                                        -------- -------- ------------------------
                                                             00       00 GERENCIA GENERAL
Seleccionar (SELECTing) información                          01       00 GERENCIA REGIONAL
                                                             01       01 CONTABILIDAD
desde una base de datos o CONSULTAR,                         01       02 RECURSOS HUMANOS
                                                             01       03 TECNOLOGIA
es una de las operaciones de Base de datos                   01       04 VENTAS
más comunes                                                  01
                                                             01
                                                                      05 ALMACENES
                                                                      06 COMPRAS
                                                             01       07 TRANSPORTE
                                                             02       00 GERENCIA REGIONAL
Items del servidor
SELEC–cionables         Tabla PERSONAL

                     PERS_COD   PERS_DATOS           PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD
• Columnas           --------   -------------------- --------- ------------------- --------- --------
• Expresiones            101
                         102
                                JORGE ITURRALDE
                                CAROLINA JOFRE             101
                                                                         05-JAN-00
                                                                         21-JAN-00
                                                                                        1500
                                                                                        1000
                                                                                                 00
                                                                                                 00
• Constantes             155
                         104
                                SEBASTIAN CAPQUIQUE
                                GERMAN ARAUJO
                                                           153
                                                           101
                                                                         30-JAN-00
                                                                         20-FEB-00
                                                                                                 05
                                                                                                 00
                         159    OMAR FIGUEROA              150           27-FEB-00               05
                         109    ROBERTO GUZMAN             107           25-MAY-00               01
Requerimientos           157    FRANCISCO MAYTA            156           28-MAY-00               05
                         111    JAVIER NERI                107           28-JUN-00       150     01
minimos de la            152    ALBERTO ARANCIBIA          150           25-AUG-00               05
                         154    RIGOBERTO CHUQUIMIA        153           28-SEP-00       500     05
sentencia SELECT         108    TERESA MOLLINEDO           107           25-NOV-00       200     01
                         105    YOVANA FERNADEZ            102           26-JAN-01       500     00
                         153    DANILO FERRUFINO           150           27-JAN-01               05
• SELECT                 156
                         150
                                BERNARDO GUZMAN
                                ALEJANDRO TORRES
                                                           150
                                                           102
                                                                         27-JAN-01
                                                                         21-MAR-01      1000
                                                                                                 05
                                                                                                 05
• FROM
Servidor

SELECCION DE
COLUMNAS

                PERS_COD   PERS_DATOS          PERS_FECHA_CONTRAT DEPA_COD
                --------   ------------------- ------------------ --------
                    101    JORGE ITURRALDE             05-JAN-00        00
                    102    CAROLINA JOFRE              21-JAN-00        00
                    155    SEBASTIAN CAPQUIQUE         30-JAN-00        05
                    104    GERMAN ARAUJO               20-FEB-00        00
                    159    OMAR FIGUEROA               27-FEB-00        05
                    109    ROBERTO GUZMAN              25-MAY-00        01

        SQL         157
                    111
                    152
                           FRANCISCO MAYTA
                           JAVIER NERI
                           ALBERTO ARANCIBIA
                                                       28-MAY-00
                                                       28-JUN-00
                                                       25-AUG-00
                                                                        05
                                                                        01
                                                                        05
                    154    RIGOBERTO CHUQUIMIA         28-SEP-00        05
                    108    TERESA MOLLINEDO            25-NOV-00        01
                    105    YOVANA FERNADEZ             26-JAN-01        00
                    153    DANILO FERRUFINO            27-JAN-01        05
                    156    BERNARDO GUZMAN             27-JAN-01        05
                    150    ALEJANDRO TORRES            21-MAR-01        05




               SQL * Plus
Sintaxis de la sentencia SELECT
       SELECT ...

       FROM ...

       .

       .



  SELECT nombre_columna [, nombre_columna...]
  FROM nombre_tabla

  o
                                                l1p19e1
  SELECT *                                      l1p21e1
                                                l1p23e1
  FROM nombre_tabla                             l1p25e1
                                                l1p27e1
Sintaxis SELECT
SELECION DE FILAS
           Servidor                                   SELECT ...

                                                      FROM ...

                                                      WHERE ...

                                                      .


      PERS_COD   PERS_DATOS          PERS_FECHA_CONTRAT DEPA_COD
      --------   ------------------- ------------------ --------
          101    JORGE ITURRALDE             05-JAN-00        00
          102    CAROLINA JOFRE              21-JAN-00        00
          155    SEBASTIAN CAPQUIQUE         30-JAN-00        05

SQL       104
          159
          109
                 GERMAN ARAUJO
                 OMAR FIGUEROA
                 ROBERTO GUZMAN
                                             20-FEB-00
                                             27-FEB-00
                                             25-MAY-00
                                                              00
                                                              05
                                                              01
          157    FRANCISCO MAYTA             28-MAY-00        05
          111    JAVIER NERI                 28-JUN-00        01
          152    ALBERTO ARANCIBIA           25-AUG-00        05
          154    RIGOBERTO CHUQUIMIA         28-SEP-00         • Nombre de columna o expresión
                                                              05
          108    TERESA MOLLINEDO            25-NOV-00        01
          105    YOVANA FERNADEZ             26-JAN-01        00
                                                                  o constante.
                                                               • Operador de comparación
                                                               • Expresión o nombre de columna
      SQL * Plus                                                 o constante
Revisión de Operadores de Comparación

   =          Igual a
                                   <=              Menor o igual que



!= <> ^=   Diferente a         BETWEEN...AND...    Entre dos valores



   >       Mayor que              IN (list)
                                                   Igual a cualquier miembro
                                                      de la siguiente lista



  >=       Mayor o igual que     IS NULL              Es un valor nulo



   <
                                                   Corresponde a un patrón de
             Menor que              LIKE          caracteres, usando comodines



                                                                   l1p31e1,2
                                                                   l1p32e1
                                                                   l1p33e1
                                                                   l1p34e1,2
Sintaxis SELECT                            SELECT ...

                                           FROM ...
Operadores de conexión lógica
con expresiones lógicas complejas.         WHERE ...

Expresiones Lógicas                                AND ...
     •       NOT
     •       AND                                   OR ...
     •       OR

Precedencia entre operadores
  =, !=, >, >=, <, <=, IN, LIKE, NULL, BETWEEN...AND...

Orden de los operadores lógicos
         1    NOT
         2    AND
         3    OR      Cuando una condición contiene más de una expresión, el Servidor
                      evalua cada expresión individualmente.

                      Los resultados de todas las condiciones son combinados en el orden
                      en que la precedencia de la jerarquía de operadores lo determina.

                                                                             l1p39e1,2
Sintaxis SELECT
           SELECT ...

           FROM ...

           WHERE ...

             ORDER BY ...



  La cláusula ORDER BY permite ordenar :

      •   en orden ascendente,
      •   en orden descendente,
      •   por nombres de multiples columnas, o
      •   por posición de las columnas.

                                                 l1p43e1,2
                                                 l1p45e1,2
REVISION DEL DICCIONARIO DE DATOS

El diccionario de datos es un grupo de tablas y vistas que contienen
información descriptiva acerca de las tablas, privilegios de acceso de los
usuarios y características de la base de datos.

Tablas del Diccionario referenciadas frecuentemente


Nombre Tabla          Descripción


USER_CATALOG          Tablas, vistas, sinónimos, secuencias propias del usuario
USER_CONSTRAINTS      Información acerca de los “constraints” sobre las tablas de usuarios
USER_INDEXES          Descripción de los índices propios del usuario
USER_SEQUENCES        Descripción de las secuecnias propias del usuario
USER_SYNONYMS         Descripción de los sinónimos propios del usuario
USER_TABLES           Descripción de las tablas propias del usuario
USER_USERS            Información acerca del usuario actual
USER_VIEWS            Descripción de las vistas propias del usuario
ALL_TABLES            Descripción de todas las tablas accesibles para el usuario

                                                                                      l1p47e1
EDICION DEL BUFFER DE SQL*PLUS

Editando los contenidos del buffer de SQL, con los comandos SQL*Plus

Comando                  Descripción

A[PPEND]                 Añade el texto especificado al final de la línea actual en el buffer
C[HANGE]                 Cambia la primera ocurrencia del texto en la línea actual del buffer
                         con la cadena de caracteres (string) provista, Ej.: C/ENPRESA/EMPRESA
CL[EAR]BUFFER            Limpia el buffer
or
CLE[AR]BUFFER
DEL                      Borra la línea actual del buffer
I[NPUT]                  Añade una o más líneas de texto despues de la línea actual en el buffer
                         Precionar <RETURN> sobre una línea en blanco para salir del modo
                         “input”
L[IST]                   Lista todas las líneas del buffer
L[IST]n                  Lista la línea n del buffer
R[UN]                    Despliega y ejecuta los contenidos del buffer
/                        Ejecuta el contenido del buffer
n                        Fija el puntero del buffer en la línea n
n<text string>           Reemplaza el contenido actual de la línea n con el “string” de texto provisto,
                         por ejemplo: 2 FROM PERSONAL

NOTA :           Un asterisco (*) aparecerá contiguo al número de línea actual

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Comandosql1

  • 2. CAP I El Método / Enfoque Relacional Filas Columnas Tabla PERSONAL PERS_COD PERS_DATOS PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD -------- -------------------- --------- ------------------- --------- -------- 101 JORGE ITURRALDE 05-JAN-00 1500 00 102 CAROLINA JOFRE 101 21-JAN-00 1000 00 155 SEBASTIAN CAPQUIQUE 153 30-JAN-00 05 104 GERMAN ARAUJO 101 20-FEB-00 00 159 OMAR FIGUEROA 150 27-FEB-00 05 109 ROBERTO GUZMAN 107 25-MAY-00 01 157 FRANCISCO MAYTA 156 28-MAY-00 05 111 JAVIER NERI 107 28-JUN-00 150 01 152 ALBERTO ARANCIBIA 150 25-AUG-00 05 154 RIGOBERTO CHUQUIMIA 153 28-SEP-00 500 05 108 TERESA MOLLINEDO 107 25-NOV-00 200 01 105 YOVANA FERNADEZ 102 26-JAN-01 500 00 153 DANILO FERRUFINO 150 27-JAN-01 05 156 BERNARDO GUZMAN 150 27-JAN-01 05 150 ALEJANDRO TORRES 102 21-MAR-01 1000 05
  • 3. Tabla DEPARTAMENTO El Método REGIONAL DEPA_COD DEPA_NOMBRE -------- -------- ------------------------ Relacional 00 00 GERENCIA GENERAL 01 00 GERENCIA REGIONAL 01 01 CONTABILIDAD 01 02 RECURSOS HUMANOS 01 03 TECNOLOGIA 01 04 VENTAS 01 05 ALMACENES 01 06 COMPRAS 01 07 TRANSPORTE 02 00 GERENCIA REGIONAL Tabla PERSONAL PERS_COD PERS_DATOS PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD -------- -------------------- --------- ------------------- --------- -------- 101 JORGE ITURRALDE 05-JAN-00 1500 00 102 CAROLINA JOFRE 101 21-JAN-00 1000 00 155 SEBASTIAN CAPQUIQUE 153 30-JAN-00 05 104 GERMAN ARAUJO 101 20-FEB-00 00 159 OMAR FIGUEROA 150 27-FEB-00 05 109 ROBERTO GUZMAN 107 25-MAY-00 01 157 FRANCISCO MAYTA 156 28-MAY-00 05 111 JAVIER NERI 107 28-JUN-00 150 01 152 ALBERTO ARANCIBIA 150 25-AUG-00 05 154 RIGOBERTO CHUQUIMIA 153 28-SEP-00 500 05 108 TERESA MOLLINEDO 107 25-NOV-00 200 01 105 YOVANA FERNADEZ 102 26-JAN-01 500 00 153 DANILO FERRUFINO 150 27-JAN-01 05 156 BERNARDO GUZMAN 150 27-JAN-01 05 150 ALEJANDRO TORRES 102 21-MAR-01 1000 05
  • 4. SQL*Plus es una herramienta diseñada por/para ORACLE, la cual extiende las capacidades del SQL ANSI estándard. Servidor PERS_COD PERS_DATOS -------- -------------------- 101 JORGE ITURRALDE 102 CAROLINA JOFRE 155 SEBASTIAN CAPQUIQUE 104 GERMAN ARAUJO 159 OMAR FIGUEROA 109 ROBERTO GUZMAN 157 FRANCISCO MAYTA SQL 111 152 JAVIER NERI ALBERTO ARANCIBIA SQL versus SQL*Plus SQL * Plus SQL Un lenguaje consistente de comandos para almacenar, recuperar, mantener y regular el acceso a la base de datos. SQL*Plus Una aplicación que reorganiza y executa comandos SQL que por Ej. permite personalizar reportes, proveyendo de ayuda, facilidades de edición y mantenimiento a variables del sistema
  • 5. Manipulación y recuperación de datos, y creación y modificación de las estructuras de datos con comandos SQL Funciones de los Comandos SQL Comandos SQL • ALTER • DROP • REVOKE • Consultas • AUDIT • GRANT • ROLLBACK • Manipulation de Datos • COMMENT • INSERT • SELECT • COMMIT • LOCK • UPDATE • Definition de Datos • CREATE • NO AUDIT • VALIDATE • Control de Datos • DELETE • RENAME SQL Buffer Comando SQL SQL Buffer
  • 6. Se escriben comandos SQL*Plus para manipular comandos SQL Funciones de los Comandos Comandos SQL* Plus SQL*Plus • $ • COPY • QUIT • Ingresar, editar, recuperar y correr • / • DESCRIBE • REMARK comandos SQL. • ACCEPT • DISCONNECT • RUN • Formatear, realizar calculos en el alma- • APPEND • EDIT • SAVE cenamiento, e imprimir resultados de • BREAK • EXIT • SET • BTITLE • GET • SHOW consultas en forma de reportes. • CHANGE • HELP • SPOOL • Listar definiciones de columnas para • CLEAR • HOST • SQLPLUS cualquier tabla. • COLUMN • INPUT • START • COMPUTE • LIST • TIMING • Accesar y copiar entre bases de datos. • • CONNECT • NEWPAGE TTITLE • Enviar mensajes y aceptar respuestas • UNDEFINE desde un usuario final. Comandos SQL*Plus SQL SQL Buffer Buffer
  • 7. INICIANDO UNA SESION SQL El primer paso para una sesión de SQL, es ingresar a SQL*Plus sqlplus <ENTER> Ingreso (Log in) Enter user_name: Usuario1 <ENTER> Enter Password: ****** <ENTER> SQL> exit <ENTER> Salida (Log off)
  • 8. Tabla DEPARTAMENTO SENTENCIA SELECT REGIONAL DEPA_COD DEPA_NOMBRE -------- -------- ------------------------ 00 00 GERENCIA GENERAL Seleccionar (SELECTing) información 01 00 GERENCIA REGIONAL 01 01 CONTABILIDAD desde una base de datos o CONSULTAR, 01 02 RECURSOS HUMANOS 01 03 TECNOLOGIA es una de las operaciones de Base de datos 01 04 VENTAS más comunes 01 01 05 ALMACENES 06 COMPRAS 01 07 TRANSPORTE 02 00 GERENCIA REGIONAL Items del servidor SELEC–cionables Tabla PERSONAL PERS_COD PERS_DATOS PERS_JEFE PERS_FECHA_CONTRATO PERS_BONO DEPA_COD • Columnas -------- -------------------- --------- ------------------- --------- -------- • Expresiones 101 102 JORGE ITURRALDE CAROLINA JOFRE 101 05-JAN-00 21-JAN-00 1500 1000 00 00 • Constantes 155 104 SEBASTIAN CAPQUIQUE GERMAN ARAUJO 153 101 30-JAN-00 20-FEB-00 05 00 159 OMAR FIGUEROA 150 27-FEB-00 05 109 ROBERTO GUZMAN 107 25-MAY-00 01 Requerimientos 157 FRANCISCO MAYTA 156 28-MAY-00 05 111 JAVIER NERI 107 28-JUN-00 150 01 minimos de la 152 ALBERTO ARANCIBIA 150 25-AUG-00 05 154 RIGOBERTO CHUQUIMIA 153 28-SEP-00 500 05 sentencia SELECT 108 TERESA MOLLINEDO 107 25-NOV-00 200 01 105 YOVANA FERNADEZ 102 26-JAN-01 500 00 153 DANILO FERRUFINO 150 27-JAN-01 05 • SELECT 156 150 BERNARDO GUZMAN ALEJANDRO TORRES 150 102 27-JAN-01 21-MAR-01 1000 05 05 • FROM
  • 9. Servidor SELECCION DE COLUMNAS PERS_COD PERS_DATOS PERS_FECHA_CONTRAT DEPA_COD -------- ------------------- ------------------ -------- 101 JORGE ITURRALDE 05-JAN-00 00 102 CAROLINA JOFRE 21-JAN-00 00 155 SEBASTIAN CAPQUIQUE 30-JAN-00 05 104 GERMAN ARAUJO 20-FEB-00 00 159 OMAR FIGUEROA 27-FEB-00 05 109 ROBERTO GUZMAN 25-MAY-00 01 SQL 157 111 152 FRANCISCO MAYTA JAVIER NERI ALBERTO ARANCIBIA 28-MAY-00 28-JUN-00 25-AUG-00 05 01 05 154 RIGOBERTO CHUQUIMIA 28-SEP-00 05 108 TERESA MOLLINEDO 25-NOV-00 01 105 YOVANA FERNADEZ 26-JAN-01 00 153 DANILO FERRUFINO 27-JAN-01 05 156 BERNARDO GUZMAN 27-JAN-01 05 150 ALEJANDRO TORRES 21-MAR-01 05 SQL * Plus
  • 10. Sintaxis de la sentencia SELECT SELECT ... FROM ... . . SELECT nombre_columna [, nombre_columna...] FROM nombre_tabla o l1p19e1 SELECT * l1p21e1 l1p23e1 FROM nombre_tabla l1p25e1 l1p27e1
  • 11. Sintaxis SELECT SELECION DE FILAS Servidor SELECT ... FROM ... WHERE ... . PERS_COD PERS_DATOS PERS_FECHA_CONTRAT DEPA_COD -------- ------------------- ------------------ -------- 101 JORGE ITURRALDE 05-JAN-00 00 102 CAROLINA JOFRE 21-JAN-00 00 155 SEBASTIAN CAPQUIQUE 30-JAN-00 05 SQL 104 159 109 GERMAN ARAUJO OMAR FIGUEROA ROBERTO GUZMAN 20-FEB-00 27-FEB-00 25-MAY-00 00 05 01 157 FRANCISCO MAYTA 28-MAY-00 05 111 JAVIER NERI 28-JUN-00 01 152 ALBERTO ARANCIBIA 25-AUG-00 05 154 RIGOBERTO CHUQUIMIA 28-SEP-00 • Nombre de columna o expresión 05 108 TERESA MOLLINEDO 25-NOV-00 01 105 YOVANA FERNADEZ 26-JAN-01 00 o constante. • Operador de comparación • Expresión o nombre de columna SQL * Plus o constante
  • 12. Revisión de Operadores de Comparación = Igual a <= Menor o igual que != <> ^= Diferente a BETWEEN...AND... Entre dos valores > Mayor que IN (list) Igual a cualquier miembro de la siguiente lista >= Mayor o igual que IS NULL Es un valor nulo < Corresponde a un patrón de Menor que LIKE caracteres, usando comodines l1p31e1,2 l1p32e1 l1p33e1 l1p34e1,2
  • 13. Sintaxis SELECT SELECT ... FROM ... Operadores de conexión lógica con expresiones lógicas complejas. WHERE ... Expresiones Lógicas AND ... • NOT • AND OR ... • OR Precedencia entre operadores =, !=, >, >=, <, <=, IN, LIKE, NULL, BETWEEN...AND... Orden de los operadores lógicos 1 NOT 2 AND 3 OR Cuando una condición contiene más de una expresión, el Servidor evalua cada expresión individualmente. Los resultados de todas las condiciones son combinados en el orden en que la precedencia de la jerarquía de operadores lo determina. l1p39e1,2
  • 14. Sintaxis SELECT SELECT ... FROM ... WHERE ... ORDER BY ... La cláusula ORDER BY permite ordenar : • en orden ascendente, • en orden descendente, • por nombres de multiples columnas, o • por posición de las columnas. l1p43e1,2 l1p45e1,2
  • 15. REVISION DEL DICCIONARIO DE DATOS El diccionario de datos es un grupo de tablas y vistas que contienen información descriptiva acerca de las tablas, privilegios de acceso de los usuarios y características de la base de datos. Tablas del Diccionario referenciadas frecuentemente Nombre Tabla Descripción USER_CATALOG Tablas, vistas, sinónimos, secuencias propias del usuario USER_CONSTRAINTS Información acerca de los “constraints” sobre las tablas de usuarios USER_INDEXES Descripción de los índices propios del usuario USER_SEQUENCES Descripción de las secuecnias propias del usuario USER_SYNONYMS Descripción de los sinónimos propios del usuario USER_TABLES Descripción de las tablas propias del usuario USER_USERS Información acerca del usuario actual USER_VIEWS Descripción de las vistas propias del usuario ALL_TABLES Descripción de todas las tablas accesibles para el usuario l1p47e1
  • 16. EDICION DEL BUFFER DE SQL*PLUS Editando los contenidos del buffer de SQL, con los comandos SQL*Plus Comando Descripción A[PPEND] Añade el texto especificado al final de la línea actual en el buffer C[HANGE] Cambia la primera ocurrencia del texto en la línea actual del buffer con la cadena de caracteres (string) provista, Ej.: C/ENPRESA/EMPRESA CL[EAR]BUFFER Limpia el buffer or CLE[AR]BUFFER DEL Borra la línea actual del buffer I[NPUT] Añade una o más líneas de texto despues de la línea actual en el buffer Precionar <RETURN> sobre una línea en blanco para salir del modo “input” L[IST] Lista todas las líneas del buffer L[IST]n Lista la línea n del buffer R[UN] Despliega y ejecuta los contenidos del buffer / Ejecuta el contenido del buffer n Fija el puntero del buffer en la línea n n<text string> Reemplaza el contenido actual de la línea n con el “string” de texto provisto, por ejemplo: 2 FROM PERSONAL NOTA : Un asterisco (*) aparecerá contiguo al número de línea actual