Domanda

I want a query which will return a combination of characters and number

Example:

Table name - emp
Columns required - fname,lname,code

If fname=abc and lname=pqr and the row is very first of the table then result should be code = ap001.

For next row it should be like this:

Fname = efg, lname = rst
Code = er002 and likewise.

I know that we can use substr to retrieve first letter of a colume but I don't know how to use it to do with two columns and how to concatenate.

È stato utile?

Soluzione

OK. You know you can use substr function. Now, to concatenate you will need a concatenation operator ||. To get the number of row retrieved by your query, you need the rownum pseudocolumn. Perhaps you will also need to use to_char function to format the number. About all those functions and operators you can read in SQL reference. Anyway I think you need something like this (I didn't check it):

select substr(fname, 1, 1) || substr(lname, 1, 1) || to_char(rownum, 'fm009') code
from emp
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top