简体   繁体   English

SQl 修剪问题

[英]SQl Trim problem

I am trying to pull data from table using this select statement..我正在尝试使用此 select 语句从表中提取数据。

SELECT ID_NO
FROM EMPLOYEE
WHERE trim(SYN_NO) ='21IT';

SYN_NO column hold data in this format SYN_NO 列以这种格式保存数据

21IT / 00065421

I want to get just first four characters and drop rest of it.. i tried trim, rtrim but it didnt work.我想只得到前四个字符并删除它的 rest .. 我试过修剪,rtrim 但它没有用。 Is there a way to do this.. Thank you有没有办法做到这一点..谢谢

Sorry, just realized this is Oracle.抱歉,刚刚意识到这是 Oracle。 You need to use SUBSTR :您需要使用SUBSTR

SELECT ID_NO
FROM EMPLOYEE
WHERE SUBSTR(SYN_NO, 1, 4) ='21IT';

Sadly for those of us coming from SQL Server, there is no LEFT in oracle.可悲的是,对于我们这些来自 SQL 服务器的人来说,oracle 中没有LEFT The article I linked below talks about one person's encounter with this problem, and recommends using我在下面链接的文章讨论了一个人遇到这个问题,并建议使用

SUBSTR(SYN_NO,1,4)

( see article ) 见文章

Oracle SUBSTR specification Oracle SUBSTR 规格

In Oracle, you'd use the SUBSTR function在 Oracle 中,您将使用SUBSTR function

SELECT id_no
  FROM employee
 WHERE substr(syn_no,1,4) = '21IT'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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