sql 判斷逗號分隔字串中, 包含某個字串

2021-10-02 22:37:06 字數 519 閱讀 4699

dimfilterids 是budg_template_dims 表裡的乙個字段, 儲存的是 "222, 123, 111" , "1123, 1456, 2123" 這一類字段, 要從表裡查詢出 dimfilterids 中包含 123 的記錄, 則使用以下 sql:

sqlserver:

select * from budg_template_dims where  charindex(','+ '"+ 123 + "' +','  ,  ','+ dimfilterids +',') > 0
oracle:

select * from budg_template_dims where instr(',' || dimfilterids || ',' , ',' ||  "123" || ',' ,1,1) > 0;

# ("被查詢字段", "匹配值", "起始位置","匹配第幾個")

查詢結果是:    "222, 123, 111" 所在這一條記錄被查出;

sql欄位中逗號分隔字串的判斷

例如,資料表t1中有乙個欄位playtheme存放的數值類似如下 第一行 1,2,12 第二行 22,222,2222 第三行 1,2 第四行 2,12 第五行 2 如果你想取出playtheme欄位包含 2 的行,在構造sql 引數形式 時,要是寫成下面這種形式的話,則會將五行一起取出來,顯然達不...

sql判斷字串包含字串語句

在sql中我判斷包含字串我們可使用很多方法,如like,replace,charindex函式都可實現我們要的功能,下面我來給各位介紹判斷字串包含字串sql語句。如果想從sql server中查詢包含某個關鍵字的東東,怎麼查詢呢?一般有兩個方法 1.用like 如下 複製 select from t...

SQL轉換列為以逗號分隔的字串

使用for xml path來將表中某一列的資料轉換為用逗號分隔的字串,例子如下 create table rowconcat rowno int primary key,rowcode varchar 30 insert into rowconcat values 1,one insert int...