I want SQLPLUS to return a negative value when running a SQL file.

Asked 2 years ago, Updated 2 years ago, 79 views

I would like to return a negative value when running SQL PLUS.
As a result of the execution, it would be good to see the following:

>sqlplus-Luser/pass@[email protected]
>echo$?
>-1

Simply put
in the DATA.SQL file EXIT-1
However, there was a description that it was impossible due to the specifications of SQL PLUS as follows, but would it be possible to do so using SP?Please let me know if there is a way.The operating system is RedhatLinux.

EXIT upper limit

Because the status code of the UNIX-based EXIT is masked by the lower 8 bits, it is converted to a different value even if a number of 256 or more is specified.Especially
Since the multiple of 256 becomes 0 when masked with the lower 8 bits, there is a risk of mistaking it as normal termination. 256
just because it's Windows-based If you use the above return values, you should refrain from using them as they will make the platform incompatible.

SQL*Plus>EXIT, QUIT

sql oracle

2022-09-30 20:34

2 Answers

This is not the answer, but I will write a little about the exit status of the shell (bash/zsh).

$bash-c'exit-1'; echo$?
255
$ bash-c'exit-2'; echo$?
254
$ bash-c'exit-3'; echo$?
253

The above example is bash, but the same is true for zsh.

man bash(1)

EXIT STATUS

The exit status of an executed command is the value returned by the waitpid system call or equal function.Exit status fall between 0 and 255, through, as expanded below, the shell may use values above 125 specifically.

The exit status is treated as unsigned char and should not be negative.Even if sqlplus is somehow given a return value of -1, the exit status in the shell is 255.Well,

Consider exit status 255 as -1

It may be good to do so, but I can't say that sqlplus might return exit status 255 due to an error, so I don't think it's appropriate.


2022-09-30 20:34

If you limit it to the return code, it says it will be masked in 8 bits, so it will be impossible.

I searched and found that some UNIX operating systems have similar Q&A descriptions.
Even if you force a negative bit, it will be around 255 if it is masked.

It's impossible for a return code, but the standard output of the shell and
As a result of the select clause, I can force it back.

set ret=`sqlplus-Suser/pass@sid`<<END
set head off;
set termout off
@ DATA.SQL
set termout on
select '-1' from dual;
exit;
END

After

echo$ret

and so on.

Additional: In my answer, I omitted the working part and only answered it, so
The following is a supplement to Heliac 2001's response to the results of the experiment.

"Mask at 8 bits" means
by binary bit operation. This means truncating non-low-order 8 bits.

-1 is expressed as a binary number in
2 complement form with the leftmost negative bit. 1111~Omitted~11111111 and 1 digit.

If the 8-bit mask truncates anything other than the lower 8 bits, it becomes 111111.
This is 255 when you change it to decimal, and the result of EXIT-1 contains this number.

The other negative numbers are like this.
-2 (decimal) = 1111 to abbreviated ~111110 (binary) - > Mask in lower 8 bits - > 254 (decimal)
-3 (decimal) = 1111 to abbreviated ~11111101 (binary) - > Mask in lower 8 bits - > 253 (decimal)


511, 767, 1023, 1777 because all the higher bits are digitized. 255 if the number 256 multiple -1 is included.
This is the same situation with other numbers.

For these reasons, you should avoid considering 255 as -1.


2022-09-30 20:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.