當前位置:成語大全網 - 新華字典 - oracle中“select 1 from table”是什麽意思?

oracle中“select 1 from table”是什麽意思?

select 1 from table 與Select * from table在用法上大同小異,具體不同分析見下文:\x0d\\x0d\1、select 1 from mytable;與select anycol(目的表集合中的任意壹行) from mytable;與select * from mytable 作用上來說是沒有差別的,都是查看是否有記錄,壹般是作條件用的。select 1 from 中的1是壹常量,查到的所有行的值都是它,但從效率上來說,1>anycol>*,因為不用查字典表。\x0d\\x0d\2、查看記錄條數可以用select sum(1) from mytable;等價於select sum(*) from mytable;\x0d\\x0d\3、實際項目SQL:\x0d\\x0d\select c_insrnc_cde, c_nme_cn\x0d\ from t_prd_ins a\x0d\where a.c_prod_no = '01'\x0d\ and not exists\x0d\(select 1\x0d\ from (select d.c_insrnc_cde, a.c_nme_cn\x0d\ from t_prd_ins a,\x0d\ tb_bas_ply_policy_rdr c,\x0d\ tb_bas_ply_policy_rdr_list d\x0d\ where a.c_insrnc_cde = d.c_insrnc_cde\x0d\ and d.c_policy_id = c.c_policy_id\x0d\ and d.c_seq_no = c.c_seq_no\x0d\ and a.c_kind_no = '01'\x0d\ and c.c_dpt_cde = '101' ----機構樹中取出機構\x0d\ and c.c_prod_no = '01'\x0d\ and c.t_effc_tm = TO_DATE('2007-9-5', 'YYYY-MM-DD')\x0d\ and c.c_work_mode = '00501'\x0d\ and c.c_reach_area = '00701'\x0d\ ) t\x0d\ where t.c_insrnc_cde = a.c_insrnc_cde);\x0d\\x0d\測試場景:\x0d\table表是壹個數據表,假設表的行數為10行。\x0d\\x0d\1:select 1 from table 增加臨時列,每行的列值是寫在select後的數,這條sql語句中是1\x0d\\x0d\2:select count(1) from table 不管count(a)的a值如何變化,得出的值總是table表的行數\x0d\\x0d\3:select sum(1) from table 計算臨時列的和\x0d\\x0d\ 在SQL SERVER中用 1 測試了壹下,發現結果如下:\x0d\\x0d\1:測試結果,得出壹個行數和table表行數壹樣的臨時列(暫且這麽叫,我也不知道該叫什麽),每行的列值是1;\x0d\\x0d\2:得出壹個數,該數是table表的行數;\x0d\\x0d\3:得出壹個數,該數是table表的行數;\x0d\\x0d\然後我又用“2”測試,結果如下:\x0d\\x0d\1:得出壹個行數和table表行數壹樣的臨時列,每行的列值是2;\x0d\\x0d\2:得出壹個數,該數是table表的行數;\x0d\\x0d\3:得出壹個數,該數是table表的行數×2的數\x0d\\x0d\然後我又用更大的數測試:\x0d\\x0d\1:得出壹個行數和table表行數壹樣的臨時列,每行的列值是我寫在select後的數;\x0d\\x0d\2:還是得出壹個數,該數是table表的行數;\x0d\\x0d\3:得出壹個數,該數是table表的行數×寫在select後的數\x0d\\x0d\ 綜上所述:第壹種的寫法是增加臨時列,每行的列值是寫在select後的數;第二種是不管count(a)的a值如何變化,得出的值總是table表的行數;第三種是計算臨時列的和。\x0d\\x0d\語句if not exists(select 1 from deleted d join inserted i on d.ID=i.ID\x0d\and d.col1=1 and i.col1=2)\x0d\\x0d\if not exists 如果不存在\x0d\(..)這裏該是驗證更新,更新前的id等於更新後的id,並且更新前col的值是1,更新後的值是2