Home > Net >  Display employee name and job joined together, length of employee name and the position of letter A
Display employee name and job joined together, length of employee name and the position of letter A

Time:08-01

While practicing DBMS I came across this question. Now, I am stuck here since it is showing error:

at line: 4 column : 1.

I am unable to figure out how to display the numeric position of 'A' in employee name. It will be great, if anyobe can help me out.

SELECT
    FIRST_NAME||' '||LAST_NAME || ' ' || JOB_ID AS "NAME  JOB" ,
    LENGTH(FIRST_NAME || LAST_NAME ) AS "LENGTH",
    CHARINDEX('A', FIRST_NAME) AS "MATCH_POSITION"
FROM EMPLOYEES
WHERE JOB_ID LIKE '%SALES';

CodePudding user response:

you can use instead of | | and Len Fucntion Not Length Used My Modified Query

SELECT
    FIRST_NAME   ' '   LAST_NAME    ' '   JOB_ID AS "NAME   JOB" ,
    LEN(FIRST_NAME   LAST_NAME) AS "LENGTH",
    CHARINDEX('A', FIRST_NAME   LAST_NAME) AS "MATCH_POSITION"
FROM EMPLOYEES
WHERE JOB_ID LIKE '%SALES';

CodePudding user response:

It's used in Oracle SQL

select first_name || ' ' || last_name || ' ' || age as 'Name   Age',
length (first_name || last_name) as 'Length',
instr(first_name,'A') as 'Match_position'
from employees
Where JOB_ID LIKE '%SALES';
  • Related