Creating Multiple tables in Oracle [duplicate] - oracle

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Creating Multiple table in Oracle
I am using Oracle Express 10g and I'm enter the following text to create 2 tables in the sql command line, but it is not working.
CREATE TABLE student (
matric_no VARCHAR2(8),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
date_of_birth DATE
);
CREATE TABLE student1 (
matric_no VARCHAR2(8),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
date_of_birth DATE
);
Can anyone see what I am doing wrong.
The error messgae I get is:
ORA-00911: invalid character
Thanks

Are you sure you didn't type this out in WORD?
Sometimes there are problems with "invisible" characters. For example if you hit TAB in WORD, it will store it as a special character which will thereby cause an error when you try running it in SQLPlus.

try to create the two tables separate. First one and then the other, and without semicolon:
CREATE TABLE student (
matric_no VARCHAR2(8),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
date_of_birth DATE
)

remove ";" when you are editing your query in notepad and then give a try

Related

'Error: ORA-01722: invalid number' when inserting into a table?

I'm very new to SQL and I am having trouble with an assignment that involves inserting records into a table. So far I have:
insert into show (show_id,production_company_id,
genre,name_of_show,mpaa_rating,feature_type) values
(1,1,'comedy','click','r','movie');
It keeps telling me the specified number is invalid and to specify a number but I don't know what that means since there is already a number there. I tried looking at other similar questions on the site, but most of them were a lot more complicated than what I have here. Thanks for any help.
edit: also, production_company_id is a foreign key if that helps at all.
here is the original table:
CREATE TABLE show (
SHOW_ID number(6,0) PRIMARY KEY,
PRODUCTION_COMPANY_ID NUMBER(6,0) NOT NULL REFERENCES PRODUCTION_COMPANY (PRODUCTION_COMPANY_ID),
GENRE VARCHAR(25),
NAME_OF_SHOW VARCHAR(25),
MPAA_RATING VARCHAR(25),
FEATURE_TYPE VARCHAR(25)
);
Please make sure that PRODUCTION_COMPANY_ID is defined as number in the table PRODUCTION_COMPANY, because in your table creation of show, production_company_id refers to that table.
If not, you can modify the column type like:
ALTER TABLE PRODUCTION_COMPANY
MODIFY PRODUCTION_COMPANY_ID number;
Or if you do not want to change the type of that column for some reason, you can try:
insert into show (show_id,production_company_id,
genre,name_of_show,mpaa_rating,feature_type) values
(1,'1','comedy','click','r','movie');

Special characters in Oracle table

I am trying to create table as below,
create table "customer`£`s"(customer_id number(10) not null,
UNIT VARCHAR2(50) not null,
city varchar2(50), constraint customers_pk PRIMARY KEY(customer_id));
But getting Invalid character error.
Can anyone help?
We are working on similar projects. I was able to create the table.

Is it possible to pre-define column data types?

When creating a table
Create table user(
username varchar2(30)
);
Is it possible to somewhere create a static or pre-defined data type?
short_name varchar2(30)
And then use this in the create table statement?
Create table user(
username short_name
);
Edit:
My initial thought was to build up and structure different varchar2 (and other data types) for easy reference when writing sql statements, example:
tiny_name varchar2(10)
short_name varchar2(30)
medium_name varchar2(60)
long_name varchar2(120)
The closest (I have seen so far) seems to be the use of TYPE, but that does not seem to cover what I am specifying in my question

Give name to existing constraint without dropping [duplicate]

This question already has answers here:
How to ADD a CONSTRAINT NAME to an already EXISTING CONSTRAINT
(2 answers)
Closed 5 years ago.
I'm learning ORACLE and create a table with different columns and constraint, Now I want to give a name to already created constraint without dropping the constraint. How I can give name to them? as I see there are couple of constraints in user_constraints table, but I don't know their name like(null, unique) and their column.
Again I want to give name to my existing constraints(which have default oracle created name like ( SYS_C0010392 ).
Here is query image that I used to create table with constraints.( SQLPLUS not allowing to copy the query that's why I add image )
ALTER TABLE dept RENAME CONSTRAINT SYS_C0010392 TO new_name;
And SQL*Plus is console application as any other so you definitely can copy selected text.
Column CDB/DBA/ALL/USER_CONSTRAINT.CONSTRAINT_TYPE describes the constraint type, see http://docs.oracle.com/cloud/latest/db121/REFRN/refrn20047.htm#REFRN20047.
Constraint name can be specified in CREATE TABLE command:
create table my_table (
col1 number
constraint my_table_col1_nn not null
constraint my_table_col1_uq unique
);
Column constraint association is available in CDB/DBA/ALL/USER_CONS_COLUMNS:
SELECT * FROM ALL_CONS_COLUMNS WHERE CONSTRAINT_NAME = 'SYS_C0010392'

How to Create a Foreign Key from a Table to a Custom Datatype

Working with Oracle Express 11g, learning the interactions for object-relational databases.
Running into trouble while trying to create a foreign key from a normal table, to a table of a custom object (customers)
The customer object is as follows (customer_id NUMBER, fname VARCHAR2, lname VARCHAR2), for our setup, we wish to join a table Applications via customer_id NUMBER. Within the SQL Workshop, selecting the customers table is not even an option, and we cannot find syntax to manually create this relationship.
Any experts have some clues to help figure this one out?
create or replace type customer is object
(
customer_id NUMBER,
fname VARCHAR2(100),
lname VARCHAR2(100)
);
/
create table customers of customer
(
constraint customer_pk primary key(customer_id)
);
create table applications
(
application_id number,
customer_id number,
constraint applications_fk1 foreign key (customer_id)
references customers(customer_id)
);

Resources