Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 111 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 475 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Issues with procedure!

Hi, Can someone help me understand whats wrong with my procedure.
CREATE OR REPLACE procedure VALID_PROC( START_DATE IN DATE, END_DATE IN DATE) IS cursor c1 is SELECT * FROM EMP WHERE HIREDATE BETWEEN TO_DATE('01-01-85','DD-MM-YY') AND TO_DATE('01-01-80','DD-MM-YY'); c_row c1%rowtype; BEGIN OPEN C1; fetch c1 into c_row; if c1%notfound then endif; INSERT INTO emp_back(empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES(c_row.empno,c_row.ename,c_row.job,c_row.hiredate,c_row.sal,c_row.comm,c_row.deptno); commit; close c1; END; /
Answers
-
Hi,
That depends on what "wrong" means to you. What is the procedure supposed to do? What is it doing differently?
Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the exact results you want from that data, so that the people who want to help you can re-create the problem and test their ideas. (If you're using the Oracle-supplied scott.emp table, you don't need to post CREATE TABLE and INSERT statements for it; just make it clear what you're doing.)
If you're asking about a DML operation, such as UPDATE, then the INSERT statements you post should show what the tables are like before the DML, and the results will be the contents of the changed table after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
You're using 2-digit years; that's always a mistake,
-
Try to spot the difference with this:
CREATE OR REPLACE procedure VALID_PROC( START_DATE IN DATE, END_DATE IN DATE)
is
begin
insert into emp_back(empno,ename,job,mgr,hiredate,sal,comm,deptno)
select c_row.empno,c_row.ename,c_row.job,c_row.hiredate,c_row.sal,c_row.comm,c_row.deptno
from emp c_row
where hiredate between start_date and end_date;
end;
It might give you a clue to what's wrong with your procedure
-
ooh - exclamation point in the title, must be important.
First, before I even read your procedure - why do you think there is something wrong with it? Did you get an error? If so, why didn't you tell us?
Secondly, there are lot's of problems...
1). Why are you using 2 digits to represent a year?
2). You just blindly skip over the case if there is no record found
3). You don't use the parameters you passed in
4). Committing inside a stored procedure is often not the right thing to do
5). Using PL/SQL when you didn't need to
6). Not processing all of the rows in the cursor (assuming that was your intent)
There may be more, but those jumped right to mind
-
Hi John, I do get a lot of errors. First i tried using dynamic values which didn't work and hence tried static dates.
CREATE OR REPLACE procedure VALID_PROC( START_DATE IN DATE, END_DATE IN DATE) IS cursor c1 is SELECT * FROM EMP WHERE HIREDATE BETWEEN TO_DATE(START_DATE,'DD-MM-YY') AND TO_DATE(END_DATE,'DD-MM-YY'); c_row c1%rowtype; BEGIN OPEN C1; fetch c1 into c_row; if c1%notfound then endif; INSERT INTO emp_back(empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES(c_row.empno,c_row.ename,c_row.job,c_row.hiredate,c_row.sal,c_row.comm,c_row.deptno); commit; close c1; END; /
And i tried
select TO_DATE('01-01-80','DD-MM-YY') from dual;
which gives me date. So not sure what you meant by "2 digits to represent a year".
-
Hi Frank, My apologies, will surely follow instructions. I was trying to create a procedure which inserts values based on 2 dates. I'm using oracle scott.emp data.
-
Thanks Ascheffer! That helps. However the validation fails and still gives errors when i try and complile.
-
- select TO_DATE('01-01-80','DD-MM-YY') from dual;
will give a date in 2080. Probably not what you want
-
Hi,
user782973-Oracle wrote: Thanks Ascheffer! That helps. However the validation fails and still gives errors when i try and complile.
Don't you think it would be helpful to say what the errors are?
-
No need, I'm very good at guessing:
endif should be end if;
PLS-00103: Encountered the symbol ";" when expecting one of the following:
if
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:And if you fixed that you wil get
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <een ID>
<een scheidingsteken-ID tussen dubbele aanhalingstekens>
<een bindvariabele> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:because you forgot to put a statement after your if clause:
-
user782973-Oracle wrote: ... And i tried
- select TO_DATE('01-01-80','DD-MM-YY') from dual;
select TO_DATE('01-01-80','DD-MM-YY') from dual;
which gives me date. So not sure what you meant by "2 digits to represent a year".
It means using a string like '01-01-80', where only 2 digits (e.g. '8' and '0') are supposed to indicate the year.
The trouble with 2-digit years is that you can easily get confused by 2 different years (in different centuries) having the same last 2 digits. For example, the table might have data from 1980, but your procedure might be looking for data from 2080.