这是我的字符串
1001|L0|Current|USSD0786|03/06/2015|03339665535|||N|Muhammad Akbar|14301-9830008-9|City Bowra Garhi Tehsil/District Kohat|01/01/1980|Pakistan|01/01/2020||ABC@ABC.COM|Muhammad Zaman|Nadra|1234567890123456789|03/06/2015|41901|529268700|||
现在我想得到人穆罕默德阿克巴的名字。我正在使用它,但它没有给我全名
substr(request,53,INSTR(request, '|')-1)
你可以解决这个问题吗?
答案 0 :(得分:0)
你确定始终在第53位开始吗?
在这种情况下,你可以使用这个:
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:61)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.receiveResponseHeader(MeasuringConnectionManager.java:201)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:715)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:520)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:517)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:331)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Thread.java:745)
或者在9号烟斗之后更强烈' |' ?
答案 1 :(得分:0)
Oracle 11g R2架构设置:
CREATE TABLE Test( request ) AS
SELECT '1001|L0|Current|USSD0786|03/06/2015|03339665535|||N|Muhammad Akbar|14301-9830008-9|City Bowra Garhi Tehsil/District Kohat|01/01/1980|Pakistan|01/01/2020||ABC@ABC.COM|Muhammad Zaman|Nadra|1234567890123456789|03/06/2015|41901|529268700|||' FROM DUAL;
查询1 :
您可以使用正则表达式(^|\|)[^|]*
来匹配字符串的开头或管道(^|\|)
,后跟零或多个非管道字符[^|]*
。如果将其与REGEXP_SUBSTR
结合使用,Results具有表达式出现的第4个参数:
查询1 :
SELECT REPLACE(
REGEXP_SUBSTR(
request,
'(^|\|)[^|]*',
1,
10 -- Change this to get different values
),
'|'
) AS value
FROM Test
<强> Results 强>:
| VALUE |
|----------------|
| Muhammad Akbar |
查询2 :
如果您想要所有不同的值,那么您可以这样做:
SELECT LEVEL,
REPLACE(
REGEXP_SUBSTR(
request,
'(^|\|)[^|]*',
1,
LEVEL -- Change this to get different values
),
'|'
) AS value
FROM Test
CONNECT BY LEVEL <= REGEXP_COUNT( request, '\|' ) + 1
<强> https://docs.angularjs.org/api/ng/directive/ngClass 强>:
| LEVEL | VALUE |
|-------|----------------------------------------|
| 1 | 1001 |
| 2 | L0 |
| 3 | Current |
| 4 | USSD0786 |
| 5 | 03/06/2015 |
| 6 | 03339665535 |
| 7 | (null) |
| 8 | (null) |
| 9 | N |
| 10 | Muhammad Akbar |
| 11 | 14301-9830008-9 |
| 12 | City Bowra Garhi Tehsil/District Kohat |
| 13 | 01/01/1980 |
| 14 | Pakistan |
| 15 | 01/01/2020 |
| 16 | (null) |
| 17 | ABC@ABC.COM |
| 18 | Muhammad Zaman |
| 19 | Nadra |
| 20 | 1234567890123456789 |
| 21 | 03/06/2015 |
| 22 | 41901 |
| 23 | 529268700 |
| 24 | (null) |
| 25 | (null) |
| 26 | (null) |
答案 2 :(得分:0)
substr
的第三个参数不正确,目前您的语句看起来像substr(request, 53, 4)
。您需要稍微修改instr
,从第53位开始查看:
substr(request, 53, instr(substr(request, 53), '|')-1)
但更好的方法是从第9次出现'|'
开始在字符串和第10次出现,以使声明独立于该硬编码值53
:
substr(request,
instr(request, '|', 1, 9) + 1,
instr(request, '|', 1, 10)-instr(request, '|', 1, 9) - 1)
答案 3 :(得分:0)
根据您对我的评论的回复,
是起始位置是53到管道'|'
您需要一个嵌套的 SUBSTR &amp; INSTR 查询。
substr(request,53, instr(substr(request,53), '|', 1, 1)-1)
例如,
SQL> WITH DATA AS(
2 select '1001|L0|Current|USSD0786|03/06/2015|03339665535|||N|Muhammad Akbar|14301-9830008-9|City Bowra Garhi Tehsil/District Kohat|01/01/1980|Pakistan|01/01/2020||ABC@ABC.COM|Muhammad Zaman|Nadra|1234567890123456789|
03/06/2015|41901|529268700|||' request
3 FROM dual
4 )
5 SELECT substr(request,53, instr(substr(request,53), '|', 1, 1)-1) NAME FROM DATA;
NAME
--------------
Muhammad Akbar