Home » SQL & PL/SQL » SQL & PL/SQL » Problem in handling Sysdate (Oracle 10g/11g)
Problem in handling Sysdate [message #381497] Sat, 17 January 2009 05:51 Go to next message
expertsudhir
Messages: 26
Registered: October 2008
Location: Delhi, India
Junior Member

I have to access the value of Sysdate which is stored in a variable.

for example,

x varchar2( 8 ) := 'Sysdate';

now how do I get the value of sysdate through variable x.
Is there any way?

Please suggest me using a query or pl/sql.

K. Sudhir

[Updated on: Sat, 17 January 2009 05:54]

Report message to a moderator

Re: Problem in handling Sysdate [message #381513 is a reply to message #381497] Sat, 17 January 2009 09:11 Go to previous messageGo to next message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
x date := sysdate;

Regards
Michel
Re: Problem in handling Sysdate [message #381550 is a reply to message #381497] Sun, 18 January 2009 01:02 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
expertsudhir wrote on Sat, 17 January 2009 12:51
I have to access the value of Sysdate which is stored in a variable.

for example,

x varchar2( 8 ) := 'Sysdate';

now how do I get the value of sysdate through variable x.
Is there any way?


PL/SQL doesn't have a built-in mechanism for dynamic variables. There are ways (dynamic sql), but you don't want to go there.
Smells like you have moved yourself into a difficult position, trying to solve something completely different.
Maybe if you can explain your actual problem, with some code snippets of what you did so far, we can help you out.
Re: Problem in handling Sysdate [message #381593 is a reply to message #381497] Sun, 18 January 2009 21:51 Go to previous messageGo to next message
st33chen
Messages: 11
Registered: January 2009
Junior Member
hello,

try this :

1. create a stored function
create or replace function EVAL_DATE( xname in varchar2 ) return date
is
l_val date;
begin
execute immediate 'select ' || xname || ' from dual' INTO l_val;
return l_val;
end;
/

2. query (assume x was defined somewhere)
select eval(x) from dual;

note :
i tried
select eval('sysdate') from dual;
ok, so i think
select eval(x) from dual;
is ok, too.
Re: Problem in handling Sysdate [message #381594 is a reply to message #381497] Sun, 18 January 2009 21:59 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
st33chen,

You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
So we can help you.
Re: Problem in handling Sysdate [message #381604 is a reply to message #381593] Sun, 18 January 2009 22:53 Go to previous messageGo to next message
expertsudhir
Messages: 26
Registered: October 2008
Location: Delhi, India
Junior Member

thanks st33chen,

your procedure works and fulfil my needs.

but second query is not performing.

thanks again.

[Updated on: Sun, 18 January 2009 22:54]

Report message to a moderator

Re: Problem in handling Sysdate [message #381631 is a reply to message #381604] Mon, 19 January 2009 00:51 Go to previous message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
"is not working" is not an Oracle message error.

In addition, the provided function is a step to hell.
Search for "SQL injection".

Regards
Michel
Previous Topic: Primary key vs foreing key
Next Topic: Getting the Prior Dimension Value
Goto Forum:
  


Current Time: Thu Dec 08 02:07:26 CST 2016

Total time taken to generate the page: 0.06998 seconds