やじゅ@アプリケーション・ラボ わんくま支局

目次

Blog 利用状況

ニュース

プロフィール

MSMVP

SQLのWHERE句にて、1=1というおまじない

検索画面等で抽出条件の有無により、SQLのWHERE句に条件を追加したり除外したりといったことが多々あります。

SELECT * FROM T_JUCHU_H
WHERE
IF ymd_from IS NULL THEN
AND JUCHU_YMD >= ymd_from
END IF
IF ymd_to IS NULL THEN
AND JUCHU_YMD <= ymd_to
END IF

この場合だと、条件が満たした場合
WHERE
AND JUCHU_YMD >= ymd_from AND JUCHU_YMD <= ymd_to
となり、WHERE後の"AND"が付いてしまい、SQLエラーとなります。

このような場合に、"1=1"というおまじないを追加してみると

WHERE 1=1
AND JUCHU_YMD >= ymd_from AND JUCHU_YMD <= ymd_to

SQLエラーとならずに実行されることになり、非常に便利です。


さて、気になったのがWHEREの順番によるパフォーマンスですが
コストベースであるなら気にする必要はないようですね。
実際に私環境上での実行プラン見ても1=1の付加による処理コスト
の変化は見当たりませんでした。

SQLのwhere条件の順序で、速度って変わるのでしょうか?
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail.php?qid=109774565
WHERE句の指定順序とパフォーマンス
http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=22052&forum=26&6

投稿日時 : 2007年11月7日 1:10

コメントを追加

# re: SQLのWHERE句にて、1=1というおまじない 2007/11/07 1:21 片桐

