我试图用3个星号填充案例陈述的左侧和右侧。它会运行,但值不会显示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);
答案 0 :(得分:0)
正如我在评论中所写,如果你想要一个常量字符串,只需使用一个并取消填充:
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 | **您好
select length(lpad('Hola',7, '*')), length(lpad('Namaste',7, '*')), length(lpad('Hello',7, '*')) from dual;
7 | 7 | 7