Solved

NESTED LTRIM STRING

Posted on 2008-10-19
14
577 Views
Last Modified: 2013-12-19
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
Comment
Question by:suredazzle
  • 7
  • 4
  • 3
14 Comments
 
LVL 11

Expert Comment

by:Missus Miss_Sellaneus
Comment Utility
SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE LEFT(ename,1) IN ('K','M');
0
 
LVL 11

Expert Comment

by:Missus Miss_Sellaneus
Comment Utility
SELECT ename,CONCAT(mgr,empno)
FROM emp
WHERE LEFT(ename,1) IN ('K','M');
0
 
LVL 11

Expert Comment

by:Missus Miss_Sellaneus
Comment Utility
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
 
LVL 11

Expert Comment

by:Missus Miss_Sellaneus
Comment Utility
LEFT isn't in Oracle, sorry!
0
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
Thanks Miss Sellaneus! SUBSTR(string, strart, end).

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

0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
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
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:suredazzle
Comment Utility
Sorry, AND is before REPLACE.
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
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
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
Hold on to last part. Let me play it more...
0
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
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
 
LVL 31

Accepted Solution

by:
awking00 earned 500 total points
Comment Utility
I think the attached should work.
updt-mgr-name.txt
0
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
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
 
LVL 1

Author Comment

by:suredazzle
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now