下記の記事を参考にmac OS でOracle Databaseを使えるように進めました。
https://qiita.com/shinbones/items/07d474a049c454100363
オラクルブロンズ白本付属のサンプル表をOracle Databaseに登録しようとSQLPlusのプロンプトに@cretab.sqlと入力して、スクリプトファイルを実行したところ下記のエラーが出ました。
SQL> @cretab.sql
SP2-0734: unknown command beginning "?@ / ???K..." - rest of line ignored.
SP2-0734: unknown command beginning "?@/* SYSTE..." - rest of line ignored.
"Clean Up ..."
"??????s???̓G???[?????????܂?????肠??܂???B"
User dropped.
"ora01" User Creating...
User created
Grant succeeded.
Grant succeeded.
Grant succeeded.
Grant succeeded.
"ora01" 's DATA Creating...
ERROR:
ORA-12545: Connect failed because target host or object does not exist
Warning: You are no longer connected to ORACLE.
SP2-0640: Not connectedが以下119行続きます。
sql
1SPOOL setup.log 2PROMPT 3PROMPT "Clean Up ..." 4PROMPT "初回実行時はエラーが発生しますが問題ありません。" 5DROP USER ora01 CASCADE; 6PROMPT 7PROMPT "ora01" User Creating... 8CREATE USER ora01 9IDENTIFIED BY oracle; 10GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO ora01; 11GRANT CREATE SYNONYM TO ora01; 12GRANT CREATE ROLE TO ora01; 13GRANT CREATE VIEW TO ora01; 14PROMPT 15PROMPT "ora01" 's DATA Creating... 16CONNECT ora01/oracle 17CREATE TABLE departments 18 (deptno NUMBER(2) CONSTRAINT pk_dept PRIMARY KEY, 19 dname VARCHAR2(14) , 20 loc VARCHAR2(10) ) ; 21CREATE TABLE employees 22 (empno NUMBER(4) CONSTRAINT pk_emp PRIMARY KEY, 23 ename VARCHAR2(10), 24 yomi VARCHAR2(20), 25 job VARCHAR2(8), 26 mgr NUMBER(4), 27 hiredate DATE, 28 sal NUMBER(7), 29 comm NUMBER(7), 30 deptno NUMBER(2) CONSTRAINT fk_deptno REFERENCES departments(deptno)); 31INSERT INTO departments VALUES 32 (10,'管理','大手町'); 33INSERT INTO departments VALUES 34 (20,'研究開発','横浜'); 35INSERT INTO departments VALUES 36 (30,'営業','品川'); 37INSERT INTO departments VALUES 38 (40,'財務','東京'); 39INSERT INTO employees VALUES 40 (1001,'佐藤','sato','社長',NULL,to_date('2001-02-25','yyyy-mm-dd'),500000,NULL,10); 41INSERT INTO employees VALUES 42 (1002,'鈴木','suzuki','事務',1013,to_date('2000-03-26','yyyy-mm-dd'),200000,NULL,20); 43INSERT INTO employees VALUES 44 (1003,'高橋','takahashi','営業',1007,to_date('2000-05-30 ','yyyy-mm-dd'),300000,30000,30); 45INSERT INTO employees VALUES 46 (1004,'田中','tanaka','営業',1007,to_date('2002-06-02','yyyy-mm-dd'),355000,50000,30); 47INSERT INTO employees VALUES 48 (1005,'渡辺','watanabe','部長',1001,to_date('2002-07-11','yyyy-mm-dd'),280000,NULL,20); 49CREATE TABLE salgrades 50 ( grade CHAR(1) CONSTRAINT pk_grade PRIMARY KEY, 51 losal NUMBER(7), 52 hisal NUMBER(7)); 53INSERT INTO salgrades VALUES ('A',100000,190000); 54INSERT INTO salgrades VALUES ('B',190001,280000); 55INSERT INTO salgrades VALUES ('C',280001,370000); 56INSERT INTO salgrades VALUES ('D',370001,460000); 57INSERT INTO salgrades VALUES ('E',460001,999999); 58CREATE TABLE customers 59 (custno NUMBER(5) CONSTRAINT cust_pk PRIMARY KEY, 60 cname VARCHAR2(20), 61 address VARCHAR2(30), 62 phone VARCHAR2(12), 63 credit_rating VARCHAR2(6)); 64INSERT INTO customers VALUES (1000,'品川商事','東京都港区1-x-x','03-1234-xxxx','優良'); 65INSERT INTO customers VALUES (1001,'横浜商店','横浜市磯子区2-x-x','045-753-xxxx','要注意'); 66INSERT INTO customers VALUES (1002,'川口や','川口市本町1-x-xx','048-336-xxxx','要注意'); 67INSERT INTO customers VALUES (1003,'○×商店','横浜市鶴見区2-xx','045-505-xxxx','良'); 68INSERT INTO customers VALUES (1004,'川崎ストア','川崎市川崎区10-xx','044-567-xxxx','優良'); 69CREATE TABLE products 70 (PRODNO CHAR(3) CONSTRAINT PROD_PK PRIMARY KEY, 71 PNAME VARCHAR2(30), 72 PRICE NUMBER(6)); 73INSERT INTO products VALUES ('A01','100円ボールペン',100); 74INSERT INTO products VALUES ('A02','芯強シャープペンシル',100); 75INSERT INTO products VALUES ('A03','10色ボールペン',300); 76INSERT INTO products VALUES ('A04','最高級万年筆',1000); 77INSERT INTO products VALUES ('A05','なないろ鉛筆',30); 78REATE TABLE orders 79 (ordno NUMBER(8) CONSTRAINT ORD_PK PRIMARY KEY, 80 custno NUMBER(5) CONSTRAINT ORD_CUST_FK REFERENCES customers(CUSTNO), 81 date_ordered DATE, 82 date_shipped DATE, 83 salesman_no NUMBER(4) CONSTRAINT ord_emp_fk REFERENCES employees(empno), 84 payment_type VARCHAR2(10)); 85INSERT INTO orders VALUES (1,1001,'2009-12-20','2009-12-27',1003,'クレジット'); 86INSERT INTO orders VALUES (2,1001,'2009-12-21','2009-12-27',1003,'クレジット'); 87INSERT INTO orders VALUES (3,1001,'2010-01-10','2010-01-17',1003,'クレジット'); 88INSERT INTO orders VALUES (4,1002,'2010-01-11','2010-01-18',1010,'クレジット'); 89INSERT INTO orders VALUES (5,1008,'2010-01-15','2010-01-22',1003,'クレジット'); 90CREATE TABLE ord_details 91 (ordno NUMBER(8) CONSTRAINT ord_det_ord_fk REFERENCES orders(ordno), 92 prodno CHAR(3) CONSTRAINT ord_det_prod_fk REFERENCES products(prodno), 93 quantity NUMBER(5), 94 CONSTRAINT ord_det_pk PRIMARY KEY(ordno,prodno)); 95INSERT INTO ord_details VALUES (1,'A02',30); 96INSERT INTO ord_details VALUES (1,'C01',20); 97INSERT INTO ord_details VALUES (2,'B01',5); 98INSERT INTO ord_details VALUES (2,'B06',10); 99INSERT INTO ord_details VALUES (2,'B02',10); 100SPOOL off
文字化けしているのをediterで開きUTF-8からShift JISへエンコードを変更しました。
回答2件
あなたの回答
tips
プレビュー