0

I have below query:

   select 'my.MYNAME=' + name  from hostnames;

   my.MYNAME=abc
   my.MYNAME=xyz
   my.MYNAME=poi

The query is dynamic is gives3 result, it may give more result depending upon data.

I need following output:

my.MYNAME1=abc
my.MYNAME2=xyz
my.MYNAME3=poi

Numbers appending to MYNAME according to result it gives.

I have tried

select 'my.MYNAME={c}' + name  from hostnames where (select count(*) as c from name);

but it is not working.

1
  • 1
    Just append ROWNUM after MYNAME Commented May 16, 2018 at 15:03

1 Answer 1

3

One way to go about it is:

SELECT CONCAT(CONCAT(CONCAT('my.MYNAME',ROWNUM),'='), name) FROM hostnames

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

It's a bit simpler and easier to follow with the concatenation operator?
Hi Alex, I agree it is simpler but according to Doc When moving SQL script files between systems having different character sets, such as between ASCII and EBCDIC, vertical bars might not be translated into the vertical bar required by the target Oracle Database environment.

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.