Google Ad unit

問題for IT 人only..

select XX from XXX where 1 = 1

點解要咁寫?? 有乜用?? 答中冇獎.. .不過可以動下腦筋!!!

3 則留言:

mcc 說...

It is good practice to always having a where clause in SQL statement. Especially for dynamic SQL construction: concat the where condition by several "and xxx", "and yyy", etc.

sean 說...

easy for re-coding when the condition of the select statment needed to be changed

PGHK 說...

sean can u explain more detail on ur idea.

i remember one my colleague use if-case to compare each criteria which make coding is very long.

from that time i start to think can i build the sql dynamically to fulfill the input criteria. but i didn't use "where 1 = 1" at that time, i just erase the 'and' word first row of where clause, the idea is very useful.

now for complicated condition, a sql may be impossible to build or hard to build. we a tmp table in oracle and insert all hit record to the table. and then select all records out. ^_^