Frage

I am using following query:

DECLARE 
result varchar2(100);

BEGIN
select (systimestamp - (select date_time from test where id=2945134)) into result from dual;

SELECT SUBSTR(result, 3,1) Final_result
FROM DUAL;

END; 

It is showing an error like:

PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
Cause: Usually a PL/SQL compilation error.

I need to store result value from first query into result variable and then use that result variable to show the substring (3,1) as a Final_result.

War es hilfreich?

Lösung

DECLARE 
  result varchar2(100);
BEGIN

  select substr((systimestamp - (select date_time from test where id=2945134)), 3,1)
    into result
  from dual;

  dbms_output.put_line(result);
END;
/

But this is a highly dubious thing you are doing. You are relying on implicit datatype conversion (interval --> varchar) which will not work properly if your NLS settings change.

You would better use to_char() to format the resulting interval to something appropriate.

Andere Tipps

Instead of making 2 select from the same table, just 1 should suffice. Also as a practice, always try using the fully qualified name of your objects

Why do you need the "DUAL" table

DECLARE 
@final_result varchar2(100);

BEGIN
select @final_result= SUBSTR((systimestamp - (select date_time from test where id=2945134)),3,1);

END; 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top