UTPLSQL 3.04版本列值比较测试失败问题求助
Hey there! Let's sort out this case-sensitive mismatch issue you're facing with your UTPLSQL test.
The Root Cause
Oracle's VARCHAR2 data type uses case-sensitive string comparisons by default. Your emp table stores the employee name as 'FORD' (all uppercase), but your test is expecting 'Ford' (title case). That's why the ut.expect(o_ename).to_equal('Ford') assertion fails—UTPLSQL is doing a strict, case-sensitive check here.
Solutions to Fix the Test
You have two straightforward options to make the comparison work:
Option 1: Use UTPLSQL's Built-In Case-Ignore Modifier
UTPLSQL 3.x lets you append .ignore_case() to your to_equal assertion to skip case checks. This keeps your test clean and readable:
ut.expect(o_ename).to_equal('Ford').ignore_case();
Option 2: Manually Normalize Case Before Comparison
If you prefer explicit case conversion, you can use Oracle's UPPER() or LOWER() functions to align the actual and expected values:
-- Compare uppercase values ut.expect(UPPER(o_ename)).to_equal('FORD'); -- Or compare lowercase values ut.expect(LOWER(o_ename)).to_equal('ford');
Modified Test Package Body Example
Here's how your updated test package body would look with Option 1:
create or replace package body testproc as procedure testename as i_empno emp.empno%TYPE := 7902; o_ename emp.ename%type; BEGIN p1(i_empno, o_ename); dbms_output.put_line(o_ename); ut.expect('Ford').to_equal('Ford'); -- This passes as expected ut.expect(o_ename).to_equal('Ford').ignore_case(); -- Now this passes too! END; end;
Bonus Note
If your business logic expects the ename to be returned in title case (like 'Ford'), you might want to check the p1 procedure to see if it's correctly formatting the string from the emp table. But if you only care about verifying the correct name regardless of case, either of the above fixes will resolve your test failure.
内容的提问来源于stack exchange,提问作者Raghukumar Gone

