如何在SQL中排除@之后的所有内容?
我是sql新手,正在编写sql脚本来选择数据,结果将以.csv格式显示。对于其中一个字段,我只需要为列表中的每个人选择电子邮件地址中@之前的内容。我不想更新表中的记录 例:约翰。doe@yahoo.com 我只需要选择约翰·多伊 我做这件事需要帮助。我正在Linux环境中使用sqlplus 下面是我在脚本中的内容。我仍然需要获得所需输出的帮助 选择nvlc.email\u email\u地址''如何在SQL中排除@之后的所有内容?,sql,oracle,Sql,Oracle,我是sql新手,正在编写sql脚本来选择数据,结果将以.csv格式显示。对于其中一个字段,我只需要为列表中的每个人选择电子邮件地址中@之前的内容。我不想更新表中的记录 例:约翰。doe@yahoo.com 我只需要选择约翰·多伊 我做这件事需要帮助。我正在Linux环境中使用sqlplus 下面是我在脚本中的内容。我仍然需要获得所需输出的帮助 选择nvlc.email\u email\u地址'' from email c, person a where c.email_pidm
from email c, person a
where c.email_pidm = a.person_pidm and
PERSON.ID = a.person_id and
c.email_emal_code = 'EMPL' and
c.email_status_ind = 'A' and
c.rowid = (select max(b.rowid)
from email b
where b.email_pidm = a.person_pidm and
b.email_emal_code = 'EMP'
and b.email_status_ind = 'A')
) "Employee_Email_Address",
SELECT SUBSTR(email_email_address, 0, INSTR(email_email_address, '@')-1)
--(select nvl(c.email_email_address, ' ')
from email c, person a
where c.email_pidm = a.person_pidm and
PERSON.ID = a.person_id and
c.email_emal_code = 'EMP' and
c.email_status_ind = 'A' and
c.rowid = (select max(b.rowid)
from email b
where b.email_pidm = a.person_pidm and
b.email_emal_code = 'EMPL'
and b.email_status_ind = 'A')
) "Username"
选择SUBSTR'test@example.com“,1,INSTR”test@example.com“,”@'-1来自双通道
输出:
试验
你可以做:
select SUBSTR("test@testdomain.com", 1, INSTR("test@testdomain.com", "@")-1)
from dual
SUBSTR的工作原理如下:
SUBSTR( string, start_position, [ length ] )
长度参数是什么…INSTRFIELD_NAME,@'-1。。。是为你准备的
INSTR告诉您在字符串或字段中查找或找到字符的位置。结果必须为-1,因此返回值中不会显示“@”。虽然数据库引擎会自动将0转换为1,但可能值得注意的是,在Oracle中,字符串是基于1的,而不是基于0的。
SUBSTR( string, start_position, [ length ] )