SQL oracle初学者问题 [英] SQL oracle beginner questions

查看:69
本文介绍了SQL oracle初学者问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题1: 插入日期时必须使用to_date吗?

Question1: Do i have to use to_date while inserting date?

INSERT INTO some_table (date1, date2) 
    VALUES (to_date('2012-10-24','YYYY-MM-DD'), to_date('2012-10-24','YYYY-MM-DD'));

还是可以只作为字符串插入?这样一切都会好吗?我已经尝试过了,并且奏效了.

Or can just insert as string? Will everything be OK this way too? I've tried and it worked.

INSERT INTO some_table (date1, date2) 
        VALUES ('2012-10-24',2012-10-24');

问题2: 如果我不命名要插入的列怎么办?它可以工作,但是我的问题是它是否现在随机插入,还是在创建表期间采用列顺序?

Question2: What happens if i won't name columns that i'm inserting into? It works, but my question is if it inserts randomly now or it takes order of columns during creation of table?

INSERT INTO some_table 
        VALUES ('2012-10-24',2012-10-24');

推荐答案

1似乎仅适用于'YYYY-MM-DD'格式: http://docs.oracle.com/cd/B28359_01 /server.111/b28286/sql_elements003.htm#SQLRF51049

1 seems to only work with the 'YYYY-MM-DD' format: http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements003.htm#SQLRF51049 says

您可以将DATE值指定为字符串文字...若要将DATE值指定为文字文字,则必须使用公历.您可以指定ANSI文字... ANSI日期文字不包含时间部分,并且必须以'YYYY-MM-DD'格式指定.

You can specify a DATE value as a string literal ... to specify a DATE value as a literal, you must use the Gregorian calendar. You can specify an ANSI literal... The ANSI date literal contains no time portion, and must be specified in the format 'YYYY-MM-DD'.

但是,如果您使用

或者,您可以指定Oracle日期值... Oracle DATE值的默认日期格式由初始化参数NLS_DATE_FORMAT指定.

Alternatively you can specify an Oracle date value... The default date format for an Oracle DATE value is specified by the initialization parameter NLS_DATE_FORMAT.

对于问题2,它使用表定义时的顺序.但是,在这种情况下,您必须为所有列提供值.

For question 2, it uses the order at definition of the table. However you have to give values for all columns in that case.

这篇关于SQL oracle初学者问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