If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Oracle Store Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-21-11, 04:48
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
Oracle Store Procedure

I have created this store proc:

create or replace PROCEDURE INSERT_TESTTABLE
(
PrimaryKey IN NUMBER
,One IN VARCHAR2
,Two IN VARCHAR2
,Three IN VARCHAR2
,Four IN VARCHAR2
,Five IN VARCHAR2
)
AS

BEGIN

INSERT INTO TestTable
(
PrimaryKey,
One,
Two,
Three,
Four,
Five
)

VALUES
(
1234,
irstValue,
SecondValue,
ThirdValue,
FourthValue,
FithValue
);

NULL;

END INSERT_TESTTABLE;

And I get this error: Error(15,13): PL/SQL: ORA-00942: table or view does not exist

Any one can help I think there's something I get wrong that I can't see.
Reply With Quote
  #2 (permalink)  
Old 11-21-11, 04:50
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by stahorse1 View Post
Any one can help I think there's something I get wrong that I can't see.
Here is a hint: "table or view does not exist"
Reply With Quote
  #3 (permalink)  
Old 11-21-11, 05:06
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

That's the thing because TestTable does exist, which is my Table
Reply With Quote
  #4 (permalink)  
Old 11-21-11, 05:21
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by stahorse1 View Post
That's the thing because TestTable does exist
Apparently not...
Reply With Quote
  #5 (permalink)  
Old 11-21-11, 05:31
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

I don't know if you have went through my code, you will notice that there is:

INSERT INTO TestTable
(
PrimaryKey,
One,
Two,
Three,
Four,
Five
)
Reply With Quote
  #6 (permalink)  
Old 11-21-11, 05:38
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Quote:
Originally Posted by stahorse1 View Post
I don't know if you have went through my code
Yes I did.


Quote:
you will notice that there is:

INSERT INTO TestTable
(
PrimaryKey,
One,
Two,
Three,
Four,
Five
)
That's where the error comes from

An INSERT statement does not create a table, it inserts into an existing one.

Did you run the approriate CREATE TABLE before you created the procedure?
Reply With Quote
  #7 (permalink)  
Old 11-21-11, 05:54
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

Yes I have, here's my .sql script:

CREATE TABLE "TestTable"(
"PrimaryKey" Integer NOT NULL,
"One" Varchar2(30 ),
"Two" Varchar2(30 ),
"Three" Varchar2(30 ),
"Four" Varchar2(30 ),
"Five" Varchar2(30 )
)
Reply With Quote
  #8 (permalink)  
Old 11-21-11, 06:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,453
Quote:
Originally Posted by stahorse1 View Post
That's the thing because TestTable does exist, which is my Table
"TestTable" may exist, but you are inserting into "TESTTABLE" - unquoted identifiers are implicitly converted to upper case (that concerns column names as well).
Reply With Quote
  #9 (permalink)  
Old 11-21-11, 06:56
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

So far thanks for your help,

Now I converted everything to upper case to avoid anything;


create or replace PROCEDURE INSERT_TESTTABLE
(
PRIMARYKEY IN NUMBER
, ONE IN VARCHAR2
, TWO IN VARCHAR2
, THREE IN VARCHAR2
, FOUR IN VARCHAR2
, FIVE IN VARCHAR2
)
AS
BEGIN

INSERT INTO TESTTABLE
(
PRIMARYKEY,
ONE,
TWO,
THREE,
FOUR,
FIVE
)

VALUES
(
1234,
firstValue,
SecondValue,
ThirdValue,
FourthValue,
FithValue
);

NULL;
END INSERT_TESTTABLE;

And I sit with this error: Error(30,15): PL/SQL: ORA-00984: column not allowed here
Reply With Quote
  #10 (permalink)  
Old 11-21-11, 08:20
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
What are FIRSTVALUE, SECONDVALUE, ... identifiers in VALUES clause?
Procedure parameters are named ONE, TWO, ...
The same names are used for table column.

Just one recommendation: do not use the same name for procedure parameter and table column name. If doing so, you must be very careful with identifying the scope. E.g. the expression
Code:
WHERE one = one
would compare column ONE with itself, so it would be equivalent to
Code:
WHERE one is not null
Prefixing it with table/procedure name would help, but it is quite inconvenient to keep it in mind and use it in whole code.

