SQL 如何在oracle查询中获取字符串的前两个字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6225392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get first two characters of a string in oracle query?
提问by Vivek
Suppose I have a column name OrderNo
with value AO025631
in a table shipment
.
假设我在表中有一个OrderNo
带有值的列名。AO025631
shipment
I am trying to query the table so that I can get only first two character of column value i.e. AO
.
我正在尝试查询表,以便我只能获得列值的前两个字符,即AO
.
Can I do this in the SQL query itself?
我可以在 SQL 查询本身中执行此操作吗?
回答by manji
SUBSTR(documentation):
SUBSTR(文档):
SELECT SUBSTR(OrderNo, 1, 2) As NewColumnName from shipment
When selected, it's like any other column. You should give it a name (with As
keyword), and you can selected other columns in the same statement:
选中后,它就像任何其他列一样。您应该为其命名(带As
关键字),并且您可以在同一语句中选择其他列:
SELECT SUBSTR(OrderNo, 1, 2) As NewColumnName, column2, ... from shipment
回答by Tony Andrews
select substr(orderno,1,2) from shipment;
You may want to have a look at the documentationtoo.
您可能也想查看文档。
回答by Datajam
Easy:
简单:
SELECT SUBSTR(OrderNo, 1, 2) FROM shipment;
回答by thomas
回答by Farshid Zaker
回答by Shepherdess
Try select substr(orderno, 1,2) from shipment;
尝试从发货中选择 substr(orderno, 1,2);