用SQL进行函数查询

来源:互联网 发布:2016淘宝销售额排名榜 编辑:程序博客网 时间:2024/06/17 03:17
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  Oracle 9i提供了很多函数可以用来辅助数据查询。接下来我们介绍常用的函数功能及使用方法。
4.5.1 【ceil】函数
    在【命令编辑区】输入“select mgr, mgr/100,ceil(mgr/100) from scott.emp;”,然后单击【执行】按钮,出现如图4.29所示的结果。
    【参见光盘文件】:/第4章/4.5/451.SQL

    【ceil】函数用法:ceil(n),取大于扔谑祅的最小整数。
 4.5.2 【floor】函数
     在【命令编辑区】输入“select mgr, mgr/100,floor(mgr/100) from scott.emp;”,然后单击【执行】按钮,出现如图4.30所示的结果。
    【参见光盘文件】:/第4章/4.5/452.SQL

    【floor】函数用法:floor(n),取小于等于数值n的最大整数。
4.5.3 【mod】函数
    在【命令编辑区】输入“select mgr, mod(mgr,1000), mod(mgr,100), mod(mgr,10) from scott.emp;”,然后单击【执行】按钮,出现如图4.31所示的结果。
    【参见光盘文件】:/第4章/4.5/453.SQL

    【mod】函数用法:mod(m,n),取m整除n后的余数。
4.5.4 【power】函数
    在【命令编辑区】输入“select mgr, power(mgr,2),power(mgr,3) from scott.emp;”,然后单击【执行】按钮,出现如图4.32所示的结果。
    【参见光盘文件】:/第4章/4.5/454.SQL

    【power】函数用法:power(m,n),取m的n次方。
4.5.5 【round】函数
    在【命令编辑区】输入“select mgr, round(mgr/100,2),round(mgr/1000,2) from scott.emp;”,然后单击【执行】按钮,出现如图4.33所示的结果。
    【参见光盘文件】:/第4章/4.5/455.SQL

    【round】函数用法:round(m,n),四舍五入,保留n位。
4.5.6 【sign】函数
    在【命令编辑区】输入“select mgr, mgr-7800,sign(mgr-7800) from scott.emp;”,然后单击【执行】按钮,出现如图4.34所示的结果。
    【参见光盘文件】:/第4章/4.5/456.SQL

    【sign】函数用法:sign(n)。n>0,取1;n=0,取0;n<0,取-1。
4.5.7 【avg】函数
    在【命令编辑区】输入“select avg(mgr) 平均薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.35所示的结果。
    【参见光盘文件】:/第4章/4.5/457.SQL

    【avg】函数用法:avg(字段名),求平均值。要求字段为数值型。
4.5.8 【count】函数
    (1)在【命令编辑区】输入“select count(*) 记录总数 from scott.emp;”,然后单击【执行】按钮,出现如图4.36所示的结果。
    【参见光盘文件】:/第4章/4.5/458-1.SQL

    (2)在【命令编辑区】输入“select count(distinct job ) 工作类别总数 from scott.emp;”,然后单击【执行】按钮,出现如图4.37所示的结果。
    【参见光盘文件】:/第4章/4.5/458-2.SQL

    【count】函数用法:count(字段名)或count(*),统计总数。
4.5.9 【min】函数
    在【命令编辑区】输入“select min(sal) 最少薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.38所示的结果。
    【参见光盘文件】:/第4章/4.5/459.SQL

    【min】函数用法:min(字段名),计算数值型字段最小数。
4.5.10 【max】函数
    在【命令编辑区】输入“select max(sal) 最高薪水 from scott.emp;”,然后单击【执行】按钮,出现如图4.39所示的结果。
    【参见光盘文件】:/第4章/4.5/4510.SQL

    【max】函数用法:max(字段名),计算数值型字段最大数。
4.5.11 【sum】函数
    在【命令编辑区】输入“select sum(sal) 薪水总和 from scott.emp;”,然后单击【执行】按钮,出现如图4.40所示的结果。
    【参见光盘文件】:/第4章/4.5/4511.SQL

    【sum】函数用法:sum(字段名),计算数值型字段总和。
    通过上面4类查询实例的学习,读者可以举一反三,灵活运用。用SQL进行数据的查询就介绍到这里,下面学习如何录入数据。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击