0

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.

3
  • give sample data with output. Commented 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'. Commented Aug 8, 2016 at 6:17
  • some equivalent to this Commented Aug 8, 2016 at 6:19

2 Answers 2

3

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;
Sign up to request clarification or add additional context in comments.

3 Comments

see edited answer also that set any char before current string with no of times.
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.
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.
-1

Do you mean simple concatenation?

WITH T AS (SELECT 'HELLO' STR FROM DUAL)
SELECT T.STR || '   '
  FROM T;

1 Comment

not a simple one, but with non-fixed amount of concatenated characters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.