Reputation: 49
Trying to get my head around PLSQL
So I want the firstname (fnamn) and lastname(enamn) to have its first letter in uppercase. Been googling around a lot, and found topics regarding it and been testing for a while now but dont get it to work.. Only managed all letters to be upper when trying.
Here's my code so far;
declare
cursor c_användare
is select upper(substr( fnamn,1)) ,Enamn,pnr
from bilägare;
v_fnamn bilägare.fnamn%type;
v_enamn bilägare.enamn%type;
v_pnr bilägare.pnr%type;
begin
if not c_användare%isopen then
open c_användare;
end if;
loop
fetch c_användare
into v_fnamn,v_enamn,v_pnr;
exit when c_användare%notfound;
dbms_output.put_line(v_Fnamn||', '||v_Enamn||', '||v_pnr||'år');
end loop;
close c_användare;
end;
Upvotes: 0
Views: 352
Reputation:
All you need is INITCAP
.
select initcap('jOHn') as first_name, initcap('smItH') as last_name from dual
union all
select initcap('JÁNOS') , initcap('KÁDÁR') from dual
;
FIRST_NAME LAST_NAME
---------- ----------
John Smith
János Kádár
Upvotes: 2
Reputation: 14916
What about:
UPPER(SUBSTR(fnamn,1,1)) || SUBSTR(fname,2)
SUBSTR() takes the 1-based first index, and then a length. If the length is omitted, the entire field is returned, so SUBSTR(field,1)
is the same as just field
.
Upvotes: 1