简体   繁体   中英

TRIM replaces LTRIM/RTRIM

I am fairly new to Oracle.

Is it safe to say that LTRIM(RTRIM(<myVarchar>)) is totally replaceable by TRIM(<myVarchar>) if I want to replace both leading and trailing whitespaces in Oracle 11g?

Also, when I am trying to use this function in my query using JPA, I am getting error "org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node".

Here is the query that I am using:

@Query("Select p from OldPin p WHERE TRIM(p.eeNo) = :accNum and 
TRIM(p.pinStatus) = 'A' and TRIM(p.memberType='E') and TRIM(p.sCode) in 
('MSHK','MCMG')")
    public OldPin findByAccountNum(@Param("accNum") String accNum); 

Trim will remove both leading and trailing spaces by default eg. Trim(' test ') output will be test

If we use Trim(both from ) then it will remove a character from both side eg., Trim(both '1' from '111oracle111') output will be oracle Trim(leading '1' from '111oracle111') output will be oracle111 Trim(trailing '1' from '111oracle111') output will be 111oracle

Trim(both 'ab' from 'abtechab') - it will throw error, because trim will support single character only

In RTrim and LTrim we can remove any number of character.

Too, you can use

select '%'||replace(' hello world ', ' ' , '')||'%' from dual;

and the output is

%helloworld%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM