① 關於indexOf(String sql)問題,求救!!!!
為重載方法:
indexOf(String sql) //此方法用於判斷字元串sql在目標字元串中存在的索引
indexOf(char sql) //此方法用於判斷字元sql在目標字元串中存在的索引
如果不存在則返回負數。
用例:
String str="abcdefg";
int count=str.indexOf(cde);
count的值為2;
char ch='f';
int count=str.indexOf(ch);
count的值為5;
② sql 條件查詢面積
Java示例:
public static void main(String args[]) {
String rawSql = "「林地」 or 「面積」>100 or 「面積」>90";
rawSql = rawSql.toLowerCase();
Vector<String> conList = new Vector<String>();
String[] split0 = rawSql.split("or");
String where = "";
int i = 0;
for (String s0 : split0) {
++i;
s0 = s0.trim();
if (s0.equals("")) {
continue;
}
String[] split1 = s0.split("and");
int j = 0;
for (String s1 : split1) {
++j;
s1 = s1.trim();
if (s1.equals("")) {
continue;
}
if (s1.indexOf("面積") < 0) {
s1 = "名稱 LIKE '%" + s1.trim() + "%'";
s1 = s1.replace("「", "").replace("」", "");
}
where += s1 + " ";
if (j > 0 && j < split1.length) {
where += " and ";
}
}
if (i > 0 && i < split0.length) {
where += " or ";
}
}
String sql = "SELECT * FROM your_table ";
if (where.length() > 0) {
sql += "WHERE " + where;
}
System.out.println(sql);
}
輸出結果:
SELECT * FROM your_table WHERE 名稱 LIKE '%林地%' or 「面積」>100 or 「面積」>90
基本思路就在那裡,參考一下吧。
③ indexOf()的用法,具體是什麼意思
indexOf()的用法:返回字元中indexof(string)中字串string在父串中首次出現的位置,從0開始!沒有返回-1;方便判斷和截取字元串!
indexOf()定義和用法
indexOf() 方法可返回某個指定的字元串值在字元串中首次出現的位置。
語法
stringObject.indexOf(searchvalue,fromindex)
參數 描述
searchvalue 必需。規定需檢索的字元串值。
fromindex 可選的整數參數。規定在字元串中開始檢索的位置。它的合法取值是 0到 - 1。如省略該參數,則將從字元串的首字元開始檢索。
說明
該方法將從頭到尾地檢索字元串 stringObject,看它是否含有子串 searchvalue。開始檢索的位置在字元串的 fromindex 處或字元串的開頭(沒有指定 fromindex 時)。如果找到一個 searchvalue,則返回 searchvalue 的第一次出現的位置。stringObject 中的字元位置是從 0 開始的。
提示和注釋
注釋:indexOf() 方法對大小寫敏感!
注釋:如果要檢索的字元串值沒有出現,則該方法返回 -1。
(3)sqlindexof怎麼寫擴展閱讀:
JavaScript一種直譯式腳本語言,是一種動態類型、弱類型、基於原型的語言,內置支持類型。它的解釋器被稱為JavaScript引擎,為瀏覽器的一部分,廣泛用於客戶端的腳本語言,最早是在HTML(標准通用標記語言下的一個應用)網頁上使用,用來給HTML網頁增加動態功能。
在1995年時,由Netscape公司的Brendan Eich,在網景導航者瀏覽器上首次設計實現而成。因為Netscape與Sun合作,Netscape管理層希望它外觀看起來像Java,因此取名為JavaScript。但實際上它的語法風格與Self及Scheme較為接近。
為了取得技術優勢,微軟推出了JScript,CEnvi推出ScriptEase,與JavaScript同樣可在瀏覽器上運行。為了統一規格,因為JavaScript兼容於ECMA標准,因此也稱為ECMAScript。
組成部分
ECMAScript,描述了該語言的語法和基本對象。
文檔對象模型(DOM),描述處理網頁內容的方法和介面。
瀏覽器對象模型(BOM),描述與瀏覽器進行交互的方法和介面。
參考資料:CSDN-indexOf()使用詳解
④ sql查詢按時間累計
做是可以做出來,我暫時沒考慮優化的問題。
我用的是Oracle資料庫,有些函數和寫法可能資料庫產品之間不太一樣,沒辦法了。
首先創建一個表:
indexof Varchar2
dateof Date
feeof Number
然後插入測試數據:
insert all
into test08 values('A',to_date('2009-05-02 00:00:00','yyyy-mm-dd hh24:mi:ss'),1)
into test08 values('B',to_date('2010-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),2)
into test08 values('A',to_date('2010-02-08 00:00:00','yyyy-mm-dd hh24:mi:ss'),3)
into test08 values('B',to_date('2010-03-09 00:00:00','yyyy-mm-dd hh24:mi:ss'),4)
into test08 values('A',to_date('2009-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),5)
into test08 values('A',to_date('2012-03-01 00:00:00','yyyy-mm-dd hh24:mi:ss'),38)
select * from al
然後這個表就和你那個差不多了
A 2009-05-02 00:00:00 1
B 2010-01-01 00:00:00 2
A 2010-02-08 00:00:00 3
B 2010-03-09 00:00:00 4
A 2009-03-01 00:00:00 5
A 2012-03-01 00:00:00 38
稍微多了幾個主要是測試用。
然後查詢你需要的:
select t1.indexof as indexof,t1.dateof as 日期,t1.feeof as 當期費用,
(
select sum(t2.feeof) from test08 t2
where t2.dateof<=t1.dateof
and t2.dateof>=trunc(t1.dateof,'yyyy')
and t2.indexof=t1.indexof
) as 本年度累加,
(
select sum(t2.feeof) from test08 t2
where t2.dateof<=t1.dateof
and t2.indexof=t1.indexof
) as 總累加
from test08 t1
order by dateof
注意:trunc函數是Oracle資料庫函數,是取當前日期的年份的。
order by dateof如果不需要可以刪除。有什麼不明白的地方可以直接M我。
⑤ sqlserver里有沒有類似indexOf功能的函數
sqlserver中和java中indexof類似的函數是字元串函數中的charindex。
CHARINDEX函數返回字元或者字元串在另一個字元串中的起始位置。
CHARINDEX函數調用方法如下:
CHARINDEX ( expression1 , expression2 [ , start_location ] )
------------------
一個修改字元串的sql語句用到了charindex,substring等函數的綜合使用
update [UpdateString]
set b=
substring(b,0,charindex(',',b,0))+','+
cast(cast(substring(substring(b,charindex(',',b,0)+1,len(b)),
0,charindex(',',substring(b,charindex(',',b,0)+1,len(b)),0)) as int)+2 as varchar)+','+
substring(substring(b,charindex(',',b,0)+1,len(b)),
charindex(',',substring(b,charindex(',',b,0)+1,len(b)),0)+1,
len(substring(b,charindex(',',b,0)+1,len(b))))
⑥ sql indexof函數怎麼用
sql indexof函數怎麼用
有,charindex就是,例如:charindex(str1,str2)返回的就是str1在str2的位置,有就返回具體位置,沒有就返回0
⑦ C# 中IndexOf的用法問題
C#中IndexOf的使用
IndexOf()
查找字串中指定字元或字串首次出現的位置,返首索引值,如:
str1.IndexOf("字"); //查找「字」在str1中的索引值(位置)
str1.IndexOf("字串");//查找「字串」的第一個字元在str1中的索引值(位置)
str1.IndexOf("字",start,end);//從str1第start+1個字元起,查找end個字元,查找「字」在字元串STR1中的位置[從第一個字元算起]注意:start+end不能大於str1的長度
indexof參數為string,在字元串中尋找參數字元串第一次出現的位置並返回該位置。如string s="0123dfdfdf";int i=s.indexof("df");這時i==4。
如果需要更強大的字元串解析功能應該用Regex類,使用正則表達式對字元串進行匹配。
indexof() :在字元串中從前向後定位字元和字元串;所有的返回值都是指在字元串的絕對位置,如為空則為- 1
string test="";
test.indexof(』d』) =2 //從前向後 定位 d 第一次出現的位置
test.indexof(』d』,1) =2 //從前向後 定位 d 從第三個字元串 第一次出現的位置
test.indexof(』d』,5,2) =6 //從前向後 定位 d 從第5 位開始查,查2位,即 從第5位到第7位;
lastindexof() :在字元串中從後向前定位字元和字元串;、
用法和 indexof() 完全相同。
⑧ sql 怎樣定位一個字元所在的位置
可以通過INSTR方法來進行查詢:
sql:select INSTR('abcdefg ','c') from al;
輸出結果:3。
解釋:以上sql就是查詢c字元在「abcdefg」中的位置。