Solved

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

Posted on 2016-10-23
6
47 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 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle query output question 4 43
Oracle SQL Select unique values from two columns 4 53
Component is listed with a Protocol more than once 3 29
Oracle dataguard 5 31
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

773 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