I create a function that returns TEXT, end I'm trying to create a simple query to test this function. the query while looks like this:
CREATE TEMP TABLE function_test(actuel TEXT,expected TEXT,t_result TEXT);
/* the t_result should be'passed' if function(actuel) = expected */
INSERT INTO
function_test(actuel ,expected);
VALUES
('a','A'),/*function(`a`) return 'A'*/
('b','B'),/*function(`b`) return 'B'*/
('c','C');/*function(`c`) return 'C'*/
IF function(actuel)=expected THEN
INSERT INTO
function_test(t_result) VALUES 'passed' ;
ELSE
INSERT INTO
function_test(t_result) VALUES 'failed';
SELECT * FROM function_test;
DROP TABLE function_test;
Output It would be nice if I could do it better than this. thinks.
CodePudding user response:
Not entirely sure I understand what you are asking, but could you not just do either
select MY_FUNCTION('a','A') from dual;
or if you need a row on success and no row on failure
select 'PASS' from dual
where MY_FUNCTION('a','A') = 'YES'
DUAL is a 1 one row table that exists in every Oracle database.
CodePudding user response:
i resolve the problem on doing this
DO $$
DECLARE
actuel_alphabet TEXT = 'abc';
ecpected_alphabet TEXT = 'ABC';
actuel_num TEXT = '0123';
ecpected_num TEXT := '0123';
the_result TEXT = '';
BEGIN
CREATE TEMP TABLE case_test(actuel TEXT , expected TEXT,test_result TEXT );
--testing is the schema were the procedure is served
IF testing.trans(actuel_alphabet) = ecpected_alphabet THEN
the_result='PASSED';
ELSE the_result='FAILED';
END IF ;
INSERT INTO
case_test(actuel,expected,test_result) VALUES
(actuel_alphabet,ecpected_alphabet,the_result);
IF testing.trans(actuel_num) = ecpected_num THEN
the_result='PASSED';
ELSE the_result='FAILED';
END IF ;
INSERT INTO
case_test(actuel,expected,test_result) VALUES
(actuel_num,ecpected_num,the_result);
END $$;
SELECT * FROM case_test;
-- DROP TABLE case_test;
I don't know if is the bather's way or not,but it works like I was expecting. good bless you StackOversflowers ✌ಠ_ಠ Output