今天在按照书上的说明,运行这本书的代码store_schema.sql时报错了,主要有2个问题:
1、在插入数据时,报错:无效的月份,后来在晚上查了一下,主要是因为插入语句中的日期中的月份是英文的,比如1月就是JAN,另外,需要日期格式是"日-月-年",所以在代码中加上了如下的语句:
alter session set nls_date_format='DD-MON-YYYY';
alter session set nls_date_language='american';
这样就不会再报错了。
2、另外,在本地机器上直接运行代码store_schema.sql时,不会报错,但如果从一台远程的机器上执行这个脚本时,则好报错,本地的机器是oracle 11g 11.2.0 .1,而远程的机器安装的是oracle 10g 10.2.0.1,每次都报:对象每次已存在。
照理在代码中会删除已经最在的用户store的表:
DROP USER store CASCADE;
但还是报这种错误,一会是对象已存在,一会是报主键冲突,说插入了重复数据。
最后发现是由于代码中有一个connect语句:
CONNECT store/store_password;
所以,导致直接连接到了本地的oracle 10g的实例上去了,而上面已经创建了相应的对象,也就是通过使用oracle 10g的sqlplus,连接到远程的oracle 11g,然后删除 oracle 11g的实例上的用于store,再次创建这个用户store、授权等,然后接下去再次连接到store用户,但连接到的是本地的oracle 10g的实例,所以只要把代码修改成下面就可以了:
CONNECT store/store_password@192.168.1.104/orcl;
store_schema.sql的完整代码:
-- This script does the following:
-- 1. Creates the store user
-- 2. Creates the database tables
-- 3. Creates the PL/SQL code
-- 4. Populates the database tables with sample data
-- attempt to drop the store user (this will generate an error
-- if the store user does not yet exist; do not worry about this
-- error); this statement is included so that you do not have
-- to manually run DROP before recreating the schema
DROP USER store CASCADE;
-- create the store user
CREATE USER store IDENTIFIED BY store_password;
-- allow the store user to connect and create database items
GRANT connect, resource TO store;
-- connect as the store user
CONNECT store/store_password@192.168.1.104/orcl;
alter session set nls_date_format='DD-MON-YYYY';
alter session set nls_date_language='american';
......
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/653220/viewspace-1982125/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/653220/viewspace-1982125/