【发布时间】:2021-05-11 18:12:59
【问题描述】:
也许有人可以帮助我.. 我在这里有循环光标。我想打印出名字和年龄(以小数表示,例如 55,6 岁)。我知道我的代码的 WHERE 部分不正确。 我正在尝试使用 varchar2(12) 字符串中的 substr() 函数获取前 6 个字符(年和月)。然后我想将其更改为日期并从 sysdate 中减去。也许我错了。感觉很迷茫:(
CREATE TABLE client(
pers_nr VARCHAR2(12) PRIMARY KEY,
fname VARCHAR2(20);
INSERT INTO client VALUES('19490321-789','Anna');
declare
cursor c_info_client is select fname, substr(pers_nr, 1, 6)
from client
--wrong!-- where substr(pnr, 1, 6) : = to_date(YYYY-MM) - sysdate;
begin
for rec in c_info_client loop
dbms_output.put_line(initcap(rec.fname) ||', ' || rec.pers_pnr ||' years');
end loop;
end;
答案应该看起来像(多行之一):
安娜,34.7 岁
【问题讨论】:
标签: oracle plsql substr to-date sysdate