CASE 语句上的 LPAD 和 RPAD

LPAD and RPAD on a CASE statement

我正在尝试用 3 个星号填充 case 语句的左侧和右侧。它运行但值不显示为 Null 值。有任何想法吗?

SELECT p.patientfirstname || ' ' || p.patientlastname AS "Patient"  
,CASE WHEN i.insuranceid IS NULL THEN RPAD(LPAD('No insurance', 3, '*'), 3, '*')
 ELSE i.insurancename 
 END "Insurance Name"
FROM patient p 
FULL OUTER JOIN insurance i ON (p.insuranceid = i.insuranceid);

正如我在评论中所写,如果你想要一个常量字符串,只需使用一个并取消填充:

 SELECT p.patientfirstname || ' ' || p.patientlastname AS "Patient"  
,CASE WHEN i.insuranceid IS NULL THEN '***No insurance***'
 ELSE i.insurancename 
 END "Insurance Name"
FROM patient p 
FULL OUTER JOIN insurance i ON (p.insuranceid = i.insuranceid);

填充用于在处理变短大小的字符串时确保固定大小的字符串。参见示例:

select lpad('Hola',7, '*'),  lpad('Namaste',7, '*'), lpad('Hello',7, '*') from dual;

***Hola |Namaste |**Hello

select length(lpad('Hola',7, '*')),  length(lpad('Namaste',7, '*')), length(lpad('Hello',7, '*')) from dual;

7 |7 |7