oracle 学习笔记(简单1)

1。总结oracle常用的语句:

创建表空间:

createtablespace[spacename]datafile[filepathname]size[num];

如:createtablespaceleo_tablespacedatafile'F:\oracle\product\10.1.0\oradata\leo_data.dbf'size500M;

创建用户:

createuser[username]identifiedby[password]defaulttablespace[spacename];

为用户授权:

grantconnect,resourceto[username];

grantdbato[username];

创建索引:

createuniqueindex[index_name]on[table_name]([column_name])

查询当前登陆用户的默认表空间的sql:函数:

selectusername,default_tablespacefromuser_users;

日期函数

日期函数规律:

日期-数字=日期

日期+数字=日期

日期-日期=数字(天数)

SQL>selectsysdatefromdual;获得当前日期

1.months_between():求出给定日期范围的月数

SQL>selectename,round(months_between(sysdate,hiredate))monthsfromemp;

2.add_months():在指定日期上加上指定月数

SQL>selectadd_months(sysdate,4)fromdual;

3.next_day():下一个的今天是哪一个日期

SQL>selectnext_day(sysdate,'星期一')fromdual;下一个星期一的日期

4.last_day():求出给定日期的那个月的最后一天日期

SQL>selectlast_day(sysdate)fromdual;

(2)将数字转换成字符串

9:表示一位数字

SQL>selectto_char(34343,'99,999')fromdual;

SQL>selectto_char(34343,'$99,999')fromdual;

SQL>selectto_char(34343,'L99,999')fromdual;根据本地语言环境进行显示,如果是中文,则显示¥

2.to_number:转换成数字

SQL>selectto_number('123')+to_number('123')fromdual;将字符串变为数字再相加

3.to_date:转换成日期

SQL>selectto_date('2010-09-10','yyyy-mm-dd')fromdual;

通用函数

1.nvl():将空值转换为指定值

SQL>selectnvl(comm,0)fromemp;

2.decode():类似于条件判断语句if...elseif...else

SQL>selectdecode(3,1,'内容是1',2,'内容是2',3,'内容是3','都不是')fromdual;

SQL>selectempno,ename,hiredate,sal,decode(job,'ANALYST','分析员','CLERK','业务员','MANAGER','经理','PRESIDENT','总裁','SALESMAN','销售员')jobfromemp;

相关推荐