设为首页收藏本站

八达网

 找回密码
 注册
查看: 135|回复: 5
打印 上一主题 下一主题

刚才SQL那道题的解决方法。。。

[复制链接]

2

主题

0

好友

6万

积分

仲裁者

A-CUP 才是王道!

2007年度八达十大杰出青年 2008年度八达十大水友 2009年度八达十大水友

跳转到指定楼层
1
发表于 2010-4-15 18:36 |只看该作者 |倒序浏览
妈的,原来学校用的是oracle,操

DATE FormatWhen a DATE value is displayed, Oracle must first convert thatvalue from the special internal format to a printable string. The conversionis done by a function TO_CHAR, according to a DATE format.Oracle's default format for DATE is "DD-MON-YY". Therefore,when you issue the queryselect b from x;you will see something like:B
---------
01-APR-98Whenever a DATE value is displayed, Oracle will call TO_CHARautomatically with the default DATE format. However, you may overridethe default behavior by calling TO_CHAR explicitly with your ownDATE format. For example,SELECT TO_CHAR(b, 'YYYY/MM/DD') AS b
FROM x;returns the result:B
---------------------------------------------------------------------------
1998/04/01The general usage of TO_CHAR is:TO_CHAR(<date>, '<format>')where the <format> string can be formed from over 40 options.Some of the more popular ones include:
, for example.
MMNumeric month (e.g., 07)
MONAbbreviated month name (e.g., JUL)
MONTHFull month name (e.g., JULY)
DDDay of month (e.g., 24)
DYAbbreviated name of day (e.g., FRI)
YYYY4-digit year (e.g., 1998)
YYLast 2 digits of the year (e.g., 98)
RRLike YY, but the two digits are ``rounded'' to a year inthe range 1950 to 2049.Thus, 06 is considered 2006 insteadof 1906
AM (or PM)Meridian indicator
HHHour of day (1-12)
HH24Hour of day (0-23)
MIMinute (0-59)
SSSecond (0-59)
You have just learned how to output a DATE value using TO_CHAR.Now what about inputting a DATE value? This is done through afunction called TO_DATE, which converts a string to a DATEvalue, again according to the DATE format. Normally, you do nothave to call TO_DATE explicitly: Whenever Oracle expects a DATEvalue, it will automatically convert your input string using TO_DATEaccording to the default DATE format "DD-MON-YY". Forexample, to insert a tuple with a DATE attribute, you can simplytype:
insert into x values(99, '31-may-98');Alternatively, you may use TO_DATE explicitly:insert into x
values(99, to_date('1998/05/31:12:00:00AM', 'yyyy/mm/dd:hh:mi:ssam'));The general usage of TO_DATE is:TO_DATE(<string>, '<format>')where the <format> string has the same options as in TO_CHAR.Finally, you can change the default DATE format of Oracle from"DD-MON-YY" to something you like by issuing the following commandin sqlplus:
alter session set NLS_DATE_FORMAT='<my_format>';The change is only valid for the current sqlplus session.The Current TimeThe built-in function SYSDATE returns a DATE value containingthe current date and time on your system. For example,select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time"
from dual;returnsCurrent Time
---------------------------------------------------------------------------
Tue 21-Apr-1998 21:18:27which is the time when I was preparing this document :-) Two interestingthings to note here:
  • You can use double quotes to make names case sensitive (by default, SQLis case insensitive), or to force spaces into names. Oracle will treateverything inside the double quotes literally as a single name. In thisexample, if "Current Time" is not quoted, it would have been interpretedas two case insensitive names CURRENT and TIME,which would actually cause a syntax error.
  • DUAL is built-in relation in Oracle which serves as a dummy relationto put in the FROM clause when nothing else is appropriate. Forexample, try "select 1+2 from dual;".
Another name for the built-in function SYSDATE is CURRENT_DATE.Be aware of these special names to avoid name conflicts.

上八达,日熊逼!

46

主题

0

好友

7万

积分

主区版主

处是一种生活态度

Rank: 8Rank: 8Rank: 8Rank: 8

2006年度八达十大杰出青年 2007年度八达十大水友

2
发表于 2010-4-15 18:38 |只看该作者
????
It's the best day of times,it's the worst day of times;

it was the age of wisdom,it was the age of foolishness;

it was the epoch of belief,it was the epoch of incredulity;

it was the season of light,it was the season of darkness;

it was the spring of hope,it was the winter of  despair;

we had everything before us,we had nothing before us;

we were all going direct to Heaven,we were all going direct the other way.
回复

使用道具 举报

376

主题

8

好友

7万

积分

仲裁者

DON'T PANIC

3
发表于 2010-4-15 18:39 |只看该作者
这边好像学校都是用的Oracle,很少用sql
回复

使用道具 举报

64

主题

0

好友

1万

积分

航母

4
发表于 2010-4-15 18:40 |只看该作者
我们也是用的Oracle
回复

使用道具 举报

190

主题

5

好友

4万

积分

管理员

小姐别发贴,是我

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

战队
[B.D]=
种族
Protoss

2013年夜饭

5
发表于 2010-4-15 18:40 |只看该作者
????
向还在为STL奋斗的玩家致敬!
回复

使用道具 举报

2

主题

0

好友

6万

积分

仲裁者

A-CUP 才是王道!

2007年度八达十大杰出青年 2008年度八达十大水友 2009年度八达十大水友

6
发表于 2010-4-15 18:43 |只看该作者
O老师懂SQL吗?有时间找你赐教啊

上八达,日熊逼!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|八达网    

GMT+8, 2026-2-24 17:40

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部