Home » SQL & PL/SQL » SQL & PL/SQL » Query within a function
Query within a function [message #35999] Mon, 29 October 2001 19:19 Go to next message
Rajarshi Dasgupta
Messages: 52
Registered: October 2001
Member
In SQL a query within a function works but not in PL/SQL.

Example:
********
SQL:
SELECT to_char((SELECT sysdate FROM dual), 'DD/MM/YYYY') FROM dual;

This SQL works properly.

PL/SQL:
DECLARE
var VARCHAR2(20);
BEGIN
SELECT to_char((SELECT SYSDATE FROM dual))
INTO var
FROM dual;
END;
/

This PL/SQL doesnot work. It gives an error.

WHY? And how can I overcome it?

----------------------------------------------------------------------
Re: Query within a function [message #36006 is a reply to message #35999] Mon, 29 October 2001 21:56 Go to previous message
Satish Shrikhande
Messages: 167
Registered: October 2001
Senior Member
Try this

DECLARE
var VARCHAR2(20);
BEGIN
SELECT to_char(d.d, 'DD/MM/YYYY') into var
FROM (SELECT sysdate d FROM dual) d;
dbms_output.put_line(var);
END;

----------------------------------------------------------------------
Previous Topic: Re: Reposting: URGENT : Help needed for Stored procedures
Next Topic: Re: Selling Sybase, Oracle OCP stuff at lower cost!
Goto Forum:
  


Current Time: Tue Nov 26 14:53:32 CST 2024