Proc Envia E-mail. Table or View does not Exist

DBA Geral (instalação, configuração do banco, scripts do Sql*Plus, shell scripts, batch scripts, etc...)
Responder
Dulima-SP
Rank: DBA Júnior
Rank: DBA Júnior
Mensagens: 193
Registrado em: Qui, 24 Jan 2008 1:56 pm
Localização: SP
Dulima

DBA Oracle Jr

Informações do Ambiente:
* Versão do Oracle: 10 G
* Sistema Operacional: RH4

Srs.

Tenho Uma proc que enviar o Resultado de uma Query pro meu e-mail

Selecionar tudo

CREATE OR REPLACE procedure tbs_teste
 is
 l_body long := chr(10)
|| lpad('KTABLESPACE', 30, ' ') || ' '
|| lpad('Tipo', 2, ' ') || ' '
|| lpad('KTBS_EM_USO', 15, ' ') || ' '
|| lpad('KTBS_SIZE', 10, ' ') || ' '
|| lpad('KTBS_MAXSIZE', 10, ' ') || ' '
|| lpad('KFREE_SPACE', 10, ' ') || ' '
|| lpad('KSPACE', 10, ' ') || ' '
|| rpad('KPERC', 7, ' ') || chr(10) ||
rpad('-', 50, '-') || ' ' ||
rpad('-', 2, '-') || ' ' ||
rpad('-', 15, '-') || ' ' ||
rpad('-', 10, '-') || ' ' ||
rpad('-', 10, '-') || ' ' ||
rpad('-', 10, '-') || ' ' ||
rpad('-', 10, '-') || ' ' ||
rpad('-', 7, '-') || chr(10);

 begin
 for x in (
	select t.tablespace_name ktablespace,
       substr(t.contents, 1, 1) tipo,
       trunc((d.tbs_size-nvl(s.free_space, 0))/1024/1024) ktbs_em_uso,
       trunc(d.tbs_size/1024/1024) ktbs_size,
       trunc(d.tbs_maxsize/1024/1024) ktbs_maxsize,
       trunc(nvl(s.free_space, 0)/1024/1024) kfree_space,
       trunc((d.tbs_maxsize - d.tbs_size + nvl(s.free_space, 0))/1024/1024) kspace,
       decode(d.tbs_maxsize, 0, 0, trunc((d.tbs_size-nvl(s.free_space, 0))*100/d.tbs_maxsize)) kperc
from
  ( select SUM(bytes) tbs_size,
           SUM(decode(sign(maxbytes - bytes), -1, bytes, maxbytes)) tbs_maxsize,
           tablespace_name tablespace
    from ( select nvl(bytes, 0) bytes, nvl(maxbytes, 0) maxbytes, tablespace_name
           from dba_data_files
           union all
           select nvl(bytes, 0) bytes, nvl(maxbytes, 0) maxbytes, tablespace_name
           from dba_temp_files
         )
    group by tablespace_name
  ) d,
  ( select SUM(bytes) free_space,
           tablespace_name tablespace
    from dba_free_space
    group by tablespace_name
  ) s,
  dba_tablespaces t
where t.tablespace_name = d.tablespace(+) and
      t.tablespace_name = s.tablespace(+)
order by 8)
 loop
  l_body := l_body || rpad(x.KTABLESPACE, 50, ' ') || ' ' ||
  rpad(x.Tipo, 2, ' ') || ' ' ||
  rpad(x.KTBS_EM_USO, 15, ' ') || ' ' ||
  rpad(x.KTBS_SIZE, 10, ' ') || ' ' ||
  rpad(x.KTBS_MAXSIZE, 10, ' ') || ' ' ||
  rpad(x.KFREE_SPACE, 10, ' ') || ' ' ||
  rpad(x.KSPACE, 10, ' ') || ' ' ||
  rpad(x.KPERC, 7, ' ') || chr(10);

 end loop;
 mail.send
     ( p_sender_email => '<XXXXXXXX@XXXXXX.com.br>',
     p_from => 'Nome Exibido <XXXXXXXX@XXXXXX.com.br>',
     p_to => mail.array( '<XXXXXXXX@XXXXXX.com.br>'),
     p_subject => 'Tbs ',
     p_body => l_body );
 end;
/
Ate ai Sem problemas, a Fomatação não esta Ideal, mas atende o que preciso.

Bom, como vocês podem ver a Query busca Infomações do Dicionario de Dados.
Pois Bem. Eu Criei um usuario e Dei Acessos as tabelas dessa Query.
sem problemas, O select me tras o resultado devolta.
quando eu vou Compilar a PROC emite o Seguinte erro

Selecionar tudo

