• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

NESTED LTRIM STRING

Hi,

This is what I got for LTRIM(str,trimlist).

I started to do nested:
SELECT ename,CONCAT(empno,mgr)
FROM emp
WHERE LTRIM(ename,'K%','M%');

Not working, I tried:

SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE LTRIM(ename) LIKE 'K%';

It is correct but I want it nested as above.

Please advise any solutions?
0
suredazzle
Asked:
suredazzle
  • 7
  • 4
  • 3
1 Solution
 
Missus Miss_SellaneusCommented:
SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE LEFT(ename,1) IN ('K','M');
0
 
Missus Miss_SellaneusCommented:
SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE LEFT(ename,1) IN ('K','M');
0
 
Missus Miss_SellaneusCommented:
Sorry about the double post.. I had to reload the page, and that's what happened.. This should give the right results:

SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE SUBSTR(ename,1,1) IN ('K','M');
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Missus Miss_SellaneusCommented:
LEFT isn't in Oracle, sorry!
0
 
suredazzleAuthor Commented:
Thanks Miss Sellaneus! SUBSTR(string, strart, end).

Another example from net:
TRIM('S" FROM 'SSMITH').

0
 
awking00Commented:
substr syntax is substr(string, start, length) => not end
Also, Miss Sellaneus' query doesn't work if emp begins with leading blanks. Modify it to
where substr(ltrim(emp),1,1) in ('K','M')
0
 
suredazzleAuthor Commented:
Hi Awking00,

Thanks Awking00!     SUBSTR(job, 1,5) = 'SALES'

How about one quick question, Replace ?

I added MGR_Name column.

ALTER TABLE EMP ADD MGR_NAME CHAR(13);
It's null.

REPLACE(string,target,replacement)

MGR is also, an empno 2345 and etc.

So, I tried this:
REPLACE(mgr, ename, mgr_name)

What solution is for it, Awking00?
0
 
suredazzleAuthor Commented:
Sorry, AND is before REPLACE.
0
 
awking00Commented:
Not sure what you're looking to do. What is the structure of the emp table (i.e. what attributes and datatypes) and what do you want the values of the newly added mgr_name to be (and where do they come from)?
0
 
suredazzleAuthor Commented:
Hold on to last part. Let me play it more...
0
 
suredazzleAuthor Commented:
HI Awking00,

I want MGR_NAME column to be the values, name of manager.

Better way than enter manually:

INSERT INTO EMP VALUES(.......)
================================================

Mapping MGR_NAME to MGR to EMPNO to ENAME. How about using REPLACE?

Name                                 Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPNO                                 NOT NULL NUMBER(4)
 ENAME                                        CHAR(10)
 JOB                                        CHAR(9)
 MGR                                        NUMBER(4)
 HIREDATE                                  DATE
 SAL                                        NUMBER(7,2)
 COMM                                        NUMBER(7,2)
 DEPTNO                            NOT NULL NUMBER(2)
 MGR_NAME                                  CHAR(10)

Hope it make sense! Please provide feedback.
     
0
 
awking00Commented:
I think the attached should work.
updt-mgr-name.txt
0
 
suredazzleAuthor Commented:
HI Awking00,

This way works too.

 Faster with less typing. I will also check your solution.

UPDATE emp
SET MGR_NAME = 'KING'
WHERE EMPNO = 7839

Thanks for everything, Awking00!
0
 
suredazzleAuthor Commented:
Sorry, it should be:

UPDATE emp
SET MGR_NAME = 'CLARK'
WHERE MGR = 7698;    >> not EMPNO

     EMPNO ENAME           MGR MGR_NAME
---------- ---------- ---------- ----------
      7654 MARTIN          7698 CLARK
      7499 ALLEN          7698 CLARK
      7844 TURNER          7698 CLARK
      7900 JAMES          7698 CLARK
      7521 WARD           7698 CLARK
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now