For example, I need to add 3 spaces to a string 'Hello'. How can I do that using simple SQL? Oracle version is 10g. Thank you.
-
give sample data with output.Sanjay Radadiya– Sanjay Radadiya2016-08-08 06:15:45 +00:00Commented Aug 8, 2016 at 6:15
-
@sanjayradadiya let's say I need to add 3 times 'a' to a string 'test' which must result 'aaatest'.BekaBot– BekaBot2016-08-08 06:17:39 +00:00Commented Aug 8, 2016 at 6:17
-
some equivalent to thisBekaBot– BekaBot2016-08-08 06:19:27 +00:00Commented Aug 8, 2016 at 6:19
Add a comment
|
2 Answers
Try this using lpad function of oracle
select lpad('a',3,'a')||'hello' from dual
here lpad('a',3,'a') return no of times return current sequence of char
Edit:
for add some char before string
with temp AS (SELECT 'HELLO' STR FROM DUAL)
SELECT lpad(str,length(str)+3,' ') output FROM temp;
3 Comments
Sanjay Radadiya
see edited answer also that set any char before current string with no of times.
BekaBot
sorry, could not mark as solved due to restrictions, now it is done. What does "with no of times" mean? Does it mean edited variant will work faster? Thank you.
Sanjay Radadiya
means how many time you want to add char before string i.e i want to add a char 3 times before hello then output is aaahello that it.
Do you mean simple concatenation?
WITH T AS (SELECT 'HELLO' STR FROM DUAL)
SELECT T.STR || ' '
FROM T;
1 Comment
BekaBot
not a simple one, but with non-fixed amount of concatenated characters