Oracleの話……ですよね(^^;
SQL-Serverだと、Where句の順番や固定値比較の書き方&サーバーのデータ格納量で実行プランが異なるので一概に「こいつが早いぜ!」と諸手をあげて歓迎できない部分がありますし(汗)

# re: SQLのWHERE句にて、1=1というおまじない 2007/11/07 1:25 中博俊

IS nullなら
JUCHU_YMD = JUCHU_YMDとすればいいのでは?

# re: SQLのWHERE句にて、1=1というおまじない 2007/11/07 10:18 やまだ

このおまじないを逆手にとって、検索文の最後に
OR 1=1
をくっつけちゃうのが、いわゆるSQLインジェクションという奴ですよね(違ったっけ?)。
その辺ちゃんと考慮に入れていないと、データ引っこ抜き放題になる、と。
#今時間ないので、何の確認もしないで書いてますが……。

# re: SQLのWHERE句にて、1=1というおまじない 2007/11/07 22:59 やじゅ

>片桐さん
確かにoracleですが、SQL-Serverもコストベースなので差はないと思われまするー

>中さん
あくまで例なので短めなんですが、実際はもっと複数項目となります。
ご指摘の件は、そういう方法もあるのねと勉強になりました。

>やまださん
OR 1=1 を追加するSQLインジェクションってありますねー
http://www.thinkit.co.jp/free/tech/7/5/1.html

SQLインジェクション対策として今のプロジェクトはバインド変数を使ってまする。

# bimatoprost 2021/12/13 7:19 Travislyday

http://plaquenils.com/ hydroxychloroquine sulfate 300 mg

# bimatoprost ophthalmic solution careprost 2021/12/16 11:29 Travislyday

http://baricitinibrx.com/ barilup

# ivermectin buy 2021/12/18 3:23 Eliastib

ptkmnb https://stromectolr.com ivermectin 5

# ivermectin for sale 2021/12/19 4:01 Eliastib

yelmkz https://stromectolr.com ivermectin 1 cream

# http://perfecthealthus.com 2021/12/21 14:00 Dennistroub

I know this is off topic but I simply needed to ask.

# ivermectin over the counter canada http://stromectolabc.com/
ivermectin 3mg tablets 2022/02/08 2:48 Busjdhj

ivermectin over the counter canada http://stromectolabc.com/
ivermectin 3mg tablets

# Wow! After all I got a web site from where I be capable of genuinely obtain helpful facts concerning my study and knowledge. 2022/02/12 13:08 Wow! After all I got a web site from where I be ca

Wow! After all I got a web site from where I be capable of genuinely obtain helpful facts concerning my study and knowledge.

# ロレックス レディース ヴィンテージ 2022/02/25 16:24 vagtlga@hotmail.co.jp

配送日ですが、私の無理な注文にも快く受けて頂き、商品もとても綺麗で、梱包もしっかりして居て、大変満足しています。
【送料無料】★ルイヴィトン★モノグラム★ミュルティクレ6★キーケース6連★M62630★
以前同じタイプの小さいサイズの物を、20年使っていましたが、車のキーが大きくなり合わなく成っていましたが無理して使っていた所、壊れてしまい買い換えました。このタイプは、ちょうど良い大きさでとても満足しています。
ロレックス レディース ヴィンテージ https://www.2bcopy.com/product/product.aspx-id=4964.htm

# buy doxycycline 100mg https://doxycyline1st.com/
where to get doxycycline 2022/02/26 9:14 Jusidkid

buy doxycycline 100mg https://doxycyline1st.com/
where to get doxycycline

# doxycycline 100mg dogs https://doxycyline1st.com/
price of doxycycline 2022/02/26 20:05 Doxycycline

doxycycline 100mg dogs https://doxycyline1st.com/
price of doxycycline

# clomid for men http://clomidfast.site/ 2022/04/12 12:29 Clomids

clomid for men http://clomidfast.site/

# where can i order prednisone 20mg http://prednisoneen.store/ 2022/04/16 22:24 Prednisone

where can i order prednisone 20mg http://prednisoneen.store/

# bNqpwvAcdymkLe 2022/04/19 12:58 johnansog

http://imrdsoacha.gov.co/silvitra-120mg-qrms

# finasteride prostate https://finasteridemen.com/
2022/05/11 14:30 Finasteride

finasteride prostate https://finasteridemen.com/

# ロレックス 中古 松山 2022/06/05 22:21 akxlofu@yahoo.co.jp

★弊社は「信用第一」をモットーにお客様にご満足頂けるよう
★全物品運賃無料(日本全国)
★不良品物情況、無償で交換します.
★税関没収する商品は再度無料で発送します
ロレックス 中古 松山 https://www.gmt78.com/product/detail/4713.htm

# ivermectin withdrawal time https://stromectolbestprice.com/ 2022/07/30 0:04 BestPrice

ivermectin withdrawal time https://stromectolbestprice.com/

# ルイ ヴィトン ロゴ tシャツ 2022/07/31 1:11 ieteegirl@ezwen.ne.jp

配送前にご丁寧にメールも頂け、荷物には手書きのお手紙もあり、大変気持ちよくお買い物できました。
商品自体もとっても満足です。
早く着用して外出したいです。

# ロレックス ピンクシェル ローマ 2022/08/04 7:57 xeybqtps@aol.jp

購入した翌々日の発送でしたが、それまでに3回も
お店からメールで連絡がきました。(サンクスメール:発送予告メール:発送メール)
真面目な店なんだなと、すごく好感がもてました。
梱包もプチプチで幾重にも包んであったり丁寧でした。
ただ、品物はしっかりとしたBOXに入っているので、
もうちょっと簡易梱包でも良いかも。
また機会があればお願いしたいと思います。

# ロレックス 偽物 所ジョージ 2022/08/04 8:05 mepkhu@ezwen.ne.jp

激安全国送料無料!100%正規品!
【新商品!】☆安心の全品国内発送!
【超人気新品】即日発送,品質100%保証!
激安販売中!
激安通販!☆安心の全品国内発送!
愛する品を選択する高級アイテムコンセント
『激安人気』送料無料.
『最速最新2022年人気新作!!』
2年保証、返品可能、全国送料無料!
顧客サービスと速い配送でお客様に手入れ。
高品質とリーズナブルで販売
オンラインストアオファー激安輸出
超安値登場!品質保証、最安値に挑戦!
オンラインストアは、ご来店ありがとうございます.
超人気【楽天市場】

# ロレックス 名古屋 コメ兵 2022/08/04 8:06 uolvsqffvqz@excite.co.jp

信じてよかったです。
本当にありがとうございました。
エルメス 時計 ケリー2 KT1.230 Q刻印 SS 白文字盤 4Pダイヤ クォーツ レディース 新品 ケリーウォッチ ブラック 婦人 女性 HERMES
最高(^^♪
元値が高価商品のモノだったので悩みましたが、信じてよかったです。気に入ってます&#127925;

# metformin buy usa https://glucophage.top/
metformin where to get 2022/08/23 7:27 Niujsdkj

metformin buy usa https://glucophage.top/
metformin where to get

# medication for ed https://ed-pills.xyz/
non prescription erection pills 2022/09/15 18:49 EdPills

medication for ed https://ed-pills.xyz/
non prescription erection pills

# erection pills online https://ed-pills.xyz/
natural ed remedies 2022/09/16 7:10 EdPills

erection pills online https://ed-pills.xyz/
natural ed remedies

# cheap ed pills https://ed-pills.xyz/
best ed treatment pills 2022/09/17 7:25 EdPills

cheap ed pills https://ed-pills.xyz/
best ed treatment pills

# erectile dysfunction drug https://ed-pills.xyz/
top ed pills 2022/09/17 19:30 EdPills

erectile dysfunction drug https://ed-pills.xyz/
top ed pills

# cheap antibiotic https://antibiotic.best/ 2022/10/08 3:34 Antibiotic

cheap antibiotic https://antibiotic.best/

# best ed medication https://erectiledysfunctionpills.shop/ 2022/10/14 22:48 Erectile

best ed medication https://erectiledysfunctionpills.shop/

# prednisone 60 mg https://prednisone20mg.icu/ 2022/10/15 13:21 Prednisone

prednisone 60 mg https://prednisone20mg.icu/

# Test, just a test 2022/12/13 5:26 candipharm.com

canadian pills online https://www.candipharm.com

# Get information now. Read here.
https://edonlinefast.com
Actual trends of drug. Long-Term Effects. 2023/02/17 16:58 EdPills

Get information now. Read here.
https://edonlinefast.com
Actual trends of drug. Long-Term Effects.

# Actual trends of drug. Learn about the side effects, dosages, and interactions.
https://canadianfast.com/
Get warning information here. Comprehensive side effect and adverse reaction information. 2023/02/19 18:16 CanadaBest

Actual trends of drug. Learn about the side effects, dosages, and interactions.
https://canadianfast.com/
Get warning information here. Comprehensive side effect and adverse reaction information.

# doors2.txt;1 2023/03/14 15:34 fHYPouNMCt

doors2.txt;1

# buy doxycycline online uk - https://doxycyclinesale.pro/# 2023/04/21 17:22 Doxycycline

buy doxycycline online uk - https://doxycyclinesale.pro/#

# top rated ed pills: https://edpills.pro/# 2023/05/15 15:21 EdPillsPro

top rated ed pills: https://edpills.pro/#

# buy paxlovid online https://paxlovid.pro/# - paxlovid generic 2023/07/02 17:18 Paxlovid

buy paxlovid online https://paxlovid.pro/# - paxlovid generic

# gГјnstige online apotheke 2023/09/26 12:45 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
versandapotheke

# internet apotheke 2023/09/27 0:00 Williamreomo

http://onlineapotheke.tech/# gГ?nstige online apotheke
internet apotheke

# versandapotheke deutschland 2023/09/27 5:57 Williamreomo

http://onlineapotheke.tech/# п»?online apotheke
п»?online apotheke

# п»їonline apotheke 2023/09/27 6:21 Williamreomo

https://onlineapotheke.tech/# internet apotheke
versandapotheke deutschland

# online apotheke deutschland 2023/09/27 6:45 Williamreomo

http://onlineapotheke.tech/# versandapotheke
internet apotheke

# п»їonline apotheke 2023/09/27 11:15 Williamreomo

http://onlineapotheke.tech/# versandapotheke versandkostenfrei
online apotheke preisvergleich

# п»їonline apotheke 2023/09/27 12:29 Williamreomo

https://onlineapotheke.tech/# versandapotheke deutschland
internet apotheke

# acquistare farmaci senza ricetta 2023/09/27 18:44 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacia online senza ricetta 2023/09/27 20:21 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# п»їfarmacia online migliore 2023/09/27 22:15 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacie on line spedizione gratuita 2023/09/27 22:48 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# canadian and international rx service 2023/10/16 12:45 Dannyhealm

Their worldwide reach ensures I never run out of my medications. https://mexicanpharmonline.shop/# reputable mexican pharmacies online

# prescription canada 2023/10/16 19:22 Dannyhealm

Every international delivery is prompt and secure. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# order prescription from canada 2023/10/17 1:07 Dannyhealm

A true champion for patients around the world. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# no.rx 2023/10/18 4:34 Dannyhealm

The gold standard for international pharmaceutical services. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# canadian pharmacies online 2023/10/18 8:39 Dannyhealm

They have an extensive range of skincare products. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# mexico drug stores online 2023/10/18 15:38 Dannyhealm

Their global pharmacists' network is commendable. http://mexicanpharmonline.shop/# mexico drug stores pharmacies

# paxlovid cost without insurance 2023/12/01 6:39 Mathewhip

paxlovid covid http://paxlovid.club/# paxlovid covid

# best canadian mail order pharmacies 2023/12/02 17:34 MichaelBum

https://paxlovid.club/# paxlovid for sale

# farmacia barata 2023/12/07 15:27 RonnieCag

http://farmacia.best/# farmacia 24h

# farmacia online envío gratis 2023/12/07 18:32 RonnieCag

http://tadalafilo.pro/# farmacias online baratas

# farmacia online envío gratis 2023/12/07 21:47 RonnieCag

https://farmacia.best/# farmacia online barata

# farmacias online seguras en españa 2023/12/08 7:04 RonnieCag

https://vardenafilo.icu/# farmacias baratas online envío gratis

# farmacia envíos internacionales 2023/12/08 12:39 RonnieCag

https://vardenafilo.icu/# farmacia online madrid

# ï»¿farmacia online 2023/12/08 21:39 RonnieCag

https://tadalafilo.pro/# farmacias baratas online envío gratis

# farmacia online envío gratis 2023/12/09 16:06 RonnieCag

https://tadalafilo.pro/# farmacias online seguras en españa

# farmacia online 24 horas 2023/12/10 6:06 RonnieCag

http://farmacia.best/# farmacia online barata

# farmacias online seguras en españa 2023/12/10 12:12 RonnieCag

https://vardenafilo.icu/# farmacias online seguras

# farmacia envíos internacionales 2023/12/10 18:37 RonnieCag

http://farmacia.best/# farmacias online seguras

# farmacia online envío gratis 2023/12/11 5:55 RonnieCag

http://farmacia.best/# farmacias baratas online envío gratis

# farmacias online seguras en españa 2023/12/11 8:54 RonnieCag

http://tadalafilo.pro/# farmacia online 24 horas

# farmacia envíos internacionales 2023/12/11 11:36 RonnieCag

http://vardenafilo.icu/# farmacia online

# farmacias online seguras en españa 2023/12/12 10:24 RonnieCag

https://vardenafilo.icu/# farmacia online madrid

# farmacia envíos internacionales 2023/12/12 16:20 RonnieCag

http://vardenafilo.icu/# farmacia envíos internacionales

# farmacias baratas online envío gratis 2023/12/13 9:44 RonnieCag

https://vardenafilo.icu/# farmacias baratas online envío gratis

# farmacia envíos internacionales 2023/12/13 12:45 RonnieCag

http://sildenafilo.store/# sildenafilo cinfa sin receta

# Pharmacie en ligne livraison rapide 2023/12/14 9:50 Larryedump

http://pharmacieenligne.guru/# Pharmacie en ligne livraison rapide

# best ed drug https://edpills.tech/# cheapest ed pills online 2023/12/23 4:42 EdPills

best ed drug https://edpills.tech/# cheapest ed pills online

タイトル
名前
URL
コメント