Solved

Error when running a simple alter statement in Aqua studio for Oracle

Posted on 2016-10-23
6
56 Views
Last Modified: 2016-10-24
I am using Aqua Studio, and am trying to create a new column in a database table. I have tried using both of the alter statements
below, but when I run them  I get this error message:

> Script lines: 1-1 -----------------------
ORA-00904: Invalid Identifier
Script line 1, statement  line 1, column 44

-- Sql I have tried

ALTER TABLE CUSTOMERS ADD 'PHONE_NUMBER' VARCHAR(50) NULL

ALTER TABLE CUSTOMERS ADD COLUMN 'PHONE_NUMBER' VARCHAR(50) NULL
0
Comment
Question by:brgdotnet
6 Comments
 
LVL 23

Accepted Solution

by:
David earned 300 total points
ID: 41856490
ALTER TABLE CUSTOMERS ADD PHONE_NUMBER VARCHAR2(50) NULL
/

I removed the single quotes.

Secondly, I altered your VARCHAR to VARCHAR2. From http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm#i45721 :
"Do not use the VARCHAR datatype. Use the VARCHAR2 datatype instead. Although the VARCHAR datatype is currently synonymous with VARCHAR2, the VARCHAR datatype is scheduled to be redefined as a separate datatype used for variable-length character strings compared with different comparison semantics."

Thirdly, what kind of a business rule requires a telephone number of 50 characters? Any telephone value should be stored without formatting, which you probably know. If that's news, the best practice is to always let the application parse the output. That way the customer can choose to view (555) 555-1212, or 555.555.1212, or whatever the local preference is. Country code, phone extension are separate values distinct from the phone number. If you are dealing with domestic phone numbers, I strongly encourage you to switch to VARCHAR2(10) instead.
2
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 200 total points
ID: 41856493
great answer David

just adding that not only should you avoid single quotes, but you should also avoid double quotes when defining tables/columns in Oracle

i.e. this is allowed:
      ALTER TABLE CUSTOMERS ADD "PHONE_NUMBER" VARCHAR2(50) NULL

BUT:
          if you were to to this the column name becomes case sensitive

far better to do as David suggests, just define the column with no quotes at all.

nb: no points please.
1
 
LVL 2

Author Comment

by:brgdotnet
ID: 41856504
Thank you gentlemen. I also have a question for the both of you. If I have to run several alter commands
in Aqua studio, do I need to separate them with some type of dlimiter? For some reason
I can run each alter statement one at a time, but not all at one time, like in sql server?

     ALTER TABLE CUSTOMERS ADD "PHONE_NUMBER" VARCHAR2(10) NULL

     ALTER TABLE CUSTOMERS ADD "Geneder" VARCHAR2(1) NULL

     ALTER TABLE CUSTOMERS ADD "Age" VARCHAR2(3) NULL
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:David
ID: 41856532
Search for syntax examples. Here you would have

Alter table customers
add
  ( column1 blah,
   column2 blah,
   and so forth )
/

1. Ditch the quote marks. Case sensitive means a query using "select age..." would fail.
2. Amaze your family and friends. Add range constraints to your column definitions. For example, let the database know that the phone number field must be numeric
Or, that age must be numeric, between two boundaries, such as zero to 120.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41856571
yes, use a comma delimiter

ditch the quotes!!!!!!!!!!!!!!!!! well said. That is what I tried to convey earlier; do NOT use quotes when defining columns, they become case sensitive and a pain to remember.

no points pl
0
 
LVL 32

Expert Comment

by:awking00
ID: 41856924
Just an observation - Do you really want a column for age that would require annual updates to be current? It might be better to use something like date_of_birth.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question