Solved

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

Posted on 2016-10-23
6
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC in excel 2016 in Windows 10 via VBA 16 387
Fill Null values 5 52
Deleting multiple child tables from parent in one SQL statement 20 55
Oracle Join issue. 3 45
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…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup

737 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