Home » SQL & PL/SQL » SQL & PL/SQL » Provide the output
Provide the output [message #607414] Thu, 06 February 2014 02:06 Go to next message
Rajesh@
Messages: 22
Registered: January 2014
Location: Hyderabad
Junior Member
Hi all,

Provide the output..
DECLARE
sysdate DATE;
BEGIN
sysdate := sysdate;
Dbms_Output.Put_Line ('Date is ' || Sysdate);
End;


Thank You
Re: Provide the output [message #607415 is a reply to message #607414] Thu, 06 February 2014 02:17 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
@mist598: you can provide the output! The code is syntactically correct, though it probably does not do what you want. You need to think about the scope of names. If the same name is used in different namespaces, which one will you be getting?
Re: Provide the output [message #607416 is a reply to message #607414] Thu, 06 February 2014 02:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SYSDATE is the name of an internal function.
If you use it for a variable you will have no more access to the function.

Always check your variable names against V$RESERVED_WORDS and don' use any name that in it.

Also, learn how to format and properly indent your code using SQL Formatter.

Re: Provide the output [message #607418 is a reply to message #607414] Thu, 06 February 2014 02:40 Go to previous messageGo to next message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Also, you'll need:

SET SERVEROUTPUT ON
Re: Provide the output [message #607420 is a reply to message #607416] Thu, 06 February 2014 03:01 Go to previous messageGo to next message
Rajesh@
Messages: 22
Registered: January 2014
Location: Hyderabad
Junior Member
Quote:

SYSDATE is the name of an internal function.
If you use it for a variable you will have no more access to the function.

Always check your variable names against V$RESERVED_WORDS and don' use any name that in it.


Yes you are right Michel Cadot , Thanks a lot, you are having more patience , i am very happy, kindness reply..Smile

Quote:
SET SERVEROUTPUT ON


Why? can u explain please.
Re: Provide the output [message #607424 is a reply to message #607420] Thu, 06 February 2014 03:17 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Rajesh@ wrote on Thu, 06 February 2014 10:01

Quote:
SET SERVEROUTPUT ON


Why? can u explain please.


dbms_output.put_line just puts the result in a buffer.
In order to get SQL*Plus displaying the content of this you have to execute this statement:
SQL> set serveroutput off
SQL> DECLARE
  2  sysdate DATE;
  3  BEGIN
  4  sysdate := sysdate;
  5  Dbms_Output.Put_Line ('Date is ' || Sysdate);
  6  End;
  7  /

PL/SQL procedure successfully completed.

SQL> set serveroutput on
SQL> DECLARE
  2  sysdate DATE;
  3  BEGIN
  4  sysdate := sysdate;
  5  Dbms_Output.Put_Line ('Date is ' || Sysdate);
  6  End;
  7  /
Date is

PL/SQL procedure successfully completed.
icon14.gif  Re: Provide the output [message #607426 is a reply to message #607424] Thu, 06 February 2014 03:34 Go to previous message
Rajesh@
Messages: 22
Registered: January 2014
Location: Hyderabad
Junior Member
Thank you so much sir.. Smile
Previous Topic: The Subqury Returns So Many Rows
Next Topic: Result from Rows to Columns
Goto Forum:
  


Current Time: Thu Apr 25 03:00:35 CDT 2024