Below are some articles about naming convention. As I am not aware of any "standard" one for Oracle, I will let on you to pick the most suitable one for you (or just search anywhere else):
http://ss64.com/ora/syntax-naming.html
http://www.oracle-base.com/articles/...onventions.php
Reply With Quote
  #11 (permalink)  
Old 11-22-11, 01:34
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

Thanks

firstvalue to firth are data I insert in the database


CREATE OR REPLACE PROCEDURE NEWPROC
(
PRIMARYKEY IN NUMBER
, ONE IN VARCHAR2
, TWO IN VARCHAR2
, THREE IN VARCHAR2
, FOUR IN VARCHAR2
, FIVE IN VARCHAR2
)
AS
BEGIN

INSERT INTO TESTTABLE
(
PRIMARYKEY,
ONE,
TWO,
THREE,
FOUR,
FIVE
)

VALUES
(
1234,
firstvalue,
secondvalue,
thirdvalue,
fouthvalue,
firthvalue
);

NULL;
END NEWPROC;
Reply With Quote
  #12 (permalink)  
Old 11-22-11, 02:01
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by stahorse1 View Post
firstvalue to firth are data I insert in the database
Maybe in your real code, but not in those pseudo ones you are posting here.
There is a difference between an identifier (FIRSTVALUE) and a character literal ('FIRSTVALUE').

I am sorry that I (and probably most members here) cannot debug the imaginary code. Maybe you should enhance your skill for doing it by studying Oracle documentation, which is available e.g. online on http://tahiti.oracle.com/ SQL Language Reference and PL/SQL User's Guide and Reference are good enough for the PL/SQL syntax and language elements.

Good luck.
Reply With Quote
  #13 (permalink)  
Old 11-22-11, 02:30
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

Ohk Thanks I will. Cause this is my first project using oracle

I changed FIRSTVALUE to firstvalue. this code below is what I have now:

CREATE OR REPLACE PROCEDURE NEWPROC
(
PRIMARYKEY IN NUMBER
, ONE IN VARCHAR2
, TWO IN VARCHAR2
, THREE IN VARCHAR2
, FOUR IN VARCHAR2
, FIVE IN VARCHAR2
)
AS
BEGIN

INSERT INTO TESTTABLE
(
PRIMARYKEY,
ONE,
TWO,
THREE,
FOUR,
FIVE
)

VALUES
(
1234,
firstvalue,
secondvalue,
thirdvalue,
fouthvalue,
firthvalue
);

NULL;
END NEWPROC;
Reply With Quote
  #14 (permalink)  
Old 11-22-11, 02:31
stahorse1 stahorse1 is offline
Registered User
 
Join Date: Nov 2011
Posts: 13
reply

Ohk Thanks I will. Cause this is my first project using oracle

I changed FIRSTVALUE to firstvalue. this code below is what I have now:

CREATE OR REPLACE PROCEDURE NEWPROC
(
PRIMARYKEY IN NUMBER
, ONE IN VARCHAR2
, TWO IN VARCHAR2
, THREE IN VARCHAR2
, FOUR IN VARCHAR2
, FIVE IN VARCHAR2
)
AS
BEGIN

INSERT INTO TESTTABLE
(
PRIMARYKEY,
ONE,
TWO,
THREE,
FOUR,
FIVE
)

VALUES
(
1234,
firstvalue,
secondvalue,
thirdvalue,
fouthvalue,
firthvalue
);

NULL;
END NEWPROC;

And get this error: Error(30,15): PL/SQL: ORA-00984: column not allowed here
Reply With Quote
  #15 (permalink)  
Old 11-22-11, 02:35
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by stahorse1 View Post
Ohk Thanks I will. Cause this is my first project using oracle
You really should, especially the asic parts about language elements.
I already posted here, so once again (and last):
FIRSTVALUE, firstvalue, FirstValue etc. are identifiers (variable, table column, whatever), they are not data
'FIRSTVALUE', 'firstvalue', 'FirstValue' etc. (note the single quotes around) are string literals, so they are treated as data.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On