Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

NESTED LTRIM STRING

Posted on 2008-10-19
14
Medium Priority
?
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 12

Expert Comment

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

Expert Comment

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

Expert Comment

by:Missus Miss_Sellaneus
ID: 22753758
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 12

Expert Comment

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

Author Comment

by:suredazzle
ID: 22753833
Thanks Miss Sellaneus! SUBSTR(string, strart, end).

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

0
 
LVL 32

Expert Comment

by:awking00
ID: 22757978
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
ID: 22760320
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
 
LVL 1

Author Comment

by:suredazzle
ID: 22760360
Sorry, AND is before REPLACE.
0
 
LVL 32

Expert Comment

by:awking00
ID: 22760380
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
ID: 22760417
Hold on to last part. Let me play it more...
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22760817
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 32

Accepted Solution

by:
awking00 earned 2000 total points
ID: 22760890
I think the attached should work.
updt-mgr-name.txt
0
 
LVL 1

Author Comment

by:suredazzle
ID: 22761526
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
ID: 22762075
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

688 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