Calling a procedure into select
Is this possible ?
select sp_info_element_ctrl(:new.code_usager_ctrl), from dual;
Hi,
932262 wrote:
Yes it was part of a trigger, what i am trying to do is to insert data of an old tabl into new one, the new one contains all the old colomns plus one, the code_usager_ctrl which is given by the procedure. But i don't want to use the trigger. Is that possible ? Or do i need to convert the procedure into a function.There is no way to call a procedure from a SQL statement.
You can call a function from a SQL statement, such as a query. There are some restrictions on the function. In particular, it can't have IN OUT or OUT arguments, only IN arguments. It looks like you could convert your procedure into a fucntion. The return value of the function would be what the IN OUT argument p_code_usager_ctrl is in the procedure. It looks like p_date_ctrl is always SYSDATE, so you might as well just use SYSDATE.
Here's the procedure
CREATE OR REPLACE PROCEDURE SP_INFO_ELEMENT_CTRL
( P_DATE_CTRL IN OUT DATE -- TIMESTAMP DE LA TRX
,P_CODE_USAGER_CTRL IN OUT CHAR -- CODE D'usager utilise
) AS
BEGIN
-- RECHERCHE DE LA DATE
P_DATE_CTRL := SYSDATE;
-- Si l'usager est IGD, c'est le package qui fourni le nom d'utilisateur
IF (USER = 'IGD' OR USER = 'GDI' OR USER='IGDD') AND P_CODE_USAGER_CTRL IS NOT NULL THEN
P_CODE_USAGER_CTRL := 'IGDD\'||TRIM(P_CODE_USAGER_CTRL);
ELSE
-- RECHERCHE DE L'usager
P_CODE_USAGER_CTRL := USER;
END IF;
END;
Edited by: 932262 on 2012-05-11 10:28It looks like this procedure doesn't do anything that you couldn't do as eaily in a CASE expression in pure SQL
Similar Messages
-
Can we call a procedure in select statement?
Can we call a procedure in select statement?
Hi,
Raghu_appsdba wrote:
Can we call a procedure in select statement?No. You can call functions, but not procedures.
If the procedure does not change the database state (for example, it doesn't update any tables), then you can wrap it in a function, or re-write it as a function.
Here's an example of wrapping.
CREATE OR REPLACE FUNCTION fun_x (in_txt IN VARCHAR2)
RETURN VARCHAR2
IS
BEGIN
proc_y (in_txt);
RETURN in_txt
END fun_x; -
Calling a procedure in select query.
I have created a procedure with three parameter one in parameter and two out parameter.
I want to call this procedure in select statement.How can i do this?
procedure is like this.
CREATE OR REPLACE PROCEDURE p_payment_adjustment (
p_cons_ref IN VARCHAR2,
p_bd OUT NUMBER,
p_ed OUT NUMBER,
p_roundoff OUT NUMBER
)You can't use procedures but you can use functions. You could create 3 functions that have the 3 out parameters as result or you could create a type that contains the 3 values and that is returned by the function.
-
Calling stored procedure into Crystal Report
Could any one help in suggesting how to call the stored procedure with parameters into crystal report?
i have tried using couple of methods
I have added this in add command option of Crystal report
Execute HRMS_DEVP.DPRC_GET_LEAVE_BAL(P_COMP_CODE,P_EMP_CODE,P_LV_CATG_CODE,P_DATE,P_BALANCE)
WHERE in p_balance i would be retrieving the output.
Second method i followed is
SELECT DFUN_GET_LEAVE_BAL(:P_COMP_CODE,:P_EMP_CODE,:P_LV_CATG_CODE,:P_DATE)FROM
DUAL;Hi,
Have you tried the 'get_value' function?..The syntax is
declare
l_dept number(5);
begin
l_dept := get_value('dept');
/* further process */
end;
where 'dept' is name of the bind variable.
-Krishnamurthy -
How to call Oracle Procedure into ODI
Hi,
I'm using ODI 10g.
Before executing the interface in a package i wanted to place my Procedure.
I created following procedure in d/b (target)
CREATE OR REPLACE PROCEDURE TEST_MY_NEW_PROCE
AS
BEGIN
DELETE FROM EMPLOYEE_TABLE
WHERE EMPLOPYEE_ID LIKE 'P%';
COMMIT;
END;
The Procedure is working fine in target database.
Now, before executing my interface i would like to run this procedure in my package. So, can some one please help me how to call this oracle procedure (Created in Target schema) into ODI and run this.
thank you.Hi GRK,
You can create an ODI procedure, add a single step, choose Oracle as Technology and your target schema.
Then just call it through a pl/sql block :
BEGIN
TEST_MY_NEW_PROCE;
END;Then drag this ODI procedure in your package.
Regards,
JeromeFr -
Procedure or function for insert into select ...
Hi!
We need to know if we can create a procedure or function that will run the following script:
insert into agent.train_schedule
select 4000, '06:25' ,trunc(sysdate, 'year')+t.n
from agent.trains, (select rownum -1 n from dual
connect by level <= 365) t
where agent.trains.id = 4000 and
agent.trains.weekday like '%'||to_char(trunc(sysdate, 'year')+t.n, 'd',
'nls_date_language=AMERICAN')||'%';
The script inserts the train schedule dates into the train schedule table in accordance to the trains table.
Any help would be appreciated.
Thanks!Try the below:
Create Or Replace procedure test_proc(p_train_no number, p_train_time varchar2) as
begin
insert into agent.train_schedule
select p_train_no, p_train_time ,trunc(sysdate, 'year')+t.n
from agent.trains, (select rownum -1 n from dual
connect by level <= 365) t
where agent.trains.id = p_train_no and
agent.trains.weekday like '%'||to_char(trunc(sysdate, 'year')+t.n, 'd',
'nls_date_language=AMERICAN')||'%';
end;
Call the procedure from the gui also pass the train number and the train time.
Regards,
Samujjwal Basu -
Unable to call a procedure from inside a another procedure
Dear members
I am trying to call a procedure from inside an another procedure.Both the procedures are present within the same package.I am trying to call the second procedure just before the end of the first procedure.Both the procedures are compiling fine but the tables are not getting populated inside the second procedure.Also the DBMS_OUTPUT statements present in second procedures are not getting displayed.(I feel the second procedured is not getting called).
The package specification is as follows:
CREATE OR REPLACE package ANVESH.conv_api_pkg
is
PROCEDURE PROC_CONVERSION_API(FILE_PATH IN VARCHAR2,FILE_NAME IN VARCHAR2) ;
TYPE cts_order_details IS TABLE OF XXCTS_ORDER_DETAILS_STG%ROWTYPE;
PROCEDURE proc_conversion_api2(p_orderdetails IN cts_order_details) ;
end conv_api_pkg;The package body is as follows:
CREATE OR REPLACE package body ANVESH.conv_api_pkg
is
PROCEDURE PROC_CONVERSION_API(FILE_PATH IN VARCHAR2,FILE_NAME IN VARCHAR2)
IS
v_file_type utl_file.file_type;
v_buffer VARCHAR2(1000);
V_CUSTOMER_NAME VARCHAR2(100);
V_MANUFACTURER VARCHAR2(100);
V_PRODUCT_NAME VARCHAR2(100);
V_QUANTITY NUMBER;
V_REQ_SHIP_DATE DATE;
V_REQ_PRICE NUMBER;
V_LOG_FILE utl_file.file_type;
V_COUNT_CUST NUMBER;
V_COUNT_PROD NUMBER;
L_ORDER_LINES CONV_API_PKG.cts_order_details:=CONV_API_PKG.cts_order_details();
BEGIN
DBMS_OUTPUT.PUT_LINE('Inside begin 1');
v_file_type := UTL_FILE.fopen(FILE_PATH, FILE_NAME, 'r',null);
DBMS_OUTPUT.PUT_LINE('Inside begin 1.1');
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('Inside begin 2');
UTL_FILE.GET_LINE (v_file_type,v_buffer);
DBMS_OUTPUT.PUT_LINE('Inside begin 2.1');
DBMS_OUTPUT.PUT_LINE('the buffer is '||v_buffer);
DBMS_OUTPUT.PUT_LINE('the length of buffer is '||length(v_buffer));
V_CUSTOMER_NAME := trim(substr(v_buffer, 1, 30));
DBMS_OUTPUT.PUT_LINE('Customer Name is '||V_CUSTOMER_NAME);
V_MANUFACTURER := trim(substr(v_buffer, 31, 40));
DBMS_OUTPUT.PUT_LINE('Manufacturer is '||V_MANUFACTURER);
V_PRODUCT_NAME := trim(substr(v_buffer, 71, 20));
DBMS_OUTPUT.PUT_LINE('Product Name is '||V_PRODUCT_NAME);
V_QUANTITY := to_number(trim(substr(v_buffer, 91, 5)));
DBMS_OUTPUT.PUT_LINE('Quantity is '||V_QUANTITY);
V_REQ_SHIP_DATE := to_date(trim(substr(v_buffer, 96, 20)), 'DD-MON-YYYY');
DBMS_OUTPUT.PUT_LINE('Requested Ship Date is '|| V_REQ_SHIP_DATE);
V_REQ_PRICE :=nvl(substr( trim(v_buffer), 116, length(v_buffer)-116),0);
--DBMS_OUTPUT.PUT_LINE('Requested Price is1 '||substr(v_buffer, 116, 5));
DBMS_OUTPUT.PUT_LINE('The requested price is '||V_REQ_PRICE);
V_LOG_FILE := UTL_FILE.FOPEN(FILE_PATH, 'LOG_FILE.dat', 'A');
IF (V_QUANTITY > 0)
THEN
DBMS_OUTPUT.PUT_LINE('The quantity is '||V_QUANTITY);
SELECT COUNT (*)
INTO V_COUNT_CUST
FROM CONVERSION_CUSTOMERS
WHERE CUSTOMER_NAME = V_CUSTOMER_NAME;
DBMS_OUTPUT.PUT_LINE('The Customer count is '||V_COUNT_CUST);
IF(V_COUNT_CUST > 0)
THEN
SELECT COUNT(*)
INTO V_COUNT_PROD
FROM conversion_products
WHERE PRODUCT_NAME = V_PRODUCT_NAME;
DBMS_OUTPUT.PUT_LINE('The Product count is '||V_COUNT_PROD);
IF(V_COUNT_PROD >0)
THEN
INSERT INTO XXCTS_ORDER_DETAILS_STG VALUES (V_CUSTOMER_NAME, V_PRODUCT_NAME, V_MANUFACTURER, V_QUANTITY, V_REQ_SHIP_DATE, V_REQ_PRICE, 'ACTIVE', 'ORDER TAKEN');
ELSE
DBMS_OUTPUT.PUT_LINE('PRODUCT SHOULD BE VALID');
UTL_FILE.PUT_LINE(V_LOG_FILE, 'PRODUCT SHOULD BE VALID');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('CUSTOMER SHOULD BE VALID');
UTL_FILE.PUT_LINE(V_LOG_FILE, 'CUSTOMER SHOULD BE VALID');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('QUANTITY SHOULD BE VALID');
UTL_FILE.PUT_LINE(V_LOG_FILE, 'QUANTITY SHOULD BE VALID');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
SELECT CUSTOMER_NAME, PRODUCT_NAME, MANUFACTURER, QUANTITY, REQUESTED_SHIP_DATE, REQUESTED_PRICE, STATUS,MESSAGE
BULK COLLECT
INTO L_ORDER_LINES
FROM XXCTS_ORDER_DETAILS_STG;
DBMS_OUTPUT.PUT_LINE('values inserted');
proc_conversion_api2(p_orderdetails=>L_ORDER_LINES);
END;
PROCEDURE proc_conversion_api2(p_orderdetails IN cts_order_details)
IS
V_AVL_QUANTITY CONVERSION_PRODUCTS.AVL_QUANTITY%TYPE;
V_REQ_SHIP_DATE DATE;
V_LIST_PRICE CONVERSION_PRODUCTS.LIST_PRICE%TYPE;
V_NET_PRICE CONVERSION_PRODUCTS.LIST_PRICE%TYPE;
V_NET CONVERSION_PRODUCTS.LIST_PRICE%TYPE;
V_EXTN_PRICE CONVERSION_PRODUCTS.LIST_PRICE%TYPE;
V_CUST_DISC CONVERSION_CUSTOMERS.DISCOUNT%TYPE;
V_CERT_DISC CONVERSION_CERTIFICATION.DISCOUNT%TYPE;
V_CUST_ID XXCTS_ORDER_DETAILS.CUSTOMER_ID%TYPE;
V_PROD_ID XXCTS_ORDER_DETAILS.PRODUCT_ID%TYPE;
V_DISC_PRICE CONVERSION_PRODUCTS.LIST_PRICE%TYPE;
V_DISC_NAME CONVERSION_CERTIFICATION.CERTIFICATION%TYPE;
V_TOTAL_DISC_AMT NUMBER;
V_TOTAL_DISC NUMBER;
V_LIMIT NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('INSIDE API_2 BEGIN 1');
FOR i IN p_orderdetails.FIRST..p_orderdetails.LAST
LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('INSIDE API_2 BEGIN 2');
SELECT PRODUCT_ID,AVL_QUANTITY,LIST_PRICE
INTO V_PROD_ID,V_AVL_QUANTITY,V_LIST_PRICE
FROM CONVERSION_PRODUCTS
WHERE PRODUCT_NAME=p_orderdetails(i).PRODUCT_NAME;
DBMS_OUTPUT.PUT_LINE('PRODUCT QUANTITY is '||V_PROD_ID);
DBMS_OUTPUT.PUT_LINE('AVAILABLE QUANTITY is '||V_AVL_QUANTITY);
DBMS_OUTPUT.PUT_LINE('LIST PRICE is '||V_LIST_PRICE);
SELECT CUSTOMER_ID,NVL(DISCOUNT,0)
INTO V_CUST_ID,V_CUST_DISC
FROM CONVERSION_CUSTOMERS
WHERE CUSTOMER_NAME=p_orderdetails(i).CUSTOMER_NAME;
DBMS_OUTPUT.PUT_LINE('CUSTOMER ID is '||V_CUST_ID);
DBMS_OUTPUT.PUT_LINE('CUSTOMER DISCOUNT IS '||V_CUST_DISC);
SELECT A.DISCOUNT,A.CERTIFICATION
INTO V_CERT_DISC,V_DISC_NAME
FROM CONVERSION_CERTIFICATION A,CONVERSION_CUSTOMERS B
WHERE A.CERTIFICATION=B.CERTIFICATION(+)
AND B.CUSTOMER_NAME=p_orderdetails(i).CUSTOMER_NAME;
DBMS_OUTPUT.PUT_LINE('CERTIFICATION DISCOUNT IS '||V_CERT_DISC);
V_NET:=((V_LIST_PRICE)-(V_LIST_PRICE)*(V_CERT_DISC)/100);
DBMS_OUTPUT.PUT_LINE('NET PRICE AFTER CERTIFICATION DISCOUNT IS '||V_NET);
V_NET_PRICE:=((V_NET)-(V_NET)*(V_CUST_DISC)/100);
DBMS_OUTPUT.PUT_LINE('NET PRICE AFTER COMPLETE DISCOUNT IS '||V_NET_PRICE);
V_EXTN_PRICE:=(V_NET_PRICE)*(p_orderdetails(i).QUANTITY);
DBMS_OUTPUT.PUT_LINE('EXTENDED PRICE IS '||V_EXTN_PRICE);
V_TOTAL_DISC:=((V_CERT_DISC)/100+(V_CUST_DISC)/100);
DBMS_OUTPUT.PUT_LINE('TOTAL DISCOUNT IS '|| V_TOTAL_DISC);
V_TOTAL_DISC_AMT:=(V_LIST_PRICE)-(V_NET_PRICE);
DBMS_OUTPUT.PUT_LINE('TOTAL DISCOUNT PRICE IS '|| V_TOTAL_DISC_AMT);
SELECT MAX(A.LIMIT)
INTO V_LIMIT
FROM CONVERSION_CERTIFICATION A,CONVERSION_CUSTOMERS B
WHERE A.CERTIFICATION=B.CERTIFICATION(+)
AND B.CUSTOMER_NAME=p_orderdetails(i).CUSTOMER_NAME;
IF p_orderdetails(i).QUANTITY<V_AVL_QUANTITY THEN
INSERT INTO XXCTS_ORDER_DETAILS VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,V_CUST_ID,V_PROD_ID,p_orderdetails(i).QUANTITY,p_orderdetails(i).REQUESTED_SHIP_DATE,p_orderdetails(i).REQUESTED_PRICE,V_LIST_PRICE,V_TOTAL_DISC,V_NET_PRICE,V_EXTN_PRICE,'QTY HOLD','REQ QNTY LESS THAN AVL QTY',SYSDATE);
INSERT INTO xxcts_order_discounts VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,SEQ_DISCOUNT_ID.NEXTVAL,V_DISC_NAME,V_TOTAL_DISC_AMT);
END IF;
IF p_orderdetails(i).REQUESTED_SHIP_DATE<SYSDATE THEN
INSERT INTO XXCTS_ORDER_DETAILS VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,V_CUST_ID,V_PROD_ID,p_orderdetails(i).QUANTITY,p_orderdetails(i).REQUESTED_SHIP_DATE,p_orderdetails(i).REQUESTED_PRICE,V_LIST_PRICE,V_TOTAL_DISC,V_NET_PRICE,V_EXTN_PRICE,'DATE HOLD','SHIPDATE CANNOT BE LESS THAN CURR DATE',SYSDATE);
INSERT INTO xxcts_order_discounts VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,SEQ_DISCOUNT_ID.NEXTVAL,V_DISC_NAME,V_TOTAL_DISC_AMT);
END IF;
IF V_NET_PRICE>p_orderdetails(i).REQUESTED_PRICE THEN
INSERT INTO XXCTS_ORDER_DETAILS VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,V_CUST_ID,V_PROD_ID,p_orderdetails(i).QUANTITY,p_orderdetails(i).REQUESTED_SHIP_DATE,p_orderdetails(i).REQUESTED_PRICE,V_LIST_PRICE,V_TOTAL_DISC,V_NET_PRICE,V_EXTN_PRICE,'PRICE HOLD','NET PRICE CANNOT BE MORE THAN REQ PRICE',SYSDATE);
INSERT INTO xxcts_order_discounts VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,SEQ_DISCOUNT_ID.NEXTVAL,V_DISC_NAME,V_TOTAL_DISC_AMT);
END IF;
/* IF V_LIMIT<p_orderdetails(i).REQUESTED_PRICE THEN
INSERT INTO XXCTS_ORDER_DETAILS VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,V_CUST_ID,V_PROD_ID,p_orderdetails(i).QUANTITY,p_orderdetails(i).REQUESTED_SHIP_DATE,p_orderdetails(i).REQUESTED_PRICE,V_LIST_PRICE,V_TOTAL_DISC,V_NET_PRICE,V_EXTN_PRICE,'ORDER LIMIT HOLD','PRICE CANNOT EXCEED ORDER LIMIT',SYSDATE);
INSERT INTO xxcts_order_discounts VALUES(SEQ_HEADER_ID.NEXTVAL,SEQ_LINE_ID.NEXTVAL,SEQ_DISCOUNT_ID.NEXTVAL,V_DISC_NAME,V_TOTAL_DISC_AMT);
END IF;*/
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(' INSIDE EXCEPTION BLOCK');
END;
END LOOP;
END;
end conv_api_pkg;
/the pl/sql block to invoke the the procedure :
declare
begin
PROC_CONVERSION_API('/usr/tmp' ,'Walmart_Orders_062908.dat');
end;please let me know what is wrong in the program.
Thanks
AnveshHi Walter
Yes 'Inside begin 1' and 'Inside begin 2' were printed.Please find the the DBMS_OUTPUT statements that were printed.
Inside begin 1
Inside begin 1.1
Inside begin 2
Inside begin 2.1
the buffer is BESTBUY SONY ERICSSON W580i 25 1-AUG-2008 50
the length of buffer is 118
Customer Name is BESTBUY
Manufacturer is SONY ERICSSON
Product Name is W580i
Quantity is 25
Requested Ship Date is 01-AUG-08
The requested price is 50
The quantity is 25
The Customer count is 1
The Product count is 0
PRODUCT SHOULD BE VALID
Inside begin 2
Inside begin 2.1
the buffer is BESTBUY SAMSUNG BLACKJACK 50 15-JUL-2008 150
the length of buffer is 119
Customer Name is BESTBUY
Manufacturer is SAMSUNG
Product Name is BLACKJACK
Quantity is 50
Requested Ship Date is 15-JUL-08
The requested price is 150
The quantity is 50
The Customer count is 1
The Product count is 1
Inside begin 2
Inside begin 2.1
the buffer is BESTBUY APPLE IPHONE 4GB 50 15-JUL-2008
the length of buffer is 116
Customer Name is BESTBUY
Manufacturer is APPLE
Product Name is IPHONE 4GB
Quantity is 50
Requested Ship Date is 15-JUL-08
The requested price is 0
The quantity is 50
The Customer count is 1
The Product count is 1
Inside begin 2
Inside begin 2.1
the buffer is BESTBUY ATT TILT 100 15-JUN-2008
the length of buffer is 116
Customer Name is BESTBUY
Manufacturer is ATT
Product Name is TILT
Quantity is 100
Requested Ship Date is 15-JUN-08
The requested price is 0
The quantity is 100
The Customer count is 1
The Product count is 1
Inside begin 2
Inside begin 2.1
the buffer is BESTBUY NOKIA N73 50 15-JUL-2008 200
the length of buffer is 118
Customer Name is BESTBUY
Manufacturer is NOKIA
Product Name is N73
Quantity is 50
Requested Ship Date is 15-JUL-08
The requested price is 20
The quantity is 50
The Customer count is 1
The Product count is 0
PRODUCT SHOULD BE VALID
Inside begin 2In the first procedure I am trying to read the data from a flat file and store it in a table.Here is the sample data from the flat file.
BESTBUY SONY ERICSSON W580i 25 1-AUG-2008 50
BESTBUY SAMSUNG BLACKJACK 50 15-JUL-2008 150
BESTBUY APPLE IPHONE 4GB 50 15-JUL-2008
BESTBUY ATT TILT 100 15-JUN-2008
BESTBUY NOKIA N73 50 15-JUL-2008 200When tried to execute the second procedure independently using the PL/SQL block,the tables in second procedure were populated and the DBMS_Output statements were also displayed.I have made use of the same query in that case
Thanks
Anvesh
Edited by: Anvesh Reddy on Dec 23, 2008 12:40 PM -
Creating parameters dynamically and calling a procedure but strange issue
Okay I have the following program that is calling a procedure(data_compare_utility)[pasted below] and data_compare_table_setup table definition and data(isert scripts) are pasted below :
DECLARE
--FP_OLD_TABLE VARCHAR2(200);
--FP_NEW_TABLE VARCHAR2(200);
--FP_DATA_COMPARE_ID NUMBER(10) := 1;
--FP_RESTRICTION_CLAUSE VARCHAR2(500) := 'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')';
--FP_RESTRICTION_CLAUSE_4_INS VARCHAR2(500) := 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')';
cursor c_data_compare_table_setup
is
select table_name, old_schema_name, new_schema_name, data_compare_id, restriction_clause, restriction_clause_ins from DATA_COMPARE_TABLE_SETUP;
r_of_data_compare_table_setup c_data_compare_table_setup%rowtype;
Lv_args_4_data_compare_utility varchar2(500);
BEGIN
--FP_OLD_TABLE := 'BIAPPS_11.RAHUL_EMPLOYEES';
--FP_NEW_TABLE := 'RAHULKALRA.RAHUL_EMPLOYEES';
open c_data_compare_table_setup;
Loop
fetch c_data_compare_table_setup into r_of_data_compare_table_setup;
exit when c_data_compare_table_setup%NOTFOUND;
--exec RAHULKALRA.P_COMPARE_DATA_UTILITY
Lv_args_4_data_compare_utility := ''''||r_of_data_compare_table_setup.OLD_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','''||r_of_data_compare_table_setup.NEW_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','||r_of_data_compare_table_setup.DATA_COMPARE_ID||','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE||''','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE_INS||'''';
P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
commit;
End Loop;
dbms_output.put_line('rahul');
dbms_output.put_line(''''||r_of_data_compare_table_setup.OLD_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','''||r_of_data_compare_table_setup.NEW_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','||r_of_data_compare_table_setup.DATA_COMPARE_ID||','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE||''','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE_INS||'''');
--P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
--P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
close c_data_compare_table_setup;
END;
Procedure : compare_data_utility:
CREATE OR REPLACE procedure RAHULKALRA.p_compare_data_utility(fp1_old_table in varchar2, fp2_new_table in varchar2, fp3_data_compare_id in number, fp4_restriction_clause in varchar2, fp5_recrtiction_clause_4_ins in varchar2)
as
Lv_common_column_names varchar2(2000);
Lv_primary_column_name varchar2(50);
Lv_insert_data_compare_log varchar2(2000);
--Lv_counter number(10);
Lv_row_id_for_data_compare_log number(10);
Lv_old_table_record_count number(10);
Lv_old_table_rec_cnt_query varchar2(200);
Lv_new_table_record_count number(10);
Lv_new_table_rec_cnt_query varchar2(200);
begin
select max(row_id) into Lv_row_id_for_data_compare_log from data_compare_log;
Lv_old_table_rec_cnt_query := 'Select count(*) from '||fp1_old_table||' '||fp4_restriction_clause;
dbms_output.put_line(Lv_old_table_rec_cnt_query);
execute immediate Lv_old_table_rec_cnt_query into Lv_old_table_record_count;
Lv_new_table_rec_cnt_query := 'Select count(*) from '||fp2_new_table||' '||fp4_restriction_clause;
execute immediate Lv_new_table_rec_cnt_query into Lv_new_table_record_count;
dbms_output.put_line(fp5_recrtiction_clause_4_ins);
if (Lv_row_id_for_data_compare_log is null)
then
Lv_row_id_for_data_compare_log := 1;
else
Lv_row_id_for_data_compare_log := Lv_row_id_for_data_compare_log + 1;
end if;
Lv_insert_data_compare_log := 'insert into data_compare_log values('||Lv_row_id_for_data_compare_log||',''comparing data for '||fp1_old_table||' and '||fp2_new_table||''','''||fp1_old_table||''','''||fp2_new_table||''',TO_DATE('''||to_char(sysdate,'DD-MON-YY HH24:MI:SS')||''',''DD-MON-YY HH24:MI:SS''),'||fp3_data_compare_id||','||Lv_old_table_record_count||','''||'Select count(*) from '||fp1_old_table||' '||fp5_recrtiction_clause_4_ins||''','||Lv_new_table_record_count||','''||'Select count(*) from '||fp2_new_table||' '||fp5_recrtiction_clause_4_ins||''')';
dbms_output.put_line(Lv_insert_data_compare_log);
execute immediate Lv_insert_data_compare_log;
commit;
-- tested : dbms_output.put_line(Lv_insert_data_compare_log);
Lv_common_column_names := f_fetch_common_column_names(fp1_old_table,fp2_new_table,fp3_data_compare_id);
-- tested : dbms_output.put_line(Lv_common_column_names);
Lv_primary_column_name := f_extract_pkey_column_names(fp1_old_table, fp2_new_table);
dbms_output.put_line(Lv_primary_column_name);
p_compare_data(fp1_old_table,fp2_new_table,Lv_common_column_names,Lv_primary_column_name,fp4_restriction_clause,fp3_data_compare_id);
end;
CREATE TABLE RAHULKALRA.DATA_COMPARE_TABLE_SETUP
TABLE_ID NUMBER(10),
TABLE_NAME VARCHAR2(100 BYTE),
OLD_SCHEMA_NAME VARCHAR2(100 BYTE),
NEW_SCHEMA_NAME VARCHAR2(100 BYTE),
RESTRICTION_CLAUSE VARCHAR2(500 BYTE),
RESTRICTION_CLAUSE_INS VARCHAR2(500 BYTE),
DATA_COMPARE_ID NUMBER(10)
Insert into DATA_COMPARE_TABLE_SETUP
(TABLE_NAME, OLD_SCHEMA_NAME, NEW_SCHEMA_NAME, DATA_COMPARE_ID, RESTRICTION_CLAUSE, RESTRICTION_CLAUSE_INS)
Values
('W_CHNL_TYPE_D', 'BIAPPS_11', 'RAHULKALRA', 1, 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')', 'WHERE W_INSERT_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''') OR W_UPDATE_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''')');
Insert into DATA_COMPARE_TABLE_SETUP
(TABLE_NAME, OLD_SCHEMA_NAME, NEW_SCHEMA_NAME, DATA_COMPARE_ID, RESTRICTION_CLAUSE, RESTRICTION_CLAUSE_INS)
Values
('RAHUL_EMPLOYEES', 'BIAPPS_11', 'RAHULKALRA', 1, 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')', 'WHERE W_INSERT_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''') OR W_UPDATE_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''')');
I am facing the following error for this command when I call P_compre_data_utility procedure from my anonymous block:
P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility); -- the error is pasted below
if I do a dbms_output.put_line(Lv_args_4_data_compare_utility) and then copy paste its output and call P_COMPARE_DATA_UTILITY, the procedure is getting executed, here is that command :
P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
Error:
ORA-06550: line 27, column 7:
PLS-00306: wrong number or types of arguments in call to 'P_COMPARE_DATA_UTILITY'
ORA-06550: line 27, column 7:
PL/SQL: Statement ignored
Question : just want to know whats wrong with : P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
please help me.
Regards
RahulMac_Freak_Rahul wrote:
Hi All,
I am really sorry, my head is so aching since I am not a regular plsql coder and to save my life I need to write this code for data comparison between 2 tables .. further sorry about calling p_data_compare utility stupidly : P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
I am calling it now using :
execute immediate 'exec P_COMPARE_DATA_UTILITY('||Lv_args_4_data_compare_utility||')';If you are sure the call works then, exec would not work since it is a SQLPLUS command.
try
execute immediate 'BEGIN P_COMPARE_DATA_UTILITY(''||Lv_args_4_data_compare_utility||''); END;';
PS: I can manually give table names to my utility , just need 60 tables to compare but would be great if I can work it out this eay.
2) I can sound very stupid since my head is aching I am not a regular plsql coder but from now on I would be one, please helpJust for your sake, to Compare 60 tables (Supposing you just want to verify count of records), you are writing an entire procedure; You might have completed this activity by now doing the manual way. By taking this way, you are investing time to generate a correct code (as you just mentioned not being a regular plsql developer) you are stuck with some un-identifiable issues.
As an alternate way, I would suggest you to export the data, after ordering, into a spreadsheet and then validate. Also, since it looks like you are comparing the data in the same database between schemas, you can also use the SQL Navigators Data Compare utility and there are many more readily available in market.
I would wish you the best if you still prefer taking the approach. -
hi,
Every thing is set now. But only one issue is left over.
CREATE OR REPLACE package dyn_query_MBU21
is
type r_cur is ref cursor;
procedure get_query(p_scorecard_id in integer,p_user_id in integer,p_start_bu in integer,p_end_bu IN INTEGER,p_parent_srsid in integer);
procedure printQuery(p_scorecard_id integer,p_user_id integer,p_start_bu integer,p_end_bu integer,p_parent_srsid integer);
end dyn_query_MBU21;
CREATE OR REPLACE package body dyn_query_MBU21
is
procedure get_query(p_scorecard_id in integer,p_user_id in integer,p_start_bu in integer,p_end_bu IN INTEGER,p_parent_srsid in integer)
is
l_query VARCHAR2(32700);
v_temp varchar2(300);
v_strLength integer;
val integer;
--p_start_bu INTEGER;
--p_end_bu INTEGER;
--v_cur r_cur;
l_buCount integer default 0;
BEGIN
l_query := 'select
a.PLAN_TO_WIN PTWID,
a.SPQRC SPQRCID,
l.NAME Plan_to_Win,
m.NAME BPD,
a.metric_id,
a.NAME Key_Measures,
a.DESCRIPTION,
c.DATE_MONTH_DIM_KEY,
c.CALENDAR_MONTH_NBR,
c.CALENDAR_YEAR_MONTH_CDE,
e.SRS_ID,e.YEAR_VALUE,
f.YTD_VALUE YTD,
g.CALENDAR_YEAR_NBR,
h.FIRST_NAME || h.LAST_NAME Scorecard_Owner
, j.TYPE_NAME Management_Level,
k.NAME Business_Unit
, N.SCORECARD_ID
, N.NAME
, K.LOC_CURRENCY_ID
--decode(ltrim(rtrim(k.PARENT_SRS_ID)),' || p_parent_srsid || ', k.NAME) Parent_BU ';
, decode(ltrim(rtrim(k.PARENT_SRS_ID)),3,''Bill Boggs'') Parent_BU ';
for x in ( select distinct NAME from SRS_DIM where parent_srs_id = p_parent_srsid and rownum < 20)
loop
l_buCount := l_buCount + 1;
l_query := l_query ||
' , decode(ltrim(rtrim(K.NAME)),'''||ltrim(rtrim(x.NAME))||''', D.MONTH_VALUE ) '||replace(to_char(x.NAME),' ','_');
-- dbms_output.put_line('this is the query'||l_query);
end loop;
l_query := l_query ||
' FROM
METRIC_DIM A,TARGET_MONTH B,DATE_MONTH_DIM C,METRIC_SRS_MONTH_EVAL D,TARGET_YEAR E,METRIC_SRS_YTD_EVAL F,DATE_YEAR_DIM G,
GM_USER_DIM H,USER_PRIV I,SRS_ITEMTYPE_DIM J,SRS_DIM K,PLAN_TO_WIN_DIM L,SPQRC_DIM M,SCORECARD_DIM N
WHERE
L.PLAN_TO_WIN_ID= A.PLAN_TO_WIN
AND M.SPQRC_ID= A.SPQRC
AND A.METRIC_ID=B.METRIC_ID
AND B.DATE_MONTH_DIM_KEY=C.DATE_MONTH_DIM_KEY
AND B.SRS_ID=K.SRS_ID
AND B.SRS_ID=F.SRS_ID
AND D.SRS_ID=F.SRS_ID
AND D.SRS_ID=K.SRS_ID
AND D.DATE_DIM_KEY=C.DATE_MONTH_DIM_KEY
AND D.METRIC_ID = B.METRIC_ID
AND D.METRIC_ID = E.METRIC_ID
AND D.METRIC_ID = F.METRIC_ID
and d.SRS_ID=b.SRS_ID
and d.DATE_DIM_KEY=b.DATE_MONTH_DIM_KEY
AND E.SRS_ID = F.SRS_ID
AND G.DATE_YEAR_DIM_KEY = E.DATE_YEAR_DIM_KEY
AND G.CALENDAR_YEAR_NBR = C.CALENDAR_YEAR_NBR
AND F.DATE_DIM_KEY = E.DATE_YEAR_DIM_KEY
AND K.PARENT_SRS_ID =n.SRS_ID
AND N.SCORECARD_ID= :p_scorecard_id
AND H.USER_ID = :p_user_id
AND K.SRS_ID BETWEEN :p_start_bu AND :p_end_bu
--AND P_PARENT_SRS_ID = :p_parent_srsid1
-- ANd n.Scorecard_id=2
-- AND H.USER_ID = 7000001
AND J.TYPE_ID = :p_parent_srsid
--AND K.SRS_ID = 8
GROUP BY
a.PLAN_TO_WIN,
a.SPQRC,
l.NAME,
m.NAME,
a.metric_id,
a.NAME,
a.DESCRIPTION,
c.DATE_MONTH_DIM_KEY,
c.CALENDAR_MONTH_NBR,
c.CALENDAR_YEAR_MONTH_CDE,
e.SRS_ID,
e.YEAR_VALUE,
f.YTD_VALUE,
g.CALENDAR_YEAR_NBR,
h.FIRST_NAME || h.LAST_NAME,
j.TYPE_NAME,
K.NAME,
l.PLAN_TO_WIN_ID,
m.SPQRC_ID,
N.SCORECARD_ID,
N.NAME,
K.LOC_CURRENCY_ID,
--decode(ltrim(rtrim(k.PARENT_SRS_ID)),' || p_parent_srsid || ', k.NAME) Parent_BU ';
, decode(ltrim(rtrim(k.PARENT_SRS_ID)),3,''Bill Boggs'') Parent_BU ';
for x in (select distinct NAME from SRS_DIM where parent_srs_id = p_parent_srsid and rownum < 20 )
loop
l_query := l_query ||' , decode(ltrim(rtrim(K.NAME)),''' || x.NAME || ''', D.MONTH_VALUE ) ';
end loop;
l_query := l_query ||'order by a.PLAN_TO_WIN';
-- open p_cur for l_query using p_scorecard_id,p_user_id,p_start_bu,p_end_bu,p_parent_srsid;
select (length(l_query)/255) + 1 into v_strLength from dual;
dbms_output.put_line('String Lenghth is :'||v_strLength);
for c in 1..v_strLength
loop
if c = 1 then
v_temp := SUBSTR(l_query, 1, 255);
else
if length(l_query) > (255 * c) then
v_temp := SUBSTR(l_query, 255 * (c-1) , 255);
end if;
end if;
dbms_output.put_line(v_temp);
end loop;
end get_query;
procedure printQuery(p_scorecard_id in integer,p_user_id in integer,p_start_bu in integer,p_end_bu IN INTEGER,p_parent_srsid in integer) is
Begin
get_query(p_scorecard_id,p_user_id,p_start_bu,p_end_bu,p_parent_srsid);
End printQuery;
end dyn_query_MBU21;
I want to split this procedure into 6 procedures to make it look easier.
1.getSQLSelect
2.getSQLFrom
3.getSQLWhere
4.getSQLGroupBY
5.getSQLOrderBY
add another proc...getSQL that returns all the above procs ie,
I need to build the entire sql & call "Open Cursor" meaning...getSQLSelect||getSQLFrom()...
How to do this ?
Thanks in AdvanceYou're missing a comma.
-
How to call one procedure from another procedure
Hi all,
Could anyone give me clue how to call a procedure contains out parameters
from another procedure.
I had following procedures.
1)
create or replace procedure INS_PUR_ORDER
p_poamt in number,
p_podate in date,
p_poid out number
is
begin
select pkseq.nextval into p_poid from dual;
insert into pur_order(poamt,podate,poid)
values (p_poamt,p_podate,p_poid);
end;
2)
create or replace procedure INS_PUR_ORDER_DETAIL
p_pounits in number,
p_poddate in date,
p_poid in number)
is
begin
Insert into pur_order_detail(podid,pounits,poddate,poid)
values(pdseq.nextval,p_pounits,p_poddate,p_poid);
end;
I need to write a 3rd procedure which calls above two procedures.
like
call first procedure ,basing on the return value
i.e if p_poid != 0 then
we need to call second procedure
in the loop.
thanks in advance.
rampa.Not sure what are you doing, you can not assign cursor to another cursor, may be you are looking for this?
SQL> create or replace procedure proc1 ( result out sys_refcursor)
2 is
3
4 begin
5 open result for
6 select 'HELLO WORLD' from dual ;
7 end proc1 ;
8 /
Procedure created.
Elapsed: 00:00:00.01
SQL> create or replace procedure proc2
2 is
3 l_cursor sys_refcursor ;
4 begin
5 l_cursor := proc1 ;
6
7
8 open l_cursor;
9 fetch l_cursor into l_text;
10 dbms_output.put_line(l_text);
11 close l_cursor;
12
13
14 end proc2 ;
15 /
Warning: Procedure created with compilation errors.
Elapsed: 00:00:00.01
SQL> show error;
Errors for PROCEDURE PROC2:
LINE/COL ERROR
5/4 PL/SQL: Statement ignored
5/16 PLS-00306: wrong number or types of arguments
in call to 'PROC1'
6/4 PLS-00201: identifier 'L_TEXT' must be
declared
6/4 PL/SQL: Statement ignored
8/4 PLS-00382: expression is of wrong type
8/4 PL/SQL: SQL Statement ignored
9/4 PL/SQL: SQL Statement ignored
9/24 PLS-00201: identifier 'L_TEXT' must be
declared
10/4 PL/SQL: Statement ignored
10/25 PLS-00201: identifier 'L_TEXT' must be
declared
---- this is the correct waySQL>ed
1 create or replace procedure proc2
2 is
3 l_cursor sys_refcursor ;
4 l_text varchar2(100);
5 begin
---- procedure call
6 proc1(l_cursor);
7 -- open l_cursor;
8 fetch l_cursor into l_text;
9 dbms_output.put_line(l_text);
10 close l_cursor;
11* end proc2 ;
SQL> /
Procedure created.
Elapsed: 00:00:00.01
SQL> set serveroutput on
SQL> execute proc2;
HELLO WORLD
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> -
Mergeing multiple procedures into a single package ???
Hello Gurus,
I m moving the data from the from one schema i,e source(SRC) schema to the another schema i,e target(trg) table, only selected columns of few tables (i,e for 4 tables)
I m writing procedures to accomplish this and put this procedures to a scheduler on a daily basis to load
I m writing 4 procedures one for each of the table .....here is the procedure i have got
create or replace procedure mov_tbl1
is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
tbl1_cur_rec tbl1_cur%rowtype;
begin
for tbl1_cur_rec in tbl1_cur
loop
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
commit
exception
when others then
rollback;
end loop;
end;
---for table 2
create or replace procedure mov_tbl2
is
cursor tbl2_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl2 src
where col3 = ' abc'
tbl2_cur_rec tbl2_cur%rowtype;
begin
for tbl2_cur_rec in tbl2_cur
loop
insert into tgt.table2(col1,col2,col3,col4)
values ( tbl2_cur_rec.col1,
tbl2_cur_reccol2,
tbl2_cur_rec.col3,
tbl2_cur_rec.col4);
commit
exception
when others then
rollback;
end loop;
end;
similarly procedures for table 3 and table 4....
here is my question....
1.How can i build a single package for all these four procedures in one package ???
2. ANd i don't want to call each procedure every time ...so can i do it by passing parameters ??? how can i accomplish that ??
I m new to writing packages ....any help is greatly appriciated ....Thank you so much gurus!!!!First of all your code doesn't compile because the exception block is inside the loop while begin and end are outside.
You have to decide whether a single row error has to invalidate the full load or if the single wrong row has to be rejected but all the other rows have to be loaded.
I suppose you need the latter hence I'm changing the code as follows:
create or replace procedure mov_tbl1
is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
-- the record variable declaration is implicit in FOR LOOP
begin
for tbl1_cur_rec in tbl1_cur
loop
begin
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
-- REMOVED COMMIT, Commit outside or at the end.
exception
when others then
null; -- May be is better to (somehow) log the error ...
end;
end loop;
end;About the package, you create it this way:
create or replace package p is
procedure upd (tab1 in boolean, tab2 in boolean, tab3 in boolean, tab4 in boolean);
end;
create or replace package p is
procedure upd (tab1 in boolean, tab2 in boolean, tab3 in boolean, tab4 in boolean) is
begin
if tab1=true then
mov_tbl1;
end if;
if tab2=true then
mov_tbl2;
end if;
if tab2=true then
mov_tbl2;
end if;
if tab2=true then
mov_tbl2;
end if;
end;
procedure mov_tbl1 is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
-- the record variable declaration is implicit in FOR LOOP
begin
for tbl1_cur_rec in tbl1_cur
loop
begin
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
-- REMOVED COMMIT, Commit outside or at the end.
exception
when others then
null; -- May be is better to (somehow) log the error ...
end;
end loop;
end;
procedure mov_tbl2 is ...
procedure mov_tbl3 is ...
procedure mov_tbl4 is ...
end;
/You can call the upd procedure (that calls the others) this way:
begin
p.upd(true,false,true,false);
end;
/To update only table1 and table3.
Max
http://oracleitalia.wordpress.com -
Error in calling collection procedure.
Hi Experts,
In a package I have one procedure "setscores_ram_bulk" with collection varaiavles.
And other two procedures are "UpdateRelatedOrders" and "SetGeoFraudScore" with out collections.
I am calling collection procedure "setscores_ram_bulk" in non collection procedures "UpdateRelatedOrders" and "SetGeoFraudScore".
I am getting the below error.
PLS-00306:wrong number or types of arguments in call to 'SETSCORES_RAM_BULK' .
I am sending my code.
CREATE OR REPLACE PACKAGE GAFT_PROG_DIT.INTERNAL_SCORING_setscore_Bulk
IS
TYPE rec_setscores IS RECORD
pBUID score.buid%TYPE,
OrderNum score.order_num%TYPE,
ScoreType VARCHAR2(100),
p_Score score.velocity_score%TYPE
type pp_rec_setscores is table of rec_setscores index by pls_integer;
PROCEDURE UpdateRelatedOrders (pBUID IN NUMBER, OrderNum IN VARCHAR2);
PROCEDURE SetGeoFraudScore (pBUID IN NUMBER,
OrderNum IN VARCHAR2,
ZipCode IN VARCHAR2,
CountryCode IN VARCHAR2,
score OUT NUMBER);
PROCEDURE setscores_ram_bulk (p_rec_setscores pp_rec_setscores);
END;
CREATE OR REPLACE PACKAGE BODY GAFT_PROG_DIT.INTERNAL_SCORING_setscore_Bulk
IS
PROCEDURE UpdateRelatedOrders (pBUID IN NUMBER, OrderNum IN VARCHAR2)
IS
tScoreID STAGING_ORDER_DATA.SCORING_ID%TYPE;
tVelocity SCORE.VELOCITY_SCORE%TYPE;
tNegative SCORE.NEGATIVE_SCORE%TYPE;
tTrend SCORE.TREND_SCORE%TYPE;
CURSOR scoreCursor (
scoreID NUMBER,
OrdNum VARCHAR2)
IS
SELECT ORDER_NUM
FROM STAGING_ORDER_DATA
WHERE SCORING_ID = scoreID
AND ADDRESS_TYPE = 'S'
AND ORDER_NUM != OrdNum;
BEGIN
SELECT SCORING_ID
INTO tScoreID
FROM STAGING_ORDER_DATA
WHERE BUID = pBUID AND ORDER_NUM = OrderNum AND ADDRESS_TYPE = 'S';
IF tScoreID IS NOT NULL
THEN
SELECT VELOCITY_SCORE, NEGATIVE_SCORE, TREND_SCORE
INTO tVelocity, tNegative, tTrend
FROM SCORE
WHERE BUID = pBUID AND ORDER_NUM = OrderNum;
FOR ord_rec IN scoreCursor (tScoreID, OrderNum)
LOOP
setscores_ram_bulk (pBUID,ord_rec.ORDER_NUM,'V',tVelocity);
setscores_ram_bulk (pBUID,ord_rec.ORDER_NUM,'N',tNegative);
setscores_ram_bulk (pBUID,ord_rec.ORDER_NUM,'T',tTrend);
END LOOP;
IF scoreCursor%ISOPEN
THEN
CLOSE scoreCursor;
END IF;
END IF;
END UpdateRelatedOrders;
PROCEDURE SetGeoFraudScore (pBUID IN NUMBER,
OrderNum IN VARCHAR2,
ZipCode IN VARCHAR2,
CountryCode IN VARCHAR2,
score OUT NUMBER)
IS
tZipCodeExist NUMBER;
tScore NUMBER;
BEGIN
SELECT COUNT (Score)
INTO tZipCodeExist
FROM MASTER_GEO_FRAUD
WHERE REPLACE (UPPER (ZIP_CODE), ' ', '') =
REPLACE (UPPER (ZipCode), ' ', '')
AND COUNTRY_CODE = CountryCode;
IF tZipCodeExist > 0
THEN
SELECT Score
INTO tScore
FROM MASTER_GEO_FRAUD
WHERE REPLACE (UPPER (ZIP_CODE), ' ', '') =
REPLACE (UPPER (ZipCode), ' ', '')
AND COUNTRY_CODE = CountryCode;
ELSE
tScore := 1000;
END IF;
setscores_ram_bulk (pBUID,OrderNum,'XS',tScore);
COMMIT;
score := tScore;
END SetGeoFraudScore;
PROCEDURE setscores_ram_bulk (p_rec_setscores pp_rec_setscores)
IS
BEGIN
FORALL i IN 1 .. p_rec_setscores.COUNT
MERGE INTO score s
USING (SELECT p_rec_setscores (i).pBUID buid,
p_rec_setscores (i).OrderNum order_num,
p_rec_setscores (i).p_score score
FROM DUAL) p
ON (s.buid = p.buid AND s.order_num = p.order_num)
WHEN MATCHED
THEN
UPDATE SET
velocity_score =DECODE (p_rec_setscores (i).ScoreType,'V', p.score,velocity_score),
negative_score =DECODE (p_rec_setscores (i).ScoreType,'N', p.score,negative_score),
trend_score =DECODE (p_rec_setscores (i).ScoreType,'T', ROUND (p.score),trend_score),
vendor_combined_score =DECODE (p_rec_setscores (i).ScoreType,'X', p.score,vendor_combined_score),
vendor_bt_score =DECODE (p_rec_setscores (i).ScoreType,'XB', p.score,vendor_bt_score),
vendor_st_score =DECODE (p_rec_setscores (i).ScoreType,'XS', p.score,vendor_st_score)
WHEN NOT MATCHED
THEN
INSERT (buid, order_num, received_date_time)
VALUES (p.buid, p.order_num, SYSDATE);
FORALL i IN 1 .. p_rec_setscores.COUNT
MERGE INTO score_filter_apply s
USING (SELECT p_rec_setscores (i).pBUID buid,
p_rec_setscores (i).OrderNum order_num,
p_rec_setscores (i).p_score score
FROM DUAL) p
ON (s.buid = p.buid AND s.order_num = p.order_num)
WHEN MATCHED
THEN
UPDATE SET
velocity_score =DECODE (p_rec_setscores (i).ScoreType,'V', p.score,velocity_score),
negative_score =DECODE (p_rec_setscores (i).ScoreType,'N', p.score,negative_score),
trend_score =DECODE (p_rec_setscores (i).ScoreType,'T', ROUND (p.score),trend_score),
vendor_combined_score =DECODE (p_rec_setscores (i).ScoreType,'X', p.score,vendor_combined_score),
vendor_bt_score =DECODE (p_rec_setscores (i).ScoreType,'XB', p.score,vendor_bt_score),
vendor_st_score =DECODE (p_rec_setscores (i).ScoreType,'XS', p.score,vendor_st_score)
WHEN NOT MATCHED
THEN
INSERT (buid, order_num, received_date_time)
VALUES (p.buid, p.order_num, SYSDATE);
END setscores_ram_bulk;
END;
/Please help me.
Thanks in advance.BluShadow wrote:
Paul Horth wrote:
You haven't taken any notice of what Alberto posted in {message:id=11026562} I see.
Why should anyone bother helping you if you never think we have answered your questions?Indeed, that must be a new record:
>
Total Posts: 336
Total Questions: 160 (160 unresolved)
>
Out of 160 questions... none of them have been resolved.
That's either down to poor answers (very unlikely with the amount of experts around) or poor questions (quote likely) or sheer laziness on feeding back on answers and marking questions as answered when they have been (most likely).Indeed, your own post just after Alberto's seems to sum it up :-) -
Calling a Procedure from a Button? (REVISITED)
Hi All,
I once asked a question Re: Calling a Procedure from a Button? & that problem was resolved when i was working on the online ApEx.
On my application, requirements have changed a bit: I have one form based on two tables. One table contributes two fields (name & surname) to the form while the remaining fields are contributed by another table to make a total of 17 fields on the form.
My process is in such a way that a user enters an id number & clicks Search button, if the apllicant exists then both name & surname corresponding with the id number will be retrieved from the database. If the applicant does not exist then an error message will be displayed inline with the id number field. Here's the PL/SQL anonymous block to that:
DECLARE
vNAME APPLICANTS.name%TYPE;
vSURNAME APPLICANTS.surname%TYPE;
BEGIN
SELECT count(*)
INTO :P2_COUNT
FROM applicants
WHERE id_number = :P2_ID_NUMBER;
IF :P2_COUNT > 0 THEN
SELECT name,surname
INTO vNAME, vSURNAME
FROM applicants
WHERE id_number = :P2_ID_NUMBER;
:P2_NAME := vNAME;
:P2_SURNAME := vSURNAME;
ELSE
apex_application.g_print_success_message := '<span style="color:red">Applicant does not exist.</span>';
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
apex_application.g_print_success_message := '<span style="color:red">Exception Caught.</span>';
END;The PL/SQL block works except for error displaying part (but that's a problem for another day).
NB: On my application, there’s already Automated Row Fetch & Automatic Row Processing (DML) processes for one table. Furthermore, there is also a javascript for verifying the validity of an id number. As a result, I decided to include Automated Row Fetch & Automatic Row Processing (DML) processes for the other table. When I click a Search button the javascript is activated even though I did not specify a URL target for the button - because this is a simple button among region items – it does not have Optional Url Redirect section.
I'm not sure what I'm doing wrong here - any help is appreciated.
Regards
KamoHi Dan,
Sorry for causing confusion with my post - it's just that I was asking the same question (with different constraints) as I had asked before so I didn't feel like going to details was necessary because in my post I included a link to the previous thread. Interestingly, I was working on apex.oracle.com when I posted the original thread - the only problem came to be when I started to move the solution to my application on my machine.
Anyway, thanks for the response!
Regards
Kamo -
Call stored procedure with OUT parameter
Hello,
I have created a short-lived process. Within this process I am using the "FOUNDATION > JDBC > Call Stored Procedure" operation to call an Oracle procedure. This procedure has 3 parameters, 2 IN and 1 OUT parameter.
The procedure is being executed correctly. Both IN parameters receive the correct values but I am unable to get the OUT parameter's value in my process.
Rewriting the procedure as a function gives me an ORA-01460 since one of the parameters contains XML (>32K) so this is not option...
Has someone been able to call a stored procedure with an OUT parameter?
Regards,
NicoObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
Creation of DB Adaptert for calling stored procedure in MS SQL server
Hi,
I need to create a DB adapter to call a stored procedure in MS SQL Server.
I have gone thru the thread MS SQL Server database connection
It mentions that we need to use a command line utility for generating the wsdl and xsd for calling stored procedures in MS SQL server. Please provide information where to find this utility and how to use it.
Any links to tutorials are welcome.
Thanks !!.
Silas.Command line is required for stored procedures, if you are using the basic options you don't need to worry.
(1) Download MS SQL Server 2005 JDBC Driver from Microsoft Site. http://msdn.microsoft.com/en-us/data/aa937724.aspx
(2) The download is self extracting exe file. Extract this into Program Files on your machine. It should create folder as "Microsoft SQL Server 2005 JDBC Driver"
(3) In above mentioned folder search for sqljdbc.jar copy this file into JDeveloper\JDBC\lib folder.
(4) Open JDeveloper/jdev/bin/jdev.conf file add following entry.
AddJavaLibPath C:/Program files/Microsoft SQL Server 2000 Driver for JDBC/lib
While executing this step make sure that your JDeveloper is closed.
(5) On command prompt go to J Developer folder and execute following command
jdev -verbose
This will open JDeveloper.
(6) Now go to JDeveloper > Connections > Database Connections > New Database Connection
(7) Select Third Party JDBC
(8) Specify MS Sql Server User Name, password and Role.
(9) In connection page specify following
- Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
- For class path browse to C:/Program files/Microsoft SQL Server 2000 Driver for JDBC/lib folder, select sqljdbc.jar add it as library.
- Specify URL as following.
jdbc:sqlserver://SERVERNAME:1433;databaseName=MSSQLDBNAME;
(10) Go to Test page and test it.
cheers
James
Maybe you are looking for
-
Acer AL1913W (16:10 1440x900) Help Please!
I have a Mac Mini with the Acer 19" (16:10) 1440 x 900 display and have some things I cannot figure out...The Mac Mini recognizes the display (1440 x900, 60Htz, Millions) but iPhoto is having issues: 1. iPhoto slideshows does not keep the image in pr
-
Wish to create an automatic script on the server.
I am using a tomcat server, Mysql database and jsp to perform some data manipulation. I would like to create a java class which could be initiated at specific intervals. My question is, even if we create a class which makes use of Java timer, .......
-
I uses 3 language on a daily basis for mail. English, Korean, & Japanese. Mac is pretty good about encoding Foreign characters. But there seems problem with lot of them. I have good luck with gmail, but Yahoo & hotmail reciepenct are a mess. I tried
-
Am busy with development of a http post xml messages exchange. We have the problem that the messages returned are not formatted correctly. 1) http post calls xsql 2) xsql does an insert into a table 3) triggers processes the rows and prepare output i
-
Need some advise on a AEBS set up and LAN
Ok. Signed up on DSL2+. I have a DSL modem i can bridge... i have 1x Airport Extreme (n + Giga LAN) and 1x Airport Express (n). My apartment is cabled with Cat 5e. Im looking to get the fastest experience both for WAN and LAN possible and am wanting