【ALLLLLLLLLLLLLLLLLLLL】判断一个记录是否存在SQL codeif exists( select 1 from t_gpslatest where f_cod
【ALLLLLLLLLLLLLLLLLLLL】判断一个记录是否存在
SQL code
if exists( select 1 from t_gpslatest where f_code='12')(update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77',f_direction='66',f_speed='55',f_time=sysdate where f_code = '11')else(insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time)values('11','22222','333333','44444','55555','66666',sysdate))
DECLARE v_num NUMBER BEGIN select Count(*) INTO v_num from t_gpslatest where f_code='12'; IF v_num!=0 THEN update t_gpslatest set f_style='99',f_longtitude='88',f_latitude='77',f_direction='66',f_speed='55',f_time=sysdate where f_code = '11'; ELSE insert into t_gpslatest(f_code,f_style,f_longtitude,f_latitude,f_direction,f_speed,f_time)values('11','22222','333333','44444','55555','66666',sysdate); END IF;END; [解决办法]
[解决办法] oracle 10g中MERGE有如下改动: 1、UPDATE或INSERT子句是可选的 2、UPDATE和INSERT子句可以加WHERE子句 3、ON条件中使用堂过滤谓词来INSERT所有的行到目标表中,不需要连接源表和目标表 4、UPDATE子句后面可以跟DELETE子句来去除一些不需要的行 --示例 MERGE INTO products p USING new products np ON (p.product_id = np. Product_id) WHERE MATCHED THEN UPDATE SET p. product_name = np. Product_name, p.category = np.category DELETE WHERE (p.category = ‘ELECTRNCS’) WHEN NOT MATCHED THEN INSERT VALUES (np. Product_id,np. Product_name,np.category) [解决办法] 1楼回答的很好了,楼主就用1楼的答案撒。