currDate VARCHAR2(4000);
SELECT to_date(SYSDATE, 'DD/MM/YYYY')  into currDate
FROM DUAL;

on executing the above statements in oracle following error is coming

ORA-00905: missing keyword 00905. 00000 - "missing keyword"

Kindly help me in resolving it. Thank you

有帮助吗?

解决方案

If you want to store the value in a variable use something like below

variable currDate varchar2(100);

exec :currDate:=to_char(SYSDATE, 'DD/MM/YYYY');
select :currDate from dual;

:CURRDATE
---------- 
13/05/2014

Or you can use anonymous pl/sql block to do this

set serveroutput on

declare
 currDate varchar2(100);
begin
 SELECT to_char(SYSDATE, 'DD/MM/YYYY') into currDate FROM DUAL;
 dbms_output.put_line(currDate);
end;

/

其他提示

This is the difference between SQL and PL/SQL( procedural extension of SQL). What you have written is the syntax for pl/sql block. General form of PL/SQL block is

declare
...
begin
/* your code */
exception
....
end;
/

If you need to assign value to a variable, the general syntax in SQL is

declaring a variable variable currDate varchar2(100);

assinging value to variable exec :currDate:=to_char(SYSDATE, 'DD/MM/YYYY');

This variable :currDate is global and it can be used throughout the session.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top