Hi all,
First of all let me admit that I have hardly any SQL knowledge, so I might be making very silly mistakes ;-)
I've configured some triggers (with the help of some templates etc.), which will insert a record in a table with events, as soon as a record is inserted/updated. The event-table will be used by an external process to synchronise data.
This works and I've tested it extensively.
Now the only thing I require is a statement that will be used only once, to start the initial synchronisation. I want to select all records in a table, and for each record, I want to insert a record into my event-table. If I can run it from Toad, it'll be more than sufficient.
This is what I have come up with: -
-
CURSOR c is SELECT * FROM prig_own.dpic300;
-
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_process
-
(
-
record_id,
-
table_key,
-
event_type,
-
event_time,
-
table_name
-
)
-
VALUES
-
(
-
idmdirect.seq_log_record_id.nextval,
-
('pk_DienstverbandID=' || REPLACE(r.object_ID,' ', '')),
-
6,
-
sysdate,
-
'view_dienstverband'
-
);
-
-
END LOOP;
-
COMMIT;
-
-
END;
-
-
I'm getting bombarded with "invalid syntax" and errors stating that a different character is expect instead of c (my cursor)
This is oracle 9i, which makes using FORALL and BULK COLLECTION impossible (I think?!)
Thx in advance!
Kind regards,
Kees
11 4213
Hi all,
First of all let me admit that I have hardly any SQL knowledge, so I might be making very silly mistakes ;-)
I've configured some triggers (with the help of some templates etc.), which will insert a record in a table with events, as soon as a record is inserted/updated. The event-table will be used by an external process to synchronise data.
This works and I've tested it extensively.
Now the only thing I require is a statement that will be used only once, to start the initial synchronisation. I want to select all records in a table, and for each record, I want to insert a record into my event-table. If I can run it from Toad, it'll be more than sufficient.
This is what I have come up with: -
-
CURSOR c is SELECT * FROM prig_own.dpic300;
-
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_process
-
(
-
record_id,
-
table_key,
-
event_type,
-
event_time,
-
table_name
-
)
-
VALUES
-
(
-
idmdirect.seq_log_record_id.nextval,
-
('pk_DienstverbandID=' || REPLACE(r.object_ID,' ', '')),
-
6,
-
sysdate,
-
'view_dienstverband'
-
);
-
-
END LOOP;
-
COMMIT;
-
-
END;
-
-
I'm getting bombarded with "invalid syntax" and errors stating that a different character is expect instead of c (my cursor)
This is oracle 9i, which makes using FORALL and BULK COLLECTION impossible (I think?!)
Thx in advance!
Kind regards,
Kees
Use DECLARE keyword before your cursor.
There are three sections in plsql block:
Declare - Optional (If you have any variable,cursor the be declared, then use this section)
Begin - Mandatory
EXCEPTION - Optional (To Handle Exceptions)
Why not use FORALL BULK INSERT in Oracle 9i? Oracle 9i very well supports this concepts.
Use DECLARE keyword before your cursor.
There are three sections in plsql block:
Declare - Optional (If you have any variable,cursor the be declared, then use this section)
Begin - Mandatory
EXCEPTION - Optional (To Handle Exceptions)
Why not use FORALL BULK INSERT in Oracle 9i? Oracle 9i very well supports this concepts.
I'm a bit at a loss... I thought I was using declare to declare the cursor? If I try and create a "normal" stored procedure, like one I have working, I just get a ORA-00900, invalid SQL Syntax.
I realise that me lacking basic knowledge is probably the problem here, but could you point a bit further in the right direction? -
CREATE OR REPLACE PROCEDURE
-
"IDMDIRECT"."PROC_FULLSYNC_DIENSTVERBAND" AS
-
CURSOR c is SELECT * FROM prig_own.dpic300;
-
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_process
-
(
-
record_id,
-
table_key,
-
event_type,
-
event_time,
-
table_name
-
)
-
VALUES
-
(
-
idmdirect.seq_log_record_id.nextval,
-
('pk_DienstverbandID=' || REPLACE(r.object_ID,' ', '')),
-
6,
-
sysdate,
-
'view_dienstverband'
-
);
-
-
END LOOP;
-
COMMIT;
-
-
END;
-
Regarding the FORALL BULK INSERT, I googled across some codesamples, which didn't seem to work for me. Another poster had the same problems, which (in the messageboard's opinion) was the result of using Oracle <10.
In my case it doesn't really matter, since I just need to run it once, to create an initial starting point :D
I'm a bit at a loss... I thought I was using declare to declare the cursor? If I try and create a "normal" stored procedure, like one I have working, I just get a ORA-00900, invalid SQL Syntax.
I realise that me lacking basic knowledge is probably the problem here, but could you point a bit further in the right direction? -
CREATE OR REPLACE PROCEDURE
-
"IDMDIRECT"."PROC_FULLSYNC_DIENSTVERBAND" AS
-
CURSOR c is SELECT * FROM prig_own.dpic300;
-
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_process
-
(
-
record_id,
-
table_key,
-
event_type,
-
event_time,
-
table_name
-
)
-
VALUES
-
(
-
idmdirect.seq_log_record_id.nextval,
-
('pk_DienstverbandID=' || REPLACE(r.object_ID,' ', '')),
-
6,
-
sysdate,
-
'view_dienstverband'
-
);
-
-
END LOOP;
-
COMMIT;
-
-
END;
-
Regarding the FORALL BULK INSERT, I googled across some codesamples, which didn't seem to work for me. Another poster had the same problems, which (in the messageboard's opinion) was the result of using Oracle <10.
In my case it doesn't really matter, since I just need to run it once, to create an initial starting point :D
Do you have SELECT privilege on the table that you are trying to select from?
Run your sql query of your cursor in TOAD/sql plus and check if it fetches data for you or display error?
Do you have SELECT privilege on the table that you are trying to select from?
Run your sql query of your cursor in TOAD/sql plus and check if it fetches data for you or display error?
I explicitly granted it to the user-object, and running the query through toad gives me fine results.
This script is provided by Novell, the manifacturer of the synchronisation software IDM. -
CREATE PROCEDURE idmdirect.proc_eventlog
-
AS
-
CURSOR c is SELECT * FROM idmdirect.event_process
-
WHERE status != 'N' FOR UPDATE;
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_processed
-
VALUES
-
(
-
r.record_id,
-
r.table_key,
-
r.status,
-
r.event_type,
-
r.event_time,
-
r.perpetrator,
-
r.table_name,
-
r.column_name,
-
r.old_value,
-
r.new_value
-
);
-
DELETE FROM idmdirect.event_process
-
WHERE CURRENT OF c;
-
END LOOP;
-
COMMIT;
-
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_1 REBUILD ONLINE';
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_2 REBUILD ONLINE';
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_3 REBUILD ONLINE';
-
-
END proc_eventlog;
-
I am certain I used this before in other implementations, but running an EXECUTE idmdirect.proc_eventlog, now gives me the same ORA-00900, invalid syntax. I'm starting to wonder if anything else might be wrong.
I explicitly granted it to the user-object, and running the query through toad gives me fine results.
This script is provided by Novell, the manifacturer of the synchronisation software IDM. -
CREATE PROCEDURE idmdirect.proc_eventlog
-
AS
-
CURSOR c is SELECT * FROM idmdirect.event_process
-
WHERE status != 'N' FOR UPDATE;
-
BEGIN
-
FOR r IN c LOOP
-
INSERT INTO idmdirect.event_processed
-
VALUES
-
(
-
r.record_id,
-
r.table_key,
-
r.status,
-
r.event_type,
-
r.event_time,
-
r.perpetrator,
-
r.table_name,
-
r.column_name,
-
r.old_value,
-
r.new_value
-
);
-
DELETE FROM idmdirect.event_process
-
WHERE CURRENT OF c;
-
END LOOP;
-
COMMIT;
-
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_1 REBUILD ONLINE';
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_2 REBUILD ONLINE';
-
-- EXECUTE IMMEDIATE 'ALTER INDEX indirect.idx_indirectlog_3 REBUILD ONLINE';
-
-
END proc_eventlog;
-
I am certain I used this before in other implementations, but running an EXECUTE idmdirect.proc_eventlog, now gives me the same ORA-00900, invalid syntax. I'm starting to wonder if anything else might be wrong.
Quite Surprising to why that happened?
Your procedure looks fine.
Anyways, invalid syntax at line no ??
Quite Surprising to why that happened?
Your procedure looks fine.
Anyways, invalid syntax at line no ??
Very awkward.... it really is the CURSOR-line... -
CURSOR cursor1 IS SELECT * FROM prig_own.dpic300;
-
When I run this in toad, I still get a ORA-00900, invalid syntax. Just the SELECT-statement works fine :(
Very awkward.... it really is the CURSOR-line... -
CURSOR cursor1 IS SELECT * FROM prig_own.dpic300;
-
When I run this in toad, I still get a ORA-00900, invalid syntax. Just the SELECT-statement works fine :(
Which version of oracle yo uare running?
Which version of oracle yo uare running?
- SELECT * FROM v$version
-
WHERE banner LIKE 'Oracle%';
Oracle9i Release 9.2.0.1.0
- SELECT * FROM v$version
-
WHERE banner LIKE 'Oracle%';
Oracle9i Release 9.2.0.1.0
OK, I think I found my problem.
1) lack of knowledge, I tried to just execute the procedure, while I should have used something like: -
BEGIN
-
IDMDIRECT.PROC_FULLSYNC;
-
COMMIT;
-
END;
-
2) And my user didn't have permissions on the tablespace -
ALTER USER username QUOTA UNLIMITED on tablespace;
-
My eventtable is full and waiting full-sync! I'm happy :-)
Big thx for the help!
Both are same.:
1. EXECUTE proc_name
2. BEGIN proc_name; END;
Check This: -
-
SQL> select * from emp;
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
-
SQL> create or replace procedure a IS
-
2 BEGIN
-
3 INSERT INTO emp as SELECT * FROM EMP;
-
4 COMMIT;
-
5 END;
-
6 /
-
-
-
Procedure created.
-
-
SQL> EXECUTE a
-
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from emp;
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
a 1
-
am 2
-
-
SQL> BEGIN a; END;
-
2 /
-
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from emp;
-
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
a 1
-
am 2
-
a 1
-
am 2
-
a 1
-
am 2
-
-
8 rows selected.
-
-
SQL>
-
-
If you see in above example, I have used both the ways of calling procedure and it works fine.
Both are same.:
1. EXECUTE proc_name
2. BEGIN proc_name; END;
Check This: -
-
SQL> select * from emp;
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
-
SQL> create or replace procedure a IS
-
2 BEGIN
-
3 INSERT INTO emp as SELECT * FROM EMP;
-
4 COMMIT;
-
5 END;
-
6 /
-
-
-
Procedure created.
-
-
SQL> EXECUTE a
-
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from emp;
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
a 1
-
am 2
-
-
SQL> BEGIN a; END;
-
2 /
-
-
PL/SQL procedure successfully completed.
-
-
SQL> select * from emp;
-
-
ENAME EMPNO
-
-------------------- ----------
-
a 1
-
am 2
-
a 1
-
am 2
-
a 1
-
am 2
-
a 1
-
am 2
-
-
8 rows selected.
-
-
SQL>
-
-
If you see in above example, I have used both the ways of calling procedure and it works fine.
Using EXECUTE, I just got those general ORA-00900 errors. But when I used the Toad-UI (which does the begin procedure; end;), I got some more errors.
ORA-01536 was clear enough. And it works now.
Thx again for the help and your time!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mark |
last post by:
Access2000
How do I write a query that combines the CTC field from each record below into
one record? I need to concatenate the CTC field with a...
|
by: MLH |
last post by:
I feel pretty lucky on my last SQL question.
I think I'll try one more...
If there is a table (tblCorrespondence) with a field in it named
and...
|
by: Jason Kumpf |
last post by:
OK I've been staring at this code all day and still with everything I
have tried I cannot figure out two problems I am having. Once is why
the...
|
by: Dylan Parry |
last post by:
Hi folks,
This is really confusing me. I am trying to insert a row into a
database, and then use scope_identity() to return the value of the ID...
|
by: FangQ |
last post by:
hi
I am very new to mysql. I have a question about using the "on duplicate
update" clause with insert command.
my table "data" has two...
|
by: Etayki |
last post by:
Hi!
I am trying to insert data into a MS SQL Database from a Console
Application written in VB.net
I have already created the table in the...
|
by: Susan Bricker |
last post by:
I have a form that displays record information in Continuous Record
display (scrollable list). One of the fields in the record is an
Integer value...
|
by: hakkatil |
last post by:
Hi to all,
I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is...
|
by: javediq143 |
last post by:
Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD...
|
by: tammygombez |
last post by:
Hey everyone!
I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |