This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Criação de Índices | |
| Porque o índice é importante? | |
| Índices (Index) são importantes pois diminuem processamento e I/O em disco. Quando usamos um comando SQL para retirar informações de uma tabela, na qual, a coluna da mesma não possui um índice, o Oracle faz um Acesso Total a Tabela para procurar o dado, ou seja, realiza-se um FULL TABLE SCAN degradando a performance do Banco de Dados Oracle. Com o índice isso não ocorre, pois com o índice isso apontará para a linha exata da tabela daquela coluna retirando o dado muito mais rápido. | |
| Crie Índices quando: | |
| Uma coluna contiver uma grande faixa de valores | |
| Uma coluna contiver muitos valores nulos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Otimização de Consulta | |
| AJUSTE DE SQL | |
| Uma das principais vantagens da linguagem SQL é que você não precisa dizer ao banco de dados exatamente como ele deve obter os dados solicitados. Basta executar uma consulta especificando as informações desejadas e o software de banco de dados descobre a melhor maneira de obtê-las. Às vezes, você pode melhorar o desempenho de suas instruções SQL “ajustando-as”. Nas seções a seguir, você verá dicas de ajuste que podem fazer suas consultas executarem mais rapidamente e técnicas de ajuste mais avançadas. | |
| USE UMA CLÁUSULA WHERE PARA FILTRAR LINHAS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*------------------------------------------- | |
| - SQL Dinamico com PL/SQL | |
| -------------------------------------------*/ | |
| /* | |
| create table tb_grandes_contratos ( | |
| cod_gcontrato integer, | |
| data date, | |
| total numeric(12,2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*------------------------------------------- | |
| - Comandos DML avancado | |
| -------------------------------------------*/ | |
| /* | |
| - Inserir os dados da consulta da tb_contrato nas tabelas | |
| - tb_curso e tb_aluno respectivamente. | |
| */ | |
| insert all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*------------------------------------------- | |
| - Database Link | |
| -------------------------------------------*/ | |
| create database link filial | |
| connect to system -- usuario | |
| identified by "oracle" -- senha do usuario | |
| using 'xe'; -- TNS (SID) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*------------------------------------------- | |
| - Aperfeicoando GROUP BY | |
| -------------------------------------------*/ | |
| select * from tb_contrato; | |
| select cod_aluno, | |
| trunc(data), | |
| sum(desconto) deconto, | |
| sum(total) total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- xxxxxxxxxxxxxxxxxxxxxxxxxx -- | |
| -- xxxxx Operadores SET xxxxx -- | |
| -- xxxxxxxxxxxxxxxxxxxxxxxxxx -- | |
| /* ----------------------------- | |
| -- UNION | |
| -- UNION ALL | |
| -- INTERSECT | |
| -- MINUS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- xxxxxxxxxxxxxxxxxxx -- | |
| -- xxxxx TRIGGER xxxxx -- | |
| -- xxxxxxxxxxxxxxxxxxx -- | |
| declare | |
| hora varchar(2); | |
| h number; | |
| begin | |
| h := to_number(to_char(sysdate, 'hh24')); | |
| dbms_output.put_line(H || ' - ' || to_char(sysdate, 'day')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- xxxxxxxxxxxxxxxxxxx -- | |
| -- xxxxx PACKAGE xxxxx -- | |
| -- xxxxxxxxxxxxxxxxxxx -- | |
| create or replace package pkg_aluno | |
| is | |
| vCidade varchar(30); -- variaveis publicas | |
| vMedia number(10,2); | |
| vNome varchar(30); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- xxxxxxxxxxxxxxxxxxxx -- | |
| -- xxxxx FUNCTION xxxxx -- | |
| -- xxxxxxxxxxxxxxxxxxxx -- | |
| create or replace function fn_consulta_preco | |
| (pCod_curso number) | |
| return number | |
| is | |
| vValor number; |