Errors for PROCEDURE TBS_TESTE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
22/11    PL/SQL: SQL Statement ignored
44/10    PL/SQL: ORA-00942: table or view does not exist
53/3     PL/SQL: Statement ignored
53/28    PLS-00364: loop index variable 'X' use is invalid
Fiz varios testes ate q Identifiquei uma Peculiaridade!!!
se eu Criar a proc em baixo no Usuario SYS, a Proc Compila sem Errios agora se For Abaixo do meu usurios, eu não Consigo compilar Diz q a Tabela não Existe...

já Deu Grant de DBA e SYSDBA... e Nada!!!

não quero Criar Abaixo do SYS!!

Aguel tem uma Ideia ???
Dulima-SP
Rank: DBA Júnior
Rank: DBA Júnior
Mensagens: 193
Registrado em: Qui, 24 Jan 2008 1:56 pm
Localização: SP
Dulima

DBA Oracle Jr

victorhugomuniz
Moderador
Moderador
Mensagens: 1396
Registrado em: Sex, 01 Fev 2008 2:06 pm
Localização: Rio de Janeiro - RJ
Contato:
:D

eu não entendi bem..

você deu grant em que objeto ?


talvez falte o sinonimo para alguma tabela que você acesse ou então coloque o owner da tabela na frente
mportes
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Mensagens: 13
Registrado em: Ter, 01 Nov 2005 11:53 pm
Localização: São Paulo
Contato:

Quando você trabalha com views ou tabelas dentro de procedures ou packages, o privilégio deve ser obtido diretamente e não por role. No seu caso, como SYSDBA, dê os seguintes grants:

Selecionar tudo

connect / as sysdba
grant select on dba_temp_files to ...
grant select on dba_data_files to ...
grant select on dba_tablespaces to ...
grant select on dba_free_space to ...
Dulima-SP
Rank: DBA Júnior
Rank: DBA Júnior
Mensagens: 193
Registrado em: Qui, 24 Jan 2008 1:56 pm
Localização: SP
Dulima

DBA Oracle Jr

Exato.. Funcionou 100%

Obrigado

Aprimorei a Processo e agora estou recebendo o Conteudo em HTML

Vou terminar de formatar e mando a vocês


Obrigado!!!
Dulima-SP
Rank: DBA Júnior
Rank: DBA Júnior
Mensagens: 193
Registrado em: Qui, 24 Jan 2008 1:56 pm
Localização: SP
Dulima

DBA Oracle Jr

Caros Amigos...

Enfin Finalizei o processo....

Proc envia e-mail em HTML

Selecionar tudo

CREATE OR REPLACE PROCEDURE prc_relatorio_diario (strPara VARCHAR2,strCc VARCHAR2 )
  IS
  BEGIN

       DECLARE
            strTitulo  VARCHAR2(200):='Servidor de Banco de Dados Oracle';
            strMsg01     VARCHAR2(8000):='<html><head>';
            strMsg02     VARCHAR2(8000):=' ';
            strMsg03     VARCHAR2(8000):=' ';
            strMsg04     VARCHAR2(8000):=' ';
            strMsg05     VARCHAR2(8000):=' ';
        --  strMsg06     VARCHAR2(8000):=' ';
        --  strMsg07     VARCHAR2(8000):=' ';

            intListado   number:=1;
		-- CASO RESULTADO DA QUERY RETORNE MAIS DE UMA PAGINA ALTERE O PARAMETRO "intEmail" PARA 1
          	intEmail     number:=NULL;
		h_host	 VARCHAR2(50):=' ';

            compSmtp  utl_smtp.connection;
            strDe     VARCHAR2(50) := 'xxxxx@xxxx.com.br';
            smtpHost  VARCHAR2(30) := '999.999.999.999'; -- Servidor de Saida

        BEGIN

			select f_hostname into h_host from dual;

            strMsg01:= strMsg01 || '<style type="text/css">';
            strMsg01:= strMsg01 || '<!--';
            strMsg01:= strMsg01 || 'table{ font-family: "Trebuchet MS", Tahoma, Arial; font-size: 12px; color: #333333; border: #000000; border-style: solid; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin; text-align: justify; };';
            strMsg01:= strMsg01 || 'th{ background-color: #000000; color: #FFFFFF; border: #000000; border-style: solid; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin; };';
            strMsg01:= strMsg01 || '#tr1 {  background-color: #CBE7E7;};';
            strMsg01:= strMsg01 || '#tr2 {  background-color: #FFFFFF;};';
            strMsg01:= strMsg01 || 'td{text-align:right;} td.first{text-align:left; padding:0 10px 0 0;}';
            strMsg01:= strMsg01 || '-->';
            strMsg01:= strMsg01 || '</style></head><Body>BANCO DE DADOS<table><thead>';
            strMsg01:= strMsg01 || '<tr><th style="padding:0 10px 0 0;">DBID</th><th>INSTANCE NAME</th><th>HOST</th><th style="padding:0 10px 0 0;">DB NAME</th><th style="padding:0 10px 0 0;">LOG MODE</th><th>DATABASE</th></tr></thead><tbody>';


			strMsg02:= strMsg02 || '<br><br>ESPAÇO ASM';
            strMsg02:= strMsg02 || '<table><thead>';
            strMsg02:= strMsg02 || '<tr><th>GRUPO</th><th>NOME DO GRUPO</th><th>STATUS</th><th>TIPO</th><th>TOTAL GB</th><th>FREE GB</th></tr></thead><tbody>';

			strMsg03:= strMsg03 || '<br><br>ESPAÇO TABLESPACE';
            strMsg03:= strMsg03 || '<table><thead>';
            strMsg03:= strMsg03 || '<tr><th style="padding:0 10px 0 0;">TABLESPACE</th><th> T </th><th>EM USO</th><th>TAMANHO ATUAL</th><th>TAMANHO MAXIMO</th><th>ESPACO LIVRE</th><th>ESPACO LIVRE TOTAL</th><th>OCUPACAO - %</th></tr></thead><tbody>';



            compSmtp := utl_smtp.open_connection(smtpHost, 25); -- SMTP porta 25
            utl_smtp.helo(compSmtp, smtpHost);
            utl_smtp.mail(compSmtp, strDe);
            utl_smtp.rcpt(compSmtp, strPara);
			utl_smtp.rcpt(compSmtp, strCc);


          	for c in
          	    (
				 select * from  vw_inf_dba_base
     			)
            loop
				if   length(strMsg01)<7500 then
                    if intListado=1 then intListado:=0; else intListado:=intListado +1; end if;
                    strMsg01:= strMsg01 || '<tr id="tr'|| to_char(intListado) || '">' || c.linha || '</tr>';
                    dbms_output.put_line('1 : ' ||  length(strmsg01));
				else
                  --Força o envio e zera as variaveis
                    utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html' || utl_tcp.crlf|| strMsg01 || utl_tcp.crlf || strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
                    dbms_output.put_line('De: ' || utl_tcp.crlf || 'Para: ' || strPara || utl_tcp.crlf || 'Título: ' || strTitulo );

                    intEmail:= intEmail + 1;
                    compSmtp := utl_smtp.open_connection(smtpHost, 25); -- SMTP porta 25
                    utl_smtp.helo(compSmtp, smtpHost);
                    utl_smtp.mail(compSmtp, strDe);
                    utl_smtp.rcpt(compSmtp, strPara);
			 		utl_smtp.rcpt(compSmtp, strCc);

                    strMsg02 :=' ';
                    strMsg03 :=' ';
                    strMsg04 :=' ';
                    strMsg05 :=' ';

				end if;
              
       		end loop;

          	for d in
          	    (
  				 select * from  VW_INF_DBA_ASM
     			)
	        loop
                if      length(strMsg02)<7500 then
                        if intListado=1 then intListado:=0; else intListado:=intListado +1; end if;
                        strMsg02:= strMsg02 || '<tr id="tr'|| to_char(intListado) || '">' || d.linha || '</tr>';
                        dbms_output.put_line('2 : ' ||  length(strmsg02));
                else
                        --Força o envio e zera as variaveis
                        utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html' || utl_tcp.crlf|| strMsg01 || utl_tcp.crlf || strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
                        dbms_output.put_line('De: ' || utl_tcp.crlf || 'Para: ' || strPara || utl_tcp.crlf || 'Título: ' || strTitulo );

                        intEmail:= intEmail + 1;
                        compSmtp := utl_smtp.open_connection(smtpHost, 25); -- SMTP porta 25
                        utl_smtp.helo(compSmtp, smtpHost);
                        utl_smtp.mail(compSmtp, strDe);
                        utl_smtp.rcpt(compSmtp, strPara);
						utl_smtp.rcpt(compSmtp, strCc);

                        strMsg03 :=' ';
                        strMsg04 :=' ';
                        strMsg05 :=' ';
                end if;

       		end loop;

			for e in
       			(
				 select * from  VW_INF_DBA_tbs
				)
	        loop
					if length(strMsg03)<7500 then
                    if intListado=1 then intListado:=0; else intListado:=intListado +1; end if;
                    strMsg03:= strMsg03 || '<tr id="tr'|| to_char(intListado) || '">' || e.linha || '</tr>';
                    dbms_output.put_line('2 : ' ||  length(strmsg02));
                 else
					--Força o envio e zera as variaveis
                    --utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(h_host) || ' ' ||to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html' || utl_tcp.crlf|| strMsg01 || utl_tcp.crlf || strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
                     utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Cc: ' || strCc  ||utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(h_host) ||  ' ' || to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html'|| utl_tcp.crlf|| strMsg01 || utl_tcp.crlf ||  strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
                     dbms_output.put_line('De: ' || utl_tcp.crlf || 'Para: ' || strPara || utl_tcp.crlf || 'Cc: ' || strCc || utl_tcp.crlf || 'Título: ' || strTitulo );

                        intEmail:= intEmail + 1;
                        compSmtp := utl_smtp.open_connection(smtpHost, 25); -- SMTP porta 25
                        utl_smtp.helo(compSmtp, smtpHost);
                        utl_smtp.mail(compSmtp, strDe);
                        utl_smtp.rcpt(compSmtp, strPara);
						utl_smtp.rcpt(compSmtp, strCc);

                        strMsg03 :=' ';
                        strMsg04 :=' ';
                        strMsg05 :=' ';
                 end if;

              --dbms_output.put_line(c.linha);
          	end loop;

			strMsg01:= strMsg01 || '</tbody></table>';
			strMsg02:= strMsg02 || '</tbody></table>';
			strMsg03:= strMsg03 || '</tbody></table>';

			utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Cc: ' || strCc  ||utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(h_host) ||  ' ' || to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html'|| utl_tcp.crlf|| strMsg01 || utl_tcp.crlf ||  strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
			--utl_smtp.data(compSmtp, 'From: ' || strDe || utl_tcp.crlf || 'To: ' || strPara  || utl_tcp.crlf || 'Subject: ' || strTitulo  || ' ' || to_char(h_host) ||  ' ' || to_char(intEmail) || utl_tcp.crlf || 'MIME-Version: 1.0' || utl_tcp.crlf || 'Content-type: text/html'|| utl_tcp.crlf|| strMsg01 || utl_tcp.crlf ||  strMsg02 || utl_tcp.crlf || strMsg03 || utl_tcp.crlf || strMsg04 || utl_tcp.crlf || strMsg05 || utl_tcp.crlf || '</Body></html>');
             
             dbms_output.put_line('De: ' || utl_tcp.crlf || 'Para: ' || strPara || utl_tcp.crlf || 'Cc: ' || strCc || utl_tcp.crlf || 'Título: ' || strTitulo );
             --dbms_output.put_line('De: ' || utl_tcp.crlf || 'Para: ' || strPara || utl_tcp.crlf || 'Título: ' || strTitulo );
             utl_smtp.quit(compSmtp);

          EXCEPTION

            WHEN UTL_SMTP.INVALID_OPERATION THEN
               dbms_output.put_line(' Operação inválida usando UTL_SMTP.');

            WHEN UTL_SMTP.TRANSIENT_ERROR THEN
               dbms_output.put_line('Email temporariamente fora do ar ou Caixa de entrada Cheia');

            WHEN UTL_SMTP.PERMANENT_ERROR THEN
               dbms_output.put_line(' Conta inexistente!');

        END;
    END;
/
Exemplo de uma VIEW q contem na Proc Acima

Selecionar tudo

CREATE OR REPLACE VIEW vw_inf_dba_base
(LINHA)
AS 
select  '<td class="first">' || v$database.dbid						|| '</td><td class="first">' ||
					upper(v$instance.instance_name)									|| '</td><td class="first">' || 
					f_hostname 																			|| '</td><td class="first">' ||  
					upper(v$database.name)													|| '</td><td class="first">' ||  
					v$database.log_mode															|| '</td><td  class="first">' ||  
					v$database.database_role    										|| '</td>' as linhas
from v$instance, v$database;

So estou com um Problema, preciso mandar o e-mail pra fora da Empresa.. e o que os Administradores me passaram foi q Seria necessario autenticar no servidor de Saida, para mandar e-mail para fora da empresa!!!

alguém já fez isso???? è Possivel.../???
Dulima-SP
Rank: DBA Júnior
Rank: DBA Júnior
Mensagens: 193
Registrado em: Qui, 24 Jan 2008 1:56 pm
Localização: SP
Dulima

DBA Oracle Jr

Caros Amigos.....

achei um exemplo...

Farei o teste durante a semana...

http://www.midstorm.org/~telles/2010/05 ... lo-oracle/

Aqueles q Conseguirem
Postem por favor...
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante