473,408 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Newbie PL/SQL Question - Inserting into a table from a stored procedure

Hello,

I'm just starting to learn PL/SQL. To get my feet wet,
I'm trying to write a simple stored procedure that takes some
values as parameters, and inserts those values into a table.
For some reason my simple procedure is not working, I'm
probably missing something simple. Here is how I'm trying to
create this procedure:

CREATE OR REPLACE PROCEDURE insert_person(uid IN NUMBER,
first_nm IN VARCHAR,
middle_nm IN VARCHAR,
last_nm IN VARCHAR) IS
BEGIN
INSERT INTO PERSONS (prsn_uid, prsn_first_nm, prsn_middle_nm,
prsn_last_nm) values (uid, first_nm, middle_nm,
last_nm);
END insert_person;

I'm not sure this is relevant, but I'm typing the above
declaration into an Java based SQL client called SquirrelSQL
(http://sourceforge.net/projects/squirrel-sql/), the
output I get after executing the above is:

Warning: Warning: execution completed with warning
SQLState: null
ErrorCode: 17110
0 Rows Updated
Query 1 elapsed time (seconds) - Total: 0.053, SQL query: 0.053,
Building output: 0
Error: java.sql.SQLException: ORA-00900: invalid SQL statement

Can anyone please point out what is wrong with the above
procedure?

Thanks,
Eraser
Jun 27 '08 #1
2 10117
There doesn't seem to be nothing wrong with your statement.
It might be the way SquirrelSQL interprets it.

Alex Ivascu
"Eraser" <er****@nospam.comwrote in message
news:pa****************************@nospam.com...
Hello,

I'm just starting to learn PL/SQL. To get my feet wet,
I'm trying to write a simple stored procedure that takes some
values as parameters, and inserts those values into a table.
For some reason my simple procedure is not working, I'm
probably missing something simple. Here is how I'm trying to
create this procedure:

CREATE OR REPLACE PROCEDURE insert_person(uid IN NUMBER,
first_nm IN VARCHAR,
middle_nm IN VARCHAR,
last_nm IN VARCHAR) IS
BEGIN
INSERT INTO PERSONS (prsn_uid, prsn_first_nm, prsn_middle_nm,
prsn_last_nm) values (uid, first_nm, middle_nm,
last_nm);
END insert_person;

I'm not sure this is relevant, but I'm typing the above
declaration into an Java based SQL client called SquirrelSQL
(http://sourceforge.net/projects/squirrel-sql/), the
output I get after executing the above is:

Warning: Warning: execution completed with warning
SQLState: null
ErrorCode: 17110
0 Rows Updated
Query 1 elapsed time (seconds) - Total: 0.053, SQL query: 0.053,
Building output: 0
Error: java.sql.SQLException: ORA-00900: invalid SQL statement

Can anyone please point out what is wrong with the above
procedure?

Thanks,
Eraser

Jun 27 '08 #2
try running from a simple sql*plus window to test: I just rana quick test
with your code and it worked:

SQLcreate table PERSONS
2 (
3 prsn_uid NUMBER,
4 prsn_first_nm VARCHAR2(20),
5 prsn_middle_nm VARCHAR2(20),
6 prsn_last_nm VARCHAR2(20)
7 );

Table created.

SQLCREATE OR REPLACE PROCEDURE insert_person(uid IN NUMBER,
2 first_nm IN VARCHAR,
3 middle_nm IN VARCHAR,
4 last_nm IN VARCHAR) IS
5 BEGIN
6 INSERT INTO PERSONS (prsn_uid, prsn_first_nm, prsn_middle_nm,
7 prsn_last_nm) values (uid, first_nm, middle_nm,
8 last_nm);
9 END insert_person;
10 /

Procedure created.

SQLset serveroutput on
SQLexec insert_person(1,'first', 'middle', 'last');

PL/SQL procedure successfully completed.

SQLCOMMIT;

Commit complete.

SQLselect * from persons;

PRSN_UID PRSN_FIRST_NM PRSN_MIDDLE_NM PRSN_LAST_NM
---------- -------------------- -------------------- --------------------
1 first middle last

SQL>
..................
I created a simple table based on your procedure, but it might be different.
--you should also look at adding exception handling in your procedure, such
as below:
CREATE OR REPLACE PROCEDURE insert_person
(
uid IN NUMBER,
first_nm IN VARCHAR,
middle_nm IN VARCHAR,
last_nm IN VARCHAR) IS
BEGIN
INSERT INTO PERSONS (prsn_uid, prsn_first_nm, prsn_middle_nm,
prsn_last_nm) values (uid, first_nm, middle_nm,
last_nm);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE ('Errors found: '||SQLERRM);
END insert_person;
/

who owns the table, who's calling the procedure: do you have privs? are
there public/private synonymns?
easiet way to debug is go to the basics: sqlplus. try inserting into the
table with the same user you are running from the java, then try the
procedure, etc....

"Eraser" <er****@nospam.comwrote in message
news:pa****************************@nospam.com...
Hello,

I'm just starting to learn PL/SQL. To get my feet wet,
I'm trying to write a simple stored procedure that takes some
values as parameters, and inserts those values into a table.
For some reason my simple procedure is not working, I'm
probably missing something simple. Here is how I'm trying to
create this procedure:

CREATE OR REPLACE PROCEDURE insert_person(uid IN NUMBER,
first_nm IN VARCHAR,
middle_nm IN VARCHAR,
last_nm IN VARCHAR) IS
BEGIN
INSERT INTO PERSONS (prsn_uid, prsn_first_nm, prsn_middle_nm,
prsn_last_nm) values (uid, first_nm, middle_nm,
last_nm);
END insert_person;

I'm not sure this is relevant, but I'm typing the above
declaration into an Java based SQL client called SquirrelSQL
(http://sourceforge.net/projects/squirrel-sql/), the
output I get after executing the above is:

Warning: Warning: execution completed with warning
SQLState: null
ErrorCode: 17110
0 Rows Updated
Query 1 elapsed time (seconds) - Total: 0.053, SQL query: 0.053,
Building output: 0
Error: java.sql.SQLException: ORA-00900: invalid SQL statement

Can anyone please point out what is wrong with the above
procedure?

Thanks,
Eraser

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan Caron | last post by:
I have to create a stored procedure to purge "x" # of records from a table. I have two tables (script below): Schedule ScheduleHistory I need to purge records out of ScheduleHistory. The...
2
by: Daniel | last post by:
hi ng, i am newbie to sqlserver and my problem seems simple, but i didn't find information about it: How can i display the RETURN @x value of a stored procedure in the sql analyzer of the...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
1
by: ILCSP | last post by:
Hello, I'm trying to accomplish 3 things with one stored procedure. I'm trying to search for a record in table X, use the outcome of that search to insert another record in table Y and then exec...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
13
by: Bangaru | last post by:
How do i view the code in stored procedure?what permission should I have for it. Also how do I get the list of tables in the DB?
6
by: BostonNole | last post by:
I am using SQL 2000 and VB.NET (VS 2005). I have three stored procedure: sp_A, sp_B and sp_C I need to be able to call sp_A once and sp_B and sp_C 1 to n number of times all within a single...
3
by: Constantine AI | last post by:
Hi we have created a stored procedure to check the dates entered into a lease table does not overlap dates already stored for a lease. However when inserting overlapping lease dates, it allows us to...
2
by: IuliaS | last post by:
Hello everyone! I want to create a stored procedure, so I can more easily, and transparent retrieve data from db2. Long story short: when a user wants to put some data in the DB, he also creates...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.