If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > DBMS_OUTPUT.PUT_LINE truncates leading zero

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-04, 06:13
dbforums_ajayp dbforums_ajayp is offline
Registered User
 
Join Date: Feb 2004
Posts: 11
Question DBMS_OUTPUT.PUT_LINE truncates leading zero

I am passing date time variable (ddmmyyhh24miss) as input to PL*SQL from a Unix shell script.

When I print this variable in the PL*SQL using DBMS_OUTPUT.PUT_LINE, in case of a day less than 10 (e.g. 06) it prints only '6'.

How can I make DBMS_OUTPUT.PUT_LINE to print '06' ?
__________________
Regards,

Ajay Patel
Reply With Quote
  #2 (permalink)  
Old 02-09-04, 07:15
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: DBMS_OUTPUT.PUT_LINE truncates leading zero

I suspect it is your call from Unix that is losing the leading zero - e.g. by passing the value as a NUMBER rather than as a character string:

PHP Code:
SQLexec dbms_output.put_line(to_char(sysdate,'DDMMYYHH24MISS'))
090204121616

PL
/SQL procedure successfully completed.

SQLexec dbms_output.put_line(to_number(to_char(sysdate,'DDMMYYHH24MISS')))
90204121627

PL
/SQL procedure successfully completed
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 02-09-04, 09:08
dbforums_ajayp dbforums_ajayp is offline
Registered User
 
Join Date: Feb 2004
Posts: 11
Re: DBMS_OUTPUT.PUT_LINE truncates leading zero

Quote:
Originally posted by andrewst
I suspect it is your call from Unix that is losing the leading zero - e.g. by passing the value as a NUMBER rather than as a character string:

PHP Code:
SQLexec dbms_output.put_line(to_char(sysdate,'DDMMYYHH24MISS'))
090204121616

PL
/SQL procedure successfully completed.

SQLexec dbms_output.put_line(to_number(to_char(sysdate,'DDMMYYHH24MISS')))
90204121627

PL
/SQL procedure successfully completed
No, the call from Unix is not removing the leading zero.

When I print the variable value using PROMPT before the PL*SQL block, the value is printed with the leading zero.
__________________
Regards,

Ajay Patel
Reply With Quote
  #4 (permalink)  
Old 02-09-04, 09:32
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: DBMS_OUTPUT.PUT_LINE truncates leading zero

Quote:
Originally posted by dbforums_ajayp
No, the call from Unix is not removing the leading zero.

When I print the variable value using PROMPT before the PL*SQL block, the value is printed with the leading zero.
Show your code! Clearly DBMS_OUTPUT is not the isee (see my example above). Perhaps you forgot to put single quotes around the value? :-

SQL> exec dbms_output.put_line(&v)
Enter value for v: 010203
10203

PL/SQL procedure successfully completed.

SQL> exec dbms_output.put_line('&v')
Enter value for v: 010203
010203

PL/SQL procedure successfully completed.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 02-09-04, 09:43
dbforums_ajayp dbforums_ajayp is offline
Registered User
 
Join Date: Feb 2004
Posts: 11
Re: DBMS_OUTPUT.PUT_LINE truncates leading zero

Quote:
Originally posted by andrewst
Show your code! Clearly DBMS_OUTPUT is not the isee (see my example above). Perhaps you forgot to put single quotes around the value? :-

SQL> exec dbms_output.put_line(&v)
Enter value for v: 010203
10203

PL/SQL procedure successfully completed.

SQL> exec dbms_output.put_line('&v')
Enter value for v: 010203
010203

PL/SQL procedure successfully completed.
Thanks!!!

The problem was because of the missing quotes ' ' )
__________________
Regards,

Ajay Patel
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On