?
Solved

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

Posted on 2016-10-23
6
Medium Priority
?
69 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 1200 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 49

Assisted Solution

by:PortletPaul
PortletPaul earned 800 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
Industry Leaders: 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 49

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

777 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