0

I have this column called Week, that is a number. Instead of displaying it like week 1,2,3,4 etc i want to display with a 0 in front. I am working in Oracle Database.

The view is constructed as following:

Select "DATO","UGEDAG","WEEK","MÅNED","ÅR","KVARTAL","MÅNEDNUMMER","MÅNEDNUMMERTAL" 
from SC_DRIFT.EXCEL_DATO_UGE 
where DATO >= '2016-01-01'
J. A.
  • 15
  • 8
  • Basically the same thing as described [here](https://stackoverflow.com/questions/16760900/pad-a-string-with-leading-zeros-so-its-3-characters-long-in-sql-server-2008) but translated in PL-SQL – Geert Bellekens Dec 21 '18 at 10:15
  • For week 1 to 9 only, or for all weeks? – jarlh Dec 21 '18 at 10:15

2 Answers2

0

You can try below - using lpad() function

Select "DATO","UGEDAG",LPAD("WEEK", 2, '0'),"MÅNED","ÅR","KVARTAL","MÅNEDNUMMER","MÅNEDNUMMERTAL" 
from SC_DRIFT.EXCEL_DATO_UGE 
where DATO >= '2016-01-01'
Fahmi
  • 37,315
  • 5
  • 22
  • 31
0

You could use TO_CHAR:

SELECT
    "DATO",
    "UGEDAG",
     SUBSTR('0' || TO_CHAR(WEEK), -2, 2) AS "WEEK",
    "MÅNED",
    "ÅR",
    "KVARTAL",
    "MÅNEDNUMMER",
    "MÅNEDNUMMERTAL" 
FROM SC_DRIFT.EXCEL_DATO_UGE 
WHERE DATO >= '2016-01-01';
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360