Sysdate complicated

Este forum é dedicado a códigos errados que se encontram por aí, ou seja, coisas que não se deve fazer de jeito nenhum! Não coloque neste forum dúvidas! (apenas situações bizarras do nosso dia a dia :-)
Post Reply
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

From time to time I find a SELECT so to get sysdate:

Select all

SELECT SYSDATE 
INTO variavel 
FROM DUAL; 
maybe the person did not know that just put sysdate anywhere in the SQL or PLSQL that the date comes without problems ...

Select all

variavel := SYSDATE; 
Below, I leave a case again in real programs!
This cursor managed to overcome the SELECT above!

Select all

DECLARE 
  CURSOR CDT IS 
    SELECT SYSDATE DAT 
    FROM DUAL; 
  VDATA  DATE; 
BEGIN 
  OPEN  CDT; 
  FETCH CDT INTO VDATA; 
  CLOSE CDT; 
END; 
was made a cursor to just know the date!
NaPraia
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 88
Joined: Fri, 22 Feb 2008 8:24 am
Location: Floripa - SC

This cursor killed the dick
as the first Select I had ever seen.
rodfbar
Rank: DBA Pleno
Rank: DBA Pleno
Posts: 241
Joined: Tue, 09 Oct 2007 11:15 am
Location: Batatais - SP

this already saw muito ... I worked with a guy who said that in the forms if he did not have the select into pro sysdate he returned the local time of the machine, and not the server time ...



User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Once I rode a trace that had some sysdates.
From what I remember, the Forms implicitly makes a Select from dual. (I may be wrong with that, but that I remember it does just that).

That is, the time is from the server.
But the case is that it is not necessary to do a SELECT from dual in the forms ... only pollute the code!
User avatar
gpilger
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 29
Joined: Wed, 21 Apr 2010 3:34 pm
Location: Novo Hamburgo - RS
Gilson Pilger
"Por não saber que erra impossível, ele foi lá e fez" autor desconhecido

And why not use it? There are people who lend themselves to give an open, fetch, and close, create a thousand variables when one is simplifies everything ..


Using Fetch Into

Select all

 
declare 
 
  cursor c_cur is 
    select 'Ivoti', 'Novo Hamburgo', 'Dois Irmãos' from dual; 
 
  v_cid_nome1 varchar2(30); 
  v_cid_nome2 varchar2(30); 
  v_cid_nome3 varchar2(30); 
 
begin 
 
  open c_cur; 
  loop 
    fetch c_cur 
      into v_cid_nome1, v_cid_nome2, v_cid_nome3; 
   
    update cidades set nome = v_cid_nome1 where codigo = 1; 
    update cidades set nome = v_cid_nome2 where codigo = 2; 
    update cidades set nome = v_cid_nome3 where codigo = 3; 
   
    exit when c_cur%NOTFOUND; 
   
  end loop; 
  close c_cur; 
 
  commit; 
 
end; 
using

Select all

 
declare 
begin 
 
  for r_cur in (select 'Ivoti' cid1, 'Novo Hamburgo' cid2, 'Dois Irmãos' cid3 from dual) 
  loop 
   
    update cidades set nome = r_cur.cid1 where codigo = 1; 
    update cidades set nome = r_cur.cid2 where codigo = 2; 
    update cidades set nome = r_cur.cid3 where codigo = 3; 
 
  end loop; 
  commit; 
 
end; 
But of course the two work, but let alone It gets a lot more clean.

Hugs
ricards
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 52
Joined: Sat, 29 Sep 2007 12:59 am
Location: Araraquara-SP
Contact:
Ricardo Neves
Analista e Instrutor Oracle Developer
Java Developer (JPA/JSF/Hibernate/WebServices/EJB)

Speak personal beleza?

in Forms 6i and Reports 6i We have the problem of sysdate Using the machine date and time is a tool bug, with this the idea is always to create a function in the BD and use them in the Forms and Reports.

From the new version this problem has been fixed.

I had this problem in a company I worked with Forms 6i.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests