Declaring cursor
Hello everyone,
I need some help with the SQL query posted below:
SQL> DECLARE cursor resolverate is
2 select e.hcfadrgcode, f.insplancode, sum(f.TOTALPAYMENTS)/sum(f.totalactualcharges) rr
3 from encounter e, encounterfinancialrecord f
4 where e.encounterid = f.encounterid
5 and e.encountertypecode = 'I'
6 and to_char(dischargetimestamp, 'YYYY-MM') >= '2004-01'
7 and to_char(dischargetimestamp, 'YYYY-MM') <= '2005-02'
8 and e.totalactualcharges > 0
9 and (arbal = 0 or bdind = 'Y')
10 group by e.hcfadrgcode, f.insplancode;
11
12 BEGIN
13
14 FOR encounter_rec in resolverate LOOP
15 select e.encounterid, (f.totalactualcharges * encounter_rec.rr) dd
16 from encounter e, encounterfinancialrecord f
17 where e.encounterid = f.encounterid
18 and e.encountertypecode = 'I'
19 and e.hcfadrgcode = encounter_rec.hcfadrgcode
20 and e.insplancode = encounter_rec.insplancode;
21
22
23
24 end loop;
25
26 END;
27
28 /
select e.encounterid, (f.totalactualcharges * encounter_rec.rr) dd
ERROR at line 15:
ORA-06550: line 15, column 7:
PLS-00428: an INTO clause is expected in this SELECT statement
In my first cursor, I'm trying to get a rate based on hcfadrgcode and insplancode. And then I would like to assign that rate in my loop to all accounts that has same hcfadrgcode and insplancode. Please let me know if you need more information.
I'm using Oracle SQL*PLUS
Thanks,
I'm not trying to update any columns. All I want is to get a file which returns the Encounter ID and Resolve Rate amount from the inner loop based on my cursor rate. For example,
DECLARE cursor resolverate is
select e.hcfadrgcode, f.insplancode, sum(f.TOTALPAYMENTS)/sum(f.totalactualcharges) rr
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and to_char(dischargetimestamp, 'YYYY-MM') >= '2004-01'
and to_char(dischargetimestamp, 'YYYY-MM') <= '2005-02'
and e.totalactualcharges > 0
and (arbal = 0 or bdind = 'Y')
group by e.hcfadrgcode, f.insplancode;
From this code, I will get
HCFACODE INSPLAN RR
012 MM 0.22
022 FN 1.23
and so on,
When I get RR from the select statement, I want to assign this to all my Encounter ID and get the RR Amount
So when I run the code below, I should get:
BEGIN
FOR encounter_rec in resolverate LOOP
select e.encounterid, (f.totalactualcharges * encounter_rec.rr) dd
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and e.hcfadrgcode = encounter_rec.hcfadrgcode
and e.insplancode = encounter_rec.insplancode;
EncounterID RRAmount
1234 $23000 (Totalcharges * RR)
2350 $28000
I like to see the result above and be able to copy it in to a text file to import it to MS Access.
Thank you so much.
Similar Messages
-
How to declare cursors dynamically
I am writing a trigger.
in the body of the trigger, I need to make a select query on a table like
select column1 from tablename where order_id = some_variable_name...
for each of the column1, I need to do some operation. Problem is I get the value of some_variable_name only in the body of the trigger, so I cant declare a cusor for this select in the declare section.
Is there any way to declare this cursor in the body block of the trigger, or is there some other way to make a select query and store the results in some data structure?One can still declare the cursor in the declare section of the trigger ... just need to parameterize the cursor definition:
create or replace trigger bit
before insert on t
for each row
declare
cursor crsdef(av_nm usr.nm%type) is
select count(0) cnt
from usr
where nm = initcap(av_nm);
begin
for crs in crsdef(:new.nm)
loop
dbms_output.put_line('cnt for '||:new.nm||' is: '||crs.cnt);
end loop;
end;
/Better yet, put the whole thing (cursor and all) in a stored procedure/function and call that from the trigger. -
Documentation for declare cursor in table function
Thanks in advance to all,
Could anyone pont me to doc about declaring cursor for table function?
For example something as:
CURSOR cur_test IS
SELECT S.*, OT.par1
FROM table S, TABLE (pak.tabfunc(&par0,S.col1) ) OT'Cause having problem in compilation (ORA_904 invalid identifier)
ThanksThanks William for reply,
Is that part of the code? No, It was only for example.
my problem is:
I don't understand, I have success in SQL
begin
FOR x IN
(SELECT s.*, OT.*
FROM tablex S,
TABLE (pkg.myfunctpipilined(x1,x2,x3,s.col1) ) OT
WHERE ........
) LOOP
dbms_output.put_line('Fetching.... ' || x.xxxxx);
END LOOP;
END;but, when i insert that in a procedure I get ORA-904 identifier on pkg.myfunctpipilined
Thanks again for your time, I appreciated, I keep on to try and looking for
ps. pkg.myfunctpipilined is pipelined function in Package based on Table's Object -
How to declare cursor in procedure based on if condition?
Hi Experts,
In sql server I have eprocedure in which I declare cursor like this:
IF (@int_cntCondition = 1 )
BEGIN
DECLARE Date_Cursor CURSOR FOR select HolidayCcy,HolidayDate from Definition..HolidayCalendar WITH (NOLOCK) where
HolidayCcy in (@Deposit_Currency,@Alternate_Currency)
AND CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),HolidayDate,106)) >=
CONVERT(SMALLDATETIME,CONVERT(VARCHAR (25),@T_Date,106))
END
ELSE
BEGIN
DECLARE Date_Cursor CURSOR FOR select HolidayCcy,HolidayDate from Definition..HolidayCalendar WITH (NOLOCK) where
HolidayCcy in (@Deposit_Currency,@Alternate_Currency,@Bank_Base_Currency)
AND CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),HolidayDate,106)) >=
CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),@T_Date,106))
END
I have to declare same cursor in oracle based on 'if' condition.
But in oracle stored procedur cursor has to declare outside of Begin statment of procedure, so how can I declare This cursor in Orracle?
if anyone know about it, Plese help or send any link to refer.
Thanks.Digambar wrote:
I have to declare same cursor in oracle based on 'if' condition.The simple answer is to use a reference cursor data type. E.g.
SQL> create or replace procedure GetObjects( cur in out sys_refcursor, objType varchar2 ) is
2 begin
3 case
4 when upper(objType) = 'EMP' then
5 open cur for select * from emp;
6
7 when upper(objType) = 'DEPT' then
8 open cur for select * from dept;
9
10 end case;
11 end;
12 /
Procedure created.
SQL>
SQL>
SQL> --// define a host refcursor variable in client
SQL> --// (e.g. VB, .Net, Java, etc)
SQL> var c refcursor
SQL>
SQL> --// make the stored proc call
SQL> begin GetObjects( :c, 'EMP' ); end;
2 /
PL/SQL procedure successfully completed.
SQL>
SQL> --// process cur reference in client
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 1980/12/17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981/02/22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981/04/02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981/09/28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981/05/01 00:00:00 2850 30
7782 CLARK MANAGER 7839 1981/06/09 00:00:00 2450 10
7788 SCOTT ANALYST 7566 1987/04/19 00:00:00 3000 20
7839 KING PRESIDENT 1981/11/17 00:00:00 5000 10
7844 TURNER SALESMAN 7698 1981/09/08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987/05/23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981/12/03 00:00:00 950 30
7902 FORD ANALYST 7566 1981/12/03 00:00:00 3000 20
7934 MILLER CLERK 7782 1982/01/23 00:00:00 1300 10
14 rows selected.
SQL>
SQL>
SQL> --// make the stored proc call
SQL> begin GetObjects( :c, 'DEPT' ); end;
2 /
PL/SQL procedure successfully completed.
SQL>
SQL> --// process cur reference in client
SQL> print c
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> -
Hello I ran into a problem while running a SQL command using OracleCommand. I am Declaring a cursor to retrieve values from table A and then loop through that dataset to update table B. When I run this script I see my application hanging right there without any response. Do I have to use REF CURSOR? HOW to use it? I can't use DECLARE CURSOR? Need help. Here is my present SQL command
DECLARE CURSOR c_load IS SELECT VALUATION_YR_MTH_NBR,PMT_PRD_NBR,PMT_DAY,PMT_MTH,PMT_YR,SERIES_NAME,GROUP_NAME,FNC_PROD_NAME,SCENARIO_ABBR,PRIN_SCHED_BAL,NET_INT_AMT,SCHED_PRIN_AMT,SPEED_PREPMT_1_MTH_AMT,LOSS_TOTAL_AMT,SURETY_FEE_AMT,INT_FROM_OTHER_GROUP_AMT,PRIN_FROM_OTHER_GROUP_AMT,SENIOR_FIXED_RATE_BOND_BAL,SENIOR_FLOAT_RATE_BOND_BAL,SUBORDINATE_RATE_BOND_BAL,IO_NOTIONAL_BAL,NON_IO_FIXED_INT_PAID_AMT,NON_IO_FLOAT_INT_PAID_AMT,IO_INT_PAID_AMT,TOTAL_PRIN_AMT,BOND_WRITE_DOWNS_AMT,SURETY_PMTS_AMT,OC_BAL,OC_TARGET_BAL,RESIDUAL_INT_AMT,RESIDUAL_PRIN_AMT,RESIDUAL_TOTAL_AMT, CHG_LST_DATE, CHG_LST_USER_ID, CHG_LST_PROG_NAME FROM RESIDCF.CASH_FLOW_FORECAST_UPLOAD WHERE PREV_UPLOADED_IND='Y'; BEGIN FOR c_inx IN c_load LOOP UPDATE RESIDCF.CASH_FLOW_FORECAST SET PMT_DAY=c_inx.PMT_DAY,PMT_MTH=c_inx.PMT_MTH,PMT_YR=c_inx.PMT_YR,PRIN_SCHED_BAL=c_inx.PRIN_SCHED_BAL,NET_INT_AMT=c_inx.NET_INT_AMT,SCHED_PRIN_AMT=c_inx.SCHED_PRIN_AMT,SPEED_PREPMT_1_MTH_AMT=c_inx.SPEED_PREPMT_1_MTH_AMT,LOSS_TOTAL_AMT=c_inx.LOSS_TOTAL_AMT,SURETY_FEE_AMT=c_inx.SURETY_FEE_AMT,INT_FROM_OTHER_GROUP_AMT=c_inx.INT_FROM_OTHER_GROUP_AMT,PRIN_FROM_OTHER_GROUP_AMT=c_inx.PRIN_FROM_OTHER_GROUP_AMT,SENIOR_FIXED_RATE_BOND_BAL=c_inx.SENIOR_FIXED_RATE_BOND_BAL,SENIOR_FLOAT_RATE_BOND_BAL=c_inx.SENIOR_FLOAT_RATE_BOND_BAL,SUBORDINATE_RATE_BOND_BAL=c_inx.SUBORDINATE_RATE_BOND_BAL,IO_NOTIONAL_BAL=c_inx.IO_NOTIONAL_BAL,NON_IO_FIXED_INT_PAID_AMT=c_inx.NON_IO_FIXED_INT_PAID_AMT,NON_IO_FLOAT_INT_PAID_AMT=c_inx.NON_IO_FLOAT_INT_PAID_AMT,IO_INT_PAID_AMT=c_inx.IO_INT_PAID_AMT,TOTAL_PRIN_AMT=c_inx.TOTAL_PRIN_AMT,BOND_WRITE_DOWNS_AMT=c_inx.BOND_WRITE_DOWNS_AMT,SURETY_PMTS_AMT=c_inx.SURETY_PMTS_AMT,OC_BAL=c_inx.OC_BAL,OC_TARGET_BAL=c_inx.OC_TARGET_BAL,RESIDUAL_INT_AMT=c_inx.RESIDUAL_INT_AMT,RESIDUAL_PRIN_AMT=c_inx.RESIDUAL_PRIN_AMT,RESIDUAL_TOTAL_AMT=c_inx.RESIDUAL_TOTAL_AMT , CHG_LST_DATE=c_inx.CHG_LST_DATE , CHG_LST_USER_ID=c_inx.CHG_LST_USER_ID , CHG_LST_PROG_NAME=c_inx.CHG_LST_PROG_NAME WHERE VALUATION_YR_MTH_NBR=c_inx.VALUATION_YR_MTH_NBR AND PMT_PRD_NBR=c_inx.PMT_PRD_NBR AND SERIES_NAME=c_inx.SERIES_NAME AND GROUP_NAME=c_inx.GROUP_NAME AND FNC_PROD_NAME=c_inx.FNC_PROD_NAME AND SCENARIO_ABBR=c_inx.SCENARIO_ABBR; END LOOP; END;That block should run the same from ODP.NET as from SQLPlus. Which is very slowly. You shouldn't be using a cursor here. Instead try an updatable join, or better MERGE (for 9i).
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems30.htm#37586
David -
HI ALL,
Is it possiable declare inside of Procedure body?
Example:
BEGIN
IF test = 1 then
Declare CursorA.....where num =1;
ElSIF test = 2 then
Declare CursorA....where num=2;
ELSE
Declare CursorA....where num=3;
END;It is possible but it is not the smart way of coding. Few other options for this would be
1. Parameterize your cursor to take the test value when you open it
2 . Use ref cursor
SQL> create table sample(num number,name varchar2(25))
2 /
Table created.
SQL> insert all
2 into sample values(1,'SCOTT')
3 into sample values(1,'TIGER')
4 into sample values(2,'PAUL')
5 into sample values(3,'HARRY')
6 into sample values(3,'NEWMAN')
7 select * from dual
8 /
5 rows created.
SQL> commit;
Commit complete.
SQL> set serveroutput on;
SQL> DECLARE
2 TEST NUMBER :=1;
3 BEGIN
4 IF TEST = 1 THEN
5 DECLARE
6 CURSOR CURSORA IS SELECT NAME FROM SAMPLE WHERE NUM =1;
7 BEGIN
8 FOR I IN CURSORA
9 LOOP
10 DBMS_OUTPUT.PUT_LINE(I.NAME);
11 END LOOP;
12 END;
13 END IF;
14
15 IF TEST = 2 THEN
16 DECLARE
17 CURSOR CURSORA IS SELECT NAME FROM SAMPLE WHERE NUM =2;
18 BEGIN
19 FOR I IN CURSORA
20 LOOP
21 DBMS_OUTPUT.PUT_LINE(I.NAME);
22 END LOOP;
23 END;
24 END IF;
25
26 END;
27 /
SCOTT
TIGER
PL/SQL procedure successfully completed.
SQL> DECLARE
2 TEST NUMBER :=1;
3 CURSOR CURSORA IS SELECT NAME FROM SAMPLE WHERE NUM=TEST ;
4 BEGIN
5 FOR I IN CURSORA
6 LOOP
7 DBMS_OUTPUT.PUT_LINE(I.NAME);
8 END LOOP;
9 END;
10 /
SCOTT
TIGER
PL/SQL procedure successfully completed.
SQL> -
Hi all,when i am trying to declare a cursor in a procedure i am getting errors.Kindly correct me where i am going wrong
1 CREATE OR REPLACE PROCEDURE xxc_lc_rcv_interface_prc IS
2 v_a NUMBER;
3 v_b NUMBER;
4 v_c NUMBER;
5 v_d NUMBER;
6 v_e NUMBER;
7 v_f NUMBER;
8 v_g NUMBER;
9 CURSOR rcv_interface_cur
10 IS
11 SELECT shipment_header_id INTO v_c
12 FROM RCV_SHIPMENT_HEADERS
13 WHERE SHIPMENT_NUM = 'NOV1124';
14 SELECT shipment_line_id INTO v_d
15 FROM RCV_SHIPMENT_LINES
16 WHERE SHIPMENT_HEADER_ID = v_c;
17 BEGIN
18 SELECT rcv_headers_interface_s.nextval INTO v_a FROM dual ;
19 SELECT rcv_interface_group_s.nextval INTO v_b FROM dual;
20 SELECT rcv_headers_interface_s.currval INTO v_e FROM dual ;
21 SELECT rcv_interface_groups_s.currval INTO v_f FROM dual;
22 SELECT rcv_transactions_interface_s.nextval INTO v_g FROM dual;
23 BEGIN
24 INSERT INTO rcv_headers_interface
25 (
26 HEADER_INTERFACE_ID,
27 GROUP_ID,
28 PROCESSING_STATUS_CODE,
29 RECEIPT_SOURCE_CODE,
30 TRANSACTION_TYPE,
31 AUTO_TRANSACT_CODE,
32 LAST_UPDATE_DATE,
33 LAST_UPDATE_LOGIN,
34 LAST_UPDATED_BY,
35 CREATION_DATE,
36 CREATED_BY,
37 VALIDATION_FLAG,
38 COMMENTS,
39 SHIPMENT_NUM,
40 FROM_ORGANIZATION_ID,
41 SHIP_TO_ORGANIZATION_ID,
42 EXPECTED_RECEIPT_DATE
43 --RECEIPT_HEADER_ID
44 )
45 VALUES
46 (v_a, --Header Interface ID
47 v_b, --Group ID
48 'PENDING', --Processing Status Code
49 'INVENTORY', --Receipt source Code
50 'RECEIVE', --Transaction Type
51 'DELIVER' , --AUT Transact Code
52 sysdate, --last update date
53 1053, --last updated by
54 1053, --Last Update Login
55 sysdate, --creation date
56 1053, --created by
57 'Y', --Validation Flag
58 'Receiving Through Interface', --Comments
59 'NOV1124' , --Shipment Number
60 81, --From Org
61 82, --To org
62 sysdate --Expected Receipt Date
63 );
64 END;
65 BEGIN
66 FOR crec IN rcv_interface_cur loop
67 INSERT INTO rcv_transactions_interface
68 (
69 HEADER_INTERFACE_ID,
70 GROUP_ID,
71 INTERFACE_TRANSACTION_ID,
72 TRANSACTION_TYPE,
73 TRANSACTION_DATE,
74 PROCESSING_STATUS_CODE,
75 PROCESSING_MODE_CODE,
76 TRANSACTION_STATUS_CODE,
77 CATEGORY_ID,
78 QUANTITY,
79 LAST_UPDATE_DATE,
80 LAST_UPDATED_BY,
81 CREATION_DATE,
82 CREATED_BY,
83 RECEIPT_SOURCE_CODE,
84 DESTINATION_TYPE_CODE,
85 AUTO_TRANSACT_CODE,
86 SOURCE_DOCUMENT_CODE,
87 UNIT_OF_MEASURE,
88 INTERFACE_SOURCE_CODE,
89 ITEM_ID,
90 --ITEM_DESCRIPTION,
91 UOM_CODE,
92 EMPLOYEE_ID,
93 SHIPMENT_HEADER_ID,
94 TO_ORGANIZATION_ID,
95 SUBINVENTORY,
96 FROM_ORGANIZATION_ID,
97 FROM_SUBINVENTORY,
98 EXPECTED_RECEIPT_DATE,
99 SHIPPED_DATE,
100 VALIDATION_FLAG
101 )
102 VALUES
103 (v_e, --Header Interface ID
104 v_f, --Group ID
105 v_g, --Interface_transaction_id
106 'RECEIVE', --Transaction Type
107 sysdate, --Transaction Date
108 'PENDING', --Processing Status Code
109 'BATCH', --Processing Mode Code
110 'PENDING', --Transaction Status Code
111 120, --Category ID
112 2, --Quantity
113 sysdate, --last update date
114 1053, --last updated by
115 sysdate, --creation date
116 1053, --created by
117 'INVENTORY', --Receipt source Code
118 'INVENTORY', --Destination Type Code
119 'DELIVER' , --AUTO Transact Code
120 'INVENTORY', --Source Document Code
121 'Each', --Unit Of Measure
122 'RCV', --Interface Source Code
123 2492, --Item ID
124 --'ABBY KITCHEN CURTAIN SET BEIGE/BURGUNDY', --Item Description
125 'EA', --UOM COde
126 1053, --User
127 v_c, --Shipment Header ID
128 v_d, --SHipment Line ID
129 82, --To Organization ID
130 'Brooklyn', --Sub Inventory ID
131 81, --From Organization
132 'Vessel', --From Subinventory
133 sysdate, --Expected Receipt Date
134 sysdate, --Shipped Date
135 'Y' --Validation Flag
136 );
137 --END IF;
138 END LOOP;
139 END;
140* END xxc_lc_rcv_interface_prc;
SQL> /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE XXC_LC_RCV_INTERFACE_PRC:
LINE/COL ERROR
14/2 PLS-00103: Encountered the symbol "SELECT" when expecting one of
the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
The symbol "begin" was substituted for "SELECT" to continue.
141/0 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purgehi,
I have corrected your code
CREATE OR REPLACE PROCEDURE xxc_lc_rcv_interface_prc
IS
v_a NUMBER;
v_b NUMBER;
v_c NUMBER;
v_d NUMBER;
v_e NUMBER;
v_f NUMBER;
v_g NUMBER;
CURSOR rcv_interface_cur
IS
SELECT shipment_header_id
INTO v_c
FROM rcv_shipment_headers
WHERE shipment_num = 'NOV';
BEGIN
SELECT shipment_line_id
INTO v_d
FROM rcv_shipment_lines
WHERE shipment_header_id = v_c;
SELECT rcv_headers_interface_s.NEXTVAL
INTO v_a
FROM DUAL;
SELECT rcv_interface_group_s.NEXTVAL
INTO v_b
FROM DUAL;
SELECT rcv_headers_interface_s.CURRVAL
INTO v_e
FROM DUAL;
SELECT rcv_interface_groups_s.CURRVAL
INTO v_f
FROM DUAL;
SELECT rcv_transactions_interface_s.NEXTVAL
INTO v_g
FROM DUAL;
BEGIN
INSERT INTO rcv_headers_interface
(header_interface_id, GROUP_ID, processing_status_code,
receipt_source_code, transaction_type,
auto_transact_code, last_update_date, last_update_login,
last_updated_by, creation_date, created_by,
validation_flag, comments, shipment_num, from_organization_id, ship_to_organization_id, expected_receipt_date
--RECEIPT_HEADER_ID
VALUES (v_a, --Header Interface ID
v_b, --Group ID
'PENDING', --Processing Status Code
'INVENTORY', --Receipt source Code
'RECEIVE', --Transaction Type
'DELIVER', --AUT Transact Code
SYSDATE, --last update date
--, --last updated by
--, --Last Update Login
SYSDATE, --creation date
-- , --created by
'Y', --Validation Flag
'Receiving Through Interface', --Comments
'NOV', --Shipment Number
-- , --From Org
-- , --To org
SYSDATE --Expected Receipt Date
END;
BEGIN
FOR crec IN rcv_interface_cur
LOOP
INSERT INTO rcv_transactions_interface
(header_interface_id, GROUP_ID,
interface_transaction_id, transaction_type,
transaction_date, processing_status_code,
processing_mode_code, transaction_status_code,
category_id, quantity, last_update_date,
last_updated_by, creation_date, created_by,
receipt_source_code, destination_type_code,
auto_transact_code, source_document_code,
unit_of_measure, interface_source_code, item_id,
--ITEM_DESCRIPTION,
uom_code, employee_id, shipment_header_id, to_organization_id, subinventory, from_organization_id, from_subinventory, expected_receipt_date, shipped_date, validation_flag
VALUES (v_e, --Header Interface ID
v_f, --Group ID
v_g, --Interface_transaction_id
'RECEIVE', --Transaction Type
SYSDATE, --Transaction Date
'PENDING', --Processing Status Code
'BATCH', --Processing Mode Code
'PENDING', --Transaction Status Code
-- , --Category ID
-- , --Quantity
SYSDATE, --last update date
-- , --last updated by
SYSDATE, --creation date
-- , --created by
'INVENTORY', --Receipt source Code
'INVENTORY', --Destination Type Code
'DELIVER', --AUTO Transact Code
'INVENTORY',
--Source Document Code
'Each', --Unit Of Measure
'RCV', --Interface Source Code
-- , --Item ID
--'ABBY KITCHEN CURTAIN SET BEIGE/BURGUNDY', --Item Description
'EA', --UOM COde
-- , --User
v_c, --Shipment Header ID
v_d, --SHipment Line ID
-- , --To Organization ID
'Brooklyn', --Sub Inventory ID
-- , --From Organization
'Vessel', --From Subinventory
SYSDATE, --Expected Receipt Date
SYSDATE, --Shipped Date
'Y' --Validation Flag
--END IF;
END LOOP;
END;
END xxc_lc_rcv_interface_prc;
there are many syntax errors i have corrected .
Note : code is not compiled or tested .Thanks,
P Prakash
Edited by: prakash on Nov 21, 2011 4:00 AM -
ESQL/C: Difficulties with DECLARE CURSOR and nested FROM CLAUSE
Hello @All,
i am trying to migrate an old esql-c-Application to Oracle 11g (on 64-Bit-AIX 7.1 - Platform)
PreCompiling is OK, but during runtime the following DECLARE - Statement returns ORA-01001: invalid cursor :
EXEC SQL
DECLARE cur_xyz CURSOR FOR
SELECT vPE, mPE, mZW, COUNT (*)
FROM ( SELECT v.K_PE AS vPE, m.K_PE AS mPE, m.ZW AS mZW, v.VKG
FROM ( SELECT K_NR, K_PE, u3.VKG, POS
FROM u3, r
WHERE u3.K_NR = '999999'
AND u3.LANG = 'F'
AND SUBSTR (PRTCTRL, 5, 1) > '0'
AND u3.VKG = r.VKG ( + )
) v, m
WHERE
v.K_NR = m.K_NR ( + )
AND v.K_PE = m.K_PE ( + )
AND POS is Null
) X
WHERE not EXISTS (SELECT VKG FROM NP WHERE X.VKG = NP.VKG )
GROUP BY vPE, mPE, mZW
ORDER BY vPE
When I run this statement without "EXEC SQL DECLARE cur_xyz CURSOR FOR" in SQL-Developer, there is no problem.
What is my fault? I hope, that I don't have to redesign this.
Thx in advance for anyonce help.Hey Billy,
I work in a C/C++-Environment under AIX. I allready build a library with with more than x.000 Functions with ESQL-Statements.
Most of them are running.
If I need a CURSOR, I allways use constructs like this:
EXEC SQL DECLARE CursorName [SCROLL]CURSOR FOR
SELECT ...
if (SQLC == 0) {
EXEC SQL OPEN CursorName;
while (SQLC == 0) {
EXEC SQL FETCH ... CursorName INTO :<Structure or Fieldlist>;
EXEC SQL CLOSE CursorName;
At the Moment, I don't work with a cursor-variable in the DECLARE-Section.
In the case i discribed above, it is the first, where the ORA-01001 occurs.
Is it necessary to work with SQL_CURSOR - Variable in all or in special cases?
Thx 4 answers. -
Hi,
on an APEX page I can create a cursor from an item like this:
cursor c is &P999_SQL_QUERY.;
and there are no problems.
Now I want to do the same in a procedure, but how could that be done?
I pass the sql-Statement as a VARCHAR2 variable to the procedure, but I do not know how I can do that. I am not familar with bind variables or something like that.
Can anyone help me please?
Thank you,
Tim> on an APEX page I can create a cursor from an item like this:
cursor c is &P999_SQL_QUERY.;
and there are no problems.
Except for the very real and harsh danger of SQL injection. Pardon for being blunt, but code like that is bloody dangerous and IMO quite silly.
> Now I want to do the same in a procedure, but how could that be done?
You have created an anonymous PL/SQL block that are parsed and compiled at run-time (with APEX PL/SQL code doing the deed).
You can do the same thing manually in PL/SQL writing your own code to perform this deed.
It will however be equally dangerous and silly to do. -
Problems while using ORDER BY in declaring a PL/SQL cursor
Hi, everybody
I hope you can help me.
We are programming a very simple PL/SQL Procedure where we are declaring the following Cursor:Declare
Cursor CUnidadP is
Select UNOR_CO_UNID_ORGID,UNOR_CO_PADREID,UNOR_NU_NIVEL from Unidad_Organizativa
where Unor_NU_NIVEL > 1)
order by Unor_NU_NIVEL;
(We need to have sorted records in the cursor)
Curiously, this cursor declaration works fine in our local 8.1.6 Database (in an NT machine) but it is not working in our customer Database (8.0.4.3.0 for SUN/SOLARIS)
where we are getting the following error messages:
"ORA-06550:line 3, column 9
PLS-00707:unsupported construct or internal error (2603)
ORA-06550:line 3, column 9
PL/SQL:SQL Statement ignored"
So, my question is: Anyone knows why? Is there any bug concerning to 8.0.4.3.0 version for SUN Solaris referring to this subject? Does anyone know a different way of doing this getting same results?
Thanks everybody and best regards
IreneThere is a bug with the following description:
Bug:619477
Description: Although SQL supports the ORDER BY clause in subqueries,
PL/SQL does not yet support these.
Workaround: Execute SQL statements with such subqueries through dynamic SQL.
An easier workaround is an explicit (out-of-line) view
Maybe this (or a related bug) is your problem -
Performance: Cursor declaration versus explicit query in BEGIN/END block
Hi guys!
Anyone knows if declare an explicit cursor inside a pl/sql block is faster than using a cursor declaration, and how fast it its?
Which block runs faster? And how fast? ( once, twice, once and a half ? )
Block1:
DECLARE
CURSOR cur_test (p1 NUMBER) IS
SELECT field1, field2 FROM table WHERE field0 = p1;
vf1 VARCHAR2(1)
vf2 NUMBER;
n NUMBER := 0;
BEGIN
OPEN cur_test ( n );
FETCH cur_test INTO vf1, vf2;
CLOSE cur_test;
END;
Block2:
DECLARE
vf1 VARCHAR2(1)
vf2 NUMBER;
n NUMBER := 0;
BEGIN
BEGIN
SELECT field1, field2
INTO vf1, vf2
FROM table WHERE field0 = n;
EXCEPTION
WHEN others THEN
null;
END;
END;
I have LOOP in a cursor and may open/fetch/closes in this loop. I´m wondering how fast would it be if I change the open/fetch/closes to explicit query blocks...
Thanks!
MuriloIf you expect your qurey to return a single row, you would generally want to use a SELECT ... INTO. You'd only want to use a cursor if you expect to return multiple rows of data.
If you are doing this in a loop, I would strongly suspect that you should be letting Oracle join the tables in SQL rather than doing your own pseudo-join logic in PL/SQL. Letting SQL do the work of joining tables is going to generally be a sustantial performance difference. The difference between the two blocks you posted will be marginal at best.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
hi all,
is it possible to declare a cursor like this ..???
declare
cursor is select ab.col1,cd.col2 from
(select a.col1,b.col2
from a,b
conditions)ab
(select c.col1,d.col2...
from c,d
conditions..)cd
i am getting the following error
PL/SQL: ORA-00923: FROM keyword not found where expectedPlenty of syntactical error in your cursor declaration. It should be like this ->
cursor c1
is
select ab.col1,
cd.col2
from (
select a.col1,
b.col2
from a,b
where conditions
) ab,
select c.col1,
d.col2...
from c,d
where conditions..) cd
where ab.cond1 = cd.cond1;Regards.
Satyaki De. -
Declaring a cursor in an Anonymous Block
How do I declare a cursor in an Anonymous Block? I've looked in several sources and haven't found anything that explains this.
Does anyone have a link to where this would be explained?
ThanksDepends on whether you're talking about an explicit or an implicit cursor, but it's basically the same way you declare either in a non-anonymous block, i.e.
DECLARE
CURSOR cursor_name IS ...
BEGIN
END;or
BEGIN
FOR x IN (SELECT ... )
LOOP
END LOOP;
END;Justin -
Evaluation of expressions in cursor declaration.
Hi, all,
If I have in an on-demand application process:
DECLARE
CURSOR c1 IS SELECT DUMMY FROM DUAL WHERE 'FOO' = V('MY_ITEM')
BEGIN
FOR c IN c1
LOOP
-- do stuff with c
END LOOP;
END
when is V('MY_ITEM') evaluated?V('MY_ITEM') will be evaluated when the cursor is opened on (every) execution of the on-demand process.
Toon -
Cursor Error in trigger - Statement Ignored/identifier must be declared PLS
I have been asked to implement a trigger and believe I have the code complete but am getting a final error on the compile. I have been running in circles for a day trying to resolve my issue. I have no PL/SQL knowlege so have been pulling from a book and google. I have three Cursors defined and the third compiles fine, the first two give the below error though I can't see a significant difference between the three. I can't help but think it is something stupid I am not seeing but I am at a loss.
If I comment out the reference to the cursor it will compile with the cursor definition but as soon as I add the Open statement the errors below appear.
Any help would be greatly appreciated as my head is getting sore.
Thanks
Mike
Error(30,13): PL/SQL: Statement ignored
Error(30,20): PLS-00201: identifier 'CURSORGETFROMDISTMAKRERS' must be declared
Error(51,13): PL/SQL: Statement ignored
Error(51,20): PLS-00201: identifier 'CURSORGETTODISTMAKRERS' must be declared
-- Table I am writing to
create table IMSV7.CTRANSWODISTMARK (
WORKORDERKEY INTEGER,
DISTMARKFROM NUMBER (9,4),
DISTMARKFROMATTRIBUTE VARCHAR (10),
DISTMARKTO NUMBER (9,4),
DISTMARKTOATTRIBUTE VARCHAR (10)
-- Excerpt from the HISTORY table I am placing the trigger against
COMPKEY NUMBER (9,0)
DISTFROMFT FLOAT
DISTTOFT FLOAT
HISTKEY NUMBER (9,0)
-- Trigger code
CREATE OR REPLACE TRIGGER MaintainCTRANSWODISTMARK
AFTER INSERT or UPDATE of DISTFROMFT, DISTTOFT ON IMSV7.HISTORY
REFERENCING NEW as NewWO
FOR EACH ROW
BEGIN
DECLARE
-- Declare cursors
CURSOR CursorGetFromDistMarkers (WOCompKey IN NUMBER, WODistFromFT IN FLOAT) IS
SELECT ATTRCODE, DISTFROMFT, MARKERFROM from RWATTRDF DF, RWATTR A
where WOCompkey = A.COMPKEY AND DF.ATTRKEY = A.ATTRKEY and DF.ATTRTYPE = 'DISTMARK'
and WODistFromFT >= DISTFROMFT and WODistFromFT <= DISTTOFT
order by A.EFFDATE DESC, DISTFROMFT DESC;
FromDistanceMarker CursorGetFromDistMarkers%ROWTYPE;
CURSOR CursorGetToDistMarkers (WOCompKey IN NUMBER, WODistToFT IN FLOAT) IS
SELECT ATTRCODE, DISTFROMFT, MARKERFROM from RWATTRDF DF, RWATTR A
where WOCompkey = A.COMPKEY AND DF.ATTRKEY = A.ATTRKEY and DF.ATTRTYPE = 'DISTMARK'
and WODistToFT >= DISTFROMFT and WODistToFT <= DISTTOFT
order by A.EFFDATE DESC, DISTFROMFT DESC;
ToDistanceMarker CursorGetToDistMarkers%ROWTYPE;
CURSOR CursorGetCTRANSWODistMark (WOHistKey IN NUMBER) IS
SELECT WORKORDERKEY from CTRANSWODISTMARK
where WORKORDERKEY = WOHistKey;
CTRANSWODistMark CursorGetCTRANSWODistMark%ROWTYPE;
varDistmarkFrom NUMBER;
varDistmarkFromAttribute VARCHAR2(10);
varDistmarkTo NUMBER;
varDistmarkToAttribute VARCHAR2(10);
BEGIN
-- Process From measurement
IF NOT CursorGetFromDistMakrers%ISOPEN
THEN
OPEN CursorGetFromDistMarkers(:NewWO.COMPKEY, :NewWO.DISTFROMFT);
END IF;
FETCH CursorGetFromDistMarkers INTO FromDistanceMarker;
IF CursorGetFromDistMarkers%NOTFOUND
THEN
-- No distance markers found, use MILES
varDistmarkFrom := :NewWO.DISTFROMFT / 5280;
varDistmarkFromAttribute := 'MILES';
ELSE
-- Found a distance marker, convert to its units and use those
-- Distance is the Marker start distance plus the offset from that start of the marker
varDistmarkFrom := FromDistanceMarker.MARKERFROM + :NewWO.DISTFROMFT - FromDistanceMarker.DISTFROMFT;
varDistmarkFromAttribute := FromDistanceMarker.ATTRCODE;
END IF;
CLOSE CursorGetFromDistMarkers;
-- Process To measurement
IF NOT CursorGetToDistMakrers%ISOPEN
THEN
OPEN CursorGetToDistMarkers(:NewWO.COMPKEY, :NewWO.DISTTOFT);
END IF;
FETCH CursorGetToDistMarkers INTO ToDistanceMarker;
IF CursorGetToDistMarkers%NOTFOUND
THEN
-- No distance markers found, use MILES
varDistmarkTo := :NewWO.DISTTOFT / 5280;
varDistmarkToAttribute := 'MILES';
ELSE
-- Found a distance marker, convert to its units and use those
-- Distance is the Marker start distance plus the offset from that start of the marker
varDistmarkTo := ToDistanceMarker.MARKERFROM + :NewWO.DISTTOFT - ToDistanceMarker.DISTFROMFT;
varDistmarkToAttribute := ToDistanceMarker.ATTRCODE;
END IF;
CLOSE CursorGetToDistMarkers;
-- Check for existing record to know if we should add or update
IF NOT CursorGetCTRANSWODistMark%ISOPEN
THEN
OPEN CursorGetCTRANSWODistMark(:NewWO.HISTKEY);
END IF;
FETCH CursorGetCTRANSWODistMark INTO CTRANSWODistMark;
IF CursorGetCTRANSWODistMark%NOTFOUND
THEN
-- Record does not exist, add one
Insert into CTRANSWODISTMARK (WORKORDERKEY, DISTMARKFROM, DISTMARKFROMATTRIBUTE, DISTMARKTO, DISTMARKTOATTRIBUTE)
values (:NewWO.HISTKEY, varDistmarkFrom, varDistmarkFromAttribute, varDistmarkTo, varDistmarkToAttribute);
ELSE
-- Existing record, update it
Update CTRANSWODISTMARK set DISTMARKFROM = varDistmarkFrom, DISTMARKFROMATTRIBUTE = varDistmarkFromAttribute,
DISTMARKTO = varDistmarkTo, DISTMARKTOATTRIBUTE = varDistmarkToAttribute
Where WORKORDERKEY = :NewWO.HISTKEY;
END IF;
END;
END;
run;
show errors trigger MaintainCTRANSWODISTMARK;the cursor is mispelled
IF NOT CursorGetFromDistMakrers%ISOPENchange it to:
IF NOT CursorGetFromDistMarkers%ISOPEN
Maybe you are looking for
-
Material valuation data lock causing failure in PGI
Greetings experts, I am running into an issue where a material valuation lock is causing deliveries to fail goods issue when PGI is triggered from the shipment. These shipments contain many deliveries and are sometimes processed in mass (VT12). This
-
How to Pass XML Data to a PDF Form and Load it into form fields
I have xml Form data in a string. I would like open a programatically launch a pdf document and pass the xml data as one of the parameters and this xml data needs to load all the form fields. Any Idea as to how this can be done?
-
Indexing xml files HELP PLEASE!!
Can anyone help!!! I am some have xml files stored in a folder. Each month this will grow by about 20-30%, I need to be able to search for particular files quickly. I am thinking of indexing the files. Does anyone know how I could do this so that as
-
Enterprise Manager Change Database
I just installed Oracle 10 and created two databases. The first one is called "deleteme" and the second one is called "test". I can access the database "test" by going to the URL http://computername.componanyname.com:5500/em/ but I can't seem to acce
-
How do i update punkbuster on mac os x lion?
whenever i try to open pb updater it says powerpc no longer supported.