Solved

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

Posted on 2016-10-23
6
34 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 31

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now