i hv a prob here which already took me days to solve it..
my explanation will be quite lengthy but i try to keep it short.
in my Oracle SQLdeveloper, i have a package name UT_BETWNSTR which contain:
create or replace
PACKAGE "UT_BETWNSTR"
IS
PROCEDURE ut_setup;
PROCEDURE ut_teardown;
PROCEDURE ut_betwnstr;
END UT_BETWNSTR;
and the package body is like this:
create or replace
PACKAGE BODY "UT_BETWNSTR"
IS
PROCEDURE ut_setup IS
BEGIN
NULL;
END;
PROCEDURE ut_teardown
IS
BEGIN
NULL;
END;
PROCEDURE ut_BETWNSTR IS
BEGIN
utAssert.eq (
'Typical valid usage',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 3,
END_IN => 5)
,
'abc'
);
utAssert.isnull (
'NULL start',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => NULL,
END_IN => 5)
);
utAssert.isnull (
'NULL end',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 2,
END_IN => NULL)
);
utAssert.isnull (
'End smaller than start',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 5,
END_IN => 2)
);
utAssert.eq (
'End larger than string length',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 3,
END_IN => 200)
,
'cdefg'
);
END ut_betwnstr;
END UT_BETWNSTR;
and the function name BETWNSTR is like this:
create or replace
FUNCTION BETWNSTR (
string_in IN VARCHAR2,
start_in IN INTEGER,
end_in IN INTEGER
)
RETURN VARCHAR2
IS
l_start PLS_INTEGER := start_in;
BEGIN
IF l_start = 0
THEN
l_start := 1;
END IF;
RETURN (SUBSTR (string_in, l_start, end_in - l_start + 1));
END;
in my C drive, i put a file name BETWNSTR.sql which contain:
connect hr/hr
SET SERVEROUTPUT ON
EXEC UTPLSQL.TEST('BETWNSTR',Recompile_in=>FALSE);
exit
and this is my batch file (also in C drive), name try.bat which contain:
@sqlplus /nolog @C:\betwnstr.sql
echo %errorlevel%
if errorlevel 0 goto Success
echo You Got Error
:Success
echo Good Job!!
pause
ok here comes the error
when i run try.bat, it will return the big FAILURE result as i purposely put
PROCEDURE ut_BETWNSTR IS
BEGIN
utAssert.eq (
'Typical valid usage',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 3,
END_IN => 5)
,
'abc'
);
instead of
PROCEDURE ut_BETWNSTR IS
BEGIN
utAssert.eq (
'Typical valid usage',
BETWNSTR(
STRING_IN => 'abcdefg',
START_IN => 3,
END_IN => 5)
,
'cde'
);
i did that in purpose so that i hope the cmd will echo out:
You Got Error
because got error in my code..but the errorlevel is echoing 0 which mean it is a success..
i know, my code now is depending on errorlevel..when errorlevel is 0 it will echo out Good Job..
what i want right now is, when i run the batch file, when it encounter an error, i can echo out You Got Error message..
how can i echo out "You Got Error" message when the errorlevel is always showing 0..
in short, i want to echo out error message without depending on errorlevel..
i am hoping anybody hv the solution for my problem could pls answer my question..
Thanks In Advance!