基于Oracle的SQL语句备忘

来源:互联网 发布:linux 音乐服务器 编辑:程序博客网 时间:2024/05/08 22:33

1. 请注意运算符的优先级,情况复杂的,多用括号以明晰逻辑。

Notice: precedence of operator!  Please don't stint '(' and ')' if you can't clarify the situation.

2. 需要根据某字段为空来查询记录:

Select condition: some section value is null in some table

select * from table_x  t   where t.section_a is null; 

3. 修改表中记录:

Update some record in some table:

update table_x set section_a = 'XXX' , section_b = 'YYY' where section_c = 'ZZZ'; 

4. 删除表中记录:

Delete some record(s) in a table:

delete  table_x  where  section_a = 'XXX'; 

5. nvl函数,其作用是:如果第一个参数为空值,则返回第二个参数的值,否则返回第一个参数的值。

Function 'nvl': If the first parameter is null, the second para as the return value; else return the first parameter.

6. 在执行一了些数据插入或删除之后,与MS SQL Server不同,Oracle中需要提交刚才执行的结果(可通过 commit; 语句实现)。

7. psu.end_date is null or psu.end_date > sysdate 判空,以及比较时间,关键字"is"和">"。

8. upper(psu.user_code)=upper('%s')  都以大写来比较,类似的,C++中有UpperCase函数。

9. 根据表中已有数据,创建一条“类似”数据并插入:??

10.select to_char(0.8, '0.0')||'%' from dual   查询结果是字符串:0.8%

原创粉丝点击