"Maikku" <kangasm...@netti.fi> a écrit dans le message de news: 2144735.1356.1334755734839.JavaMail.geo-discussion-forums@vbuo5...
| Why is this working:
| ACCEPT TESTNUMER NUMBER PROMPT "GIVE A NUMBER> "
|
| SPOOL &TESTNUMBER._LOGNAME.LOG
|
| but this isn't:
| SPOOL LOGNAME_&TESTNUMBER..LOG
|
| It seems, that I can use a number in logname if it's in the beginning of the logname, but otherwise not. If I use char it works both ways.
|
| I'm using SqlPlus 10.2.0.2.
|
| TIA
|
| Maija-Leena
Just execute "DEF TESTNUMBER" and you will understand.
If you don't then execute "PROMPT LOGNAME_&TESTNUMBER..LOG" and I hope this time you will.
On Wed, 18 Apr 2012 17:06:53 +0200, Michel Cadot wrote:
> "Maikku" <kangasm...@netti.fi> a écrit dans le message de news:
> 2144735.1356.1334755734839.JavaMail.geo-discussion-forums@vbuo5...
> | Why is this working:
> | ACCEPT TESTNUMER NUMBER PROMPT "GIVE A NUMBER> "
> |
> | SPOOL &TESTNUMBER._LOGNAME.LOG |
> | but this isn't:
> | SPOOL LOGNAME_&TESTNUMBER..LOG |
> | It seems, that I can use a number in logname if it's in the beginning
> of the logname, but otherwise not. If I use char it works both ways.
> |
> | I'm using SqlPlus 10.2.0.2.
> |
> | TIA |
> | Maija-Leena
> Just execute "DEF TESTNUMBER" and you will understand.
> If you don't then execute "PROMPT LOGNAME_&TESTNUMBER..LOG" and I hope
> this time you will.
> Regards Michel
Sorry, no dynamic spool names:
SQL> column mydt new_value mynum
SQL> select to_number(to_char(sysdate,'J')) as mydt from dual;
MYDT
----------
2456036
Elapsed: 00:00:00.02
SQL> select &&mynum+1 from dual;
old 1: select &&mynum+1 from dual
new 1: select 2456036+1 from dual
2456036+1
----------
2456037
Elapsed: 00:00:00.01
SQL> spool /tmp/test_&&mynum
SP2-0768: Illegal SPOOL command
Usage: SPOOL { <file> | OFF | OUT }
where <file> is file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]
SQL>
Oracle doesn't allow that. Of course, there are other scripting languages that can be used to that end.
On Apr 18, 11:28 pm, Maikku <kangasm...@netti.fi> wrote:
> Why is this working:
> ACCEPT TESTNUMER NUMBER PROMPT "GIVE A NUMBER> "
> SPOOL &TESTNUMBER._LOGNAME.LOG
> but this isn't:
> SPOOL LOGNAME_&TESTNUMBER..LOG
> It seems, that I can use a number in logname if it's in the beginning of the logname, but otherwise not. If I use char it works both ways.
> I'm using SqlPlus 10.2.0.2.
The problem is you are using the default formatting of NUMBER in a
character string (the name of the file). That won't work because it
left-pads the number with blanks.
If you change the default numformat - or change the variable format -
it'll work:
Ie, I simply changed the default way NUMBER is displayed to the
minimal string ('TM'). Look it up in the doco on COLUMN in the SQLPlus
guide. Works on both 10 and 11g, AFAIK.
Mladen alluded to it when he asked you to do a "DEF TESTNUMBER": there
you can see the default formatting which is right-justified numwidth.
On Wed, 18 Apr 2012 16:07:25 -0700, Noons wrote:
> Mladen alluded to it when he asked you to do a "DEF TESTNUMBER": there
> you can see the default formatting which is right-justified numwidth.
That was Michael, not me. I don't do such tricks in SQL*Plus.
On Apr 19, 11:40 am, Mladen Gogala <gogala.mla...@gmail.com> wrote:
> On Wed, 18 Apr 2012 16:07:25 -0700, Noons wrote:
> > Mladen alluded to it when he asked you to do a "DEF TESTNUMBER": there
> > you can see the default formatting which is right-justified numwidth.
> That was Michael, not me. I don't do such tricks in SQL*Plus.
> On Wed, 18 Apr 2012 17:06:53 +0200, Michel Cadot wrote:
>> "Maikku"<kangasm...@netti.fi> a écrit dans le message de news:
>> 2144735.1356.1334755734839.JavaMail.geo-discussion-forums@vbuo5...
>> | Why is this working:
>> | ACCEPT TESTNUMER NUMBER PROMPT "GIVE A NUMBER> "
>> |
>> | SPOOL&TESTNUMBER._LOGNAME.LOG |
>> | but this isn't:
>> | SPOOL LOGNAME_&TESTNUMBER..LOG |
>> | It seems, that I can use a number in logname if it's in the beginning
>> of the logname, but otherwise not. If I use char it works both ways.
>> |
>> | I'm using SqlPlus 10.2.0.2.
>> |
>> | TIA |
>> | Maija-Leena
>> Just execute "DEF TESTNUMBER" and you will understand.
>> If you don't then execute "PROMPT LOGNAME_&TESTNUMBER..LOG" and I hope
>> this time you will.
>> Regards Michel
> Sorry, no dynamic spool names:
> SQL> column mydt new_value mynum
> SQL> select to_number(to_char(sysdate,'J')) as mydt from dual;
> MYDT
> ----------
> 2456036
> Elapsed: 00:00:00.02
> SQL> select&&mynum+1 from dual;
> old 1: select&&mynum+1 from dual
> new 1: select 2456036+1 from dual
> 2456036+1
> ----------
> 2456037
> Elapsed: 00:00:00.01
> SQL> spool /tmp/test_&&mynum
> SP2-0768: Illegal SPOOL command
> Usage: SPOOL {<file> | OFF | OUT }
> where<file> is file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]
> SQL>
> Oracle doesn't allow that. Of course, there are other scripting languages
> that can be used to that end.
Hi Mladen,
why not ?
I use dynamic file every day from my sql-scripts.
A little example with sysdate:
set termout off
set feedback off
col char_date new_value file_date noprint
-- this or whatever you need in your filename.
select to_char(sysdate, 'YYYY_MM_DD_hh24miss') char_date from dual ;
set termout on
set feedback on
-- check if there a leading or trailing spaces
def file_time
spool c:\temp\test_sysdate_&file_date..log
Ok, it's written without testing, no database at home.
An issue may the formatting of the variables with leading spaces.
On Thu, 19 Apr 2012 18:00:15 +0200, Kay Kanekowski wrote:
> Hi Mladen,
> why not ?
> I use dynamic file every day from my sql-scripts.
SQL*Plus is not a scripting tool, at least not a good one, not even a usable one. There used to be a good reporting tool called RPT/RPF, but the programmer got called to better things and the tool was canceled.
When I need scripting tool, I use the available scripting languages. Better, faster and less convoluted.