Dynamically call another procedure
In SQLServer you can have a variable that holds a procedure
name. The variable can then be used in the execute statement.
Is there any way in PLSQL to dynamicaly call another procedure.
example:
begin
declare procname varchar2(32) = 'proc1';
--now call the procedure
procname -- ?
execute immediate procname -- ?
end;
Thanks,
Dermot.
Just wrap it in an anonymous block:
create or replace procwrap
(p_procname in varchar2)
is
begin
execute immediate 'begin ' || p_procname || '; end;';
end;
Similar Messages
-
In SQLScript, how to use EXEC to call another procedure with parameters in procedure?
Hi experts,
In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very muchHi Sagar,
thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
create procedure ftest1(out sum_num bigint)
as
begin
declare fa_output bigint;
declare v_sql_drop varchar(200);
declare v_sql varchar(500);
declare cursor c_cursor1 for select num from TABLE1;
--v_sql_drop := 'drop procedure fe';
--exec v_sql_drop;
v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
v_sql := :v_sql || ' end';
exec v_sql;
open c_cursor1;
for c_item as c_cursor1 do
exec 'call fe(c_item.num,o_num=>fa_output)';
if sum_num is null then
sum_num := fa_output;
else
sum_num := :sum_num + fa_output;
end if;
end for;
close c_cursor1;
end;
The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again! -
Writing a simple procedure to call another procedure
Greetings,
im pretty new to pl/sql and just recently started playing around with it, I was wondering howi would go about creating a basic skeleton of procedure that would call another procedure.
function testfunction is the function I wish to call and accepts 3 params, it then returns a pl/sql table which contains all the rows I want. I then want to populate a table with this data. Do I need to create a loop within the procedure to populate the table or can I use a function of some sort to just directly insert the entire pl/sql table into the actual table?Thankyou both for the follow ups! I may have to go with the loop method but before I dive into that I was reading about the merge function and feel as though it would do what I need perfectly (I just need to append data to a table)
So I came up with something like this
PROCEDURE test_procedure
IS
BEGIN
MERGE INTO test_table
USING (test_package.test_function(123, 456, 789))
WHEN MATCHED THEN UPDATE SET FIELDA = resulta, FIELDB = resultb, FIELDC = resultc
WHEN NOT MATCHED THEN INSERT (FIELDA, FIELDB, FIELDC) VALUES (resulta, resultb, resultc)
END test_procedure;
This seems like it would work great, the resulta, resultb, and resultc are all returned from the function but im not sure exactally about that being the correct way to call it. I will go read up on this approach but fall back on the looping if it doesnt work out, thankyou everyone =D -
Need to write a plsql block for calling another procedure.
Hi Guys,
I have a requirement to write a plsql block and to call another procedure which is having 5 parameters (each parameter having multiple values). Calling procedure generates one SQL query and it needs to be generated all combinations and print in another table.
I need to pass multiple values for first three parameters from my PLSQL block and run.
call sample proc:
procedure(
param1 varchar2,
param2 p_varchar2,
param3 p_varchar2,
param4 in varchar2,
param5 in number
is
begin
ls_sql_query := 'with client_query as (select * from table)';
end;
Thanks in advance!
Rgds,
LRKThis article is on exactly your subject. It is worth a careful read.
Ask Tom: On Popularity and Natural Selection
I paraphrase: "Always code a reference to every possible bind variable but do so in such a way that the optimizer removes the bind variable for us if we aren't going to actually use it in that particular execution of the SQL statement."
P.S. This is the same answer I gave when you asked the same question earlier. -
Pocedure calling another procedure
Hi all,
I hav a procedure which will display all the student records.
CREATE OR REPLACE procedure a
AS
CURSOR o IS
SELECT * FROM lgrade;
o_rec o%ROWTYPE;
BEGIN
OPEN o;
LOOP
FETCH o INTO o_rec;
EXIT WHEN o%NOTFOUND;
dbms_output.put_line(o_rec.cno||' '||o_rec.csno ||' '||o_rec.descript||' '|| o_rec.sfname||' '||o_rec.slname||' '|| o_rec.score||' '|| o_rec.grade);
END LOOP;
CLOSE o;
END;
It displays course, section numbers, student's name , score and grade.
CS 10 2 DP Overview Jeff Runyan 86.333 B
CS 100 2 Hands, On Windows Peggy Noviello 89 B
CS 100 1 Hands, On Windows Debra Boyce 88.766 B
CS 100 1 Hands, On Windows Rommel Frost 88.1 B
CS 100 2 Hands, On Windows J. Segall 85.333 B
CS 100 5 Hands, On Windows Jose Benitez 91.6 A
CS 100 4 Hands, On Windows Mrudula Philpotts 90.613 A
CS 100 4 Hands, On Windows Gene Bresser 84.568 B
CS 100 3 Hands, On Windows Michael Lefbowitz 86.916 B
CS 100 1 Hands, On Windows Lula Oates 82.1 B
CS 100 1 Hands, On Windows Roger Snow 90.266 A
CS 100 3 Hands, On Windows Monica Waldman 86.472 B
CS 100 1 Hands, On Windows Regina Bose 94.1 A
CS 100 1 Hands, On Windows Jenny Golsmith 87.1 B
1) I want to use this procedure inside another procedure say b to display only certain cousre records. How can i do that?
2) I want to use this procedure inside another procedure to display particular student's different course grades. How can i do that?PL/SQL is not usually used this way - displaying data. The DBMS_OUTPUT interface is very primitive - and does not "display" anything. It is a static PL buffer that contains lines. The client, e.g. SQL*Plus/TOAD, displays its contents after calling Oracle to execute code.
That said, PL/SQL can be used to teach programming fundamentals - despite the fact that this is NOT how one would usually apply the PL/SQL language to real problems.
A display procedure should be just that - display. Nothing else. A well designed procedure (or function) does a single job, and does it well. So a display proc can look as follows:
create or replace procedure DisplayStudent( studentRow lgrage%rowtype ) is
begin
dbms.output.put_line( ... insert your display contents ... );
.. etc ..
end;
1) I want to use this procedure inside another procedure say b to display only certain cousre records. How can i do that?
2) I want to use this procedure inside another procedure to display particular student's different course grades. How can i do that?The same way. By using SQL to specify the data set that you want to display. For example:
begin
for student in ( select l.* from lgrade l where l.score >= 80 ) -- display students with a score of 80% plus
loop
DisplayStudent( student ); -- call the display proc and pass it a student row to display
end loop;
end;
/And that is the basic approach. Two important factors.
Modularise. A good program design means creating building blocks to solve the problem. Where a block can be re-used (like the DisplayStudent procedure above).
Maximize SQL. SQL is a very capable and powerful program language. You use it to crunch the data. You do not pull all the rows from the table into PL/SQL and then apply an IF condition to filter the data. That is row-by-row and slow-by-slow processing. -
Calling another procedure in a procedure
How can we execute procedure in another procedure?
Try running following code
create or replace procedure child is
begin
dbms_output.put_line('This text from Child');
end;
create or replace procedure parent is
begin
child;
end;
exec parent;
null -
PL/SQL precedure calling another procedure
Can someone provide an example of a procedure calling a second procedure. I have two procedures which work fine when called via exec from sql*plus, but when the first trys to call the second, I start getting errors. The first execute immediate runs, but errors out, the second execute immediate doesn't compile.
Thanks
HeaderProc
is
cursor h is
select * from header where val2 <> 'Y';
--func_call varchar2(100);
begin
dbms_output.put_line('Starting HeaderProc');
for current_header in h
loop
dbms_output.put_line('"' | | current_header.val1 | | '","' | | current_header.val2 | | '"');
-- EXECUTE IMMEDIATE 'exec user.childproc(10)';
--EXECUTE IMMEDIATE 'exec childproc(' | | 'current_header'.'key' | | ')';
end loop;
end;
ChildProc
(p_key IN number) is
cursor h is
select * from child where parent = p_key;
begin
dbms_output.put_line('Starting child');
for current_child in h
loop
dbms_output.put_line('"' | | current_child.cval1 | | '","' | | current_child.cval2 | | '"');
end loop;
end;
nullTo call a proc from another proc simply call it by name from the first proc.
childproc(current_header.key) ;
null -
Dynamically calling stored procedure and getting result set c++
Hello,
I am trying to write some c++ code that will dynamically bind values to a stored procedure and excute the procedure and get back a resultset. The problem I am running into is how to get back the resultset. Any help or example would be highly appreciated.int main(int argc, char* argv[])
OCIError* pOciError;
char* pConnectChar = "dbname";
char* pUsernameChar = "scott";
char* pPasswordChar = "tiger";
int answer;
OCIStmt* pOciStatement;
char* sqlCharArray = "BEGIN :success := sp_ListEmp; END;";
int id;
char ename[40];
OCIEnv* g_pOciEnvironment = NULL;
OCIServer* g_pOciServer = NULL;
OCISession* g_pOciSession = NULL;
OCISvcCtx* g_pOciServiceContext = NULL;
sb2* pIndicator=0;
sb2* pIndicator2=0;
sb2* pIndicator3=0;
OCIDefine* pOciDefine;
OCIDefine* pOciDefine2;
OCIBind* pBind;
OCIStmt* cursor;
answer = OCIInitialize(OCI_THREADED, NULL, NULL, NULL, NULL);
answer = OCIEnvInit(&g_pOciEnvironment, OCI_DEFAULT, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciSession, OCI_HTYPE_SESSION, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServer, OCI_HTYPE_SERVER, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
answer = OCIServerAttach(g_pOciServer, pOciError, (unsigned char *)pConnectChar, strlen(pConnectChar),
OCI_DEFAULT);
answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pUsernameChar, strlen(pUsernameChar),
OCI_ATTR_USERNAME, pOciError);
answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pPasswordChar, strlen(pPasswordChar),
OCI_ATTR_PASSWORD, pOciError);
answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciServer, 0, OCI_ATTR_SERVER, pOciError);
answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciSession, 0, OCI_ATTR_SESSION, pOciError);
answer = OCISessionBegin(g_pOciServiceContext, pOciError, g_pOciSession, OCI_CRED_RDBMS, OCI_DEFAULT);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&pOciStatement), OCI_HTYPE_STMT, 0, NULL);
answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray, strlen(sqlCharArray),
OCI_NTV_SYNTAX, OCI_DEFAULT);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&cursor), OCI_HTYPE_STMT, 0, NULL);
answer = OCIBindByPos(pOciStatement,&pBind, pOciError, 1, &cursor, 0,SQLT_RSET,
pIndicator2, 0,NULL, 0,0,OCI_DEFAULT);
answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
OCI_COMMIT_ON_SUCCESS);
answer = OCIDefineByPos(cursor,&pOciDefine, pOciError,2,&id,sizeof(int),
SQLT_INT,pIndicator, 0, 0,OCI_DEFAULT);
answer = OCIDefineByPos(cursor,&pOciDefine2, pOciError,1,ename,40,
SQLT_STR,pIndicator3, 0, 0,OCI_DEFAULT);
if (answer == 0)
while ((answer = OCIStmtFetch(cursor,pOciError, 1,OCI_FETCH_NEXT,OCI_DEFAULT)) == 0)
printf("fetched id %d and name %s\n",id,ename);
answer = OCIHandleFree(pOciError, OCI_HTYPE_ERROR);
return 0; -
How to call another procedure???
I create a procedure, and inside this procedure there are others procedures in xxx.sql (vi file)...
how to call these procedutes???
Urgent...
ThanksIf I understood well u have two sql files, say x.sql and y.sql (u used vi to write them).
Suppose u want to call y.sql in a certain row of the x.sql file. Then just put inside the x.sql file.
@y
If you have a PL/sql procedure inside your sql file, maybe it's different.
I hav't tried all of the possibilities, but if the procedure u want to call is a stored one, just call its name.
I hope it helps.
Bye Dino -
Dynamic SQL Stored Procedure call in Pro*C Application
Hello All
Could you help with a sample Pro*C program (or snippet) which has a dynamic call to a stored procedure? The procedure to be called is determined at run time and so also the number of parameters to it.
Is this even possible using Pro*C?
Thanks in Advance
RDHi Colin & Faust
We found sample pro*c programs for dynamically calling PL/SQL blocks but not for dynamically calling stored procedures.
Heres the program we compiled successfully but it doesnt work, it gives a core dump on execution. Could you point out whats wrong.
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<sqlca.h>
#include<string>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<thread.h>
#include<sqlda.h>
#include<sqlcpr.h>
using namespace std;
#define TRUE 1
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *UserID = getenv( "DATABASE" );
char query[100];
EXEC SQL END DECLARE SECTION;
SQLDA *bind_des;
EXEC SQL CONNECT :UserID;
EXEC SQL WHENEVER SQLERROR CONTINUE;
bind_des = SQLSQLDAAlloc( 0, 2, (size_t)10, (size_t)0 );
bind_des->N = 2;
strcpy( query, "CALL sel_dept( :empno,:name );");
//Calling stored procedure sel_dept( no NUMBER IN, name VARCHAR2 OUT)
EXEC SQL PREPARE sql_stmt from :query;
EXEC SQL DESCRIBE BIND VARIABLES FOR sql_stmt INTO bind_des;
bind_des->N = bind_des->F;
//cout << " bind_des->N after assigment = " << bind_des->N;
//--------------------- Enter the Input values -----------------------------
//parameter :1
bind_des->L[0] = 4;
/* Allocate storage for value and null terminator. */
bind_des->V[0] = (char *) malloc(bind_des->L[0] + 1);
/* Store value in bind descriptor. */
strcpy(bind_des->V[0], "50");
/* Set datatype to STRING. */
bind_des->T[0] = 2;
//parameter :2
bind_des->L[1] = 20;
/* Allocate storage for value and null terminator. */
bind_des->V[1] = (char *) malloc(bind_des->L[1] + 1);
/* Store value in bind descriptor. */
strcpy(bind_des->V[1], "");
/* Set datatype to STRING. */
bind_des->T[1] = 5;
EXEC SQL EXECUTE sql_stmt;
//cout<<"name"<<"\t"<bind_des->V[0]<<"\t"<<bind_des->V[1]<<endl;
cout << "name"<<"\t";
cout << "bind_des->V[0]=" << bind_des->V[0]<<"\t";
cout << "bind_des->V[1]=" << bind_des->V[1]<<"\t"<<endl;
for (int i = 0; i < bind_des->F; i++) /* for bind descriptor */
free(bind_des->V);
free(bind_des->I[i]);
SQLSQLDAFree(0, bind_des);
EXEC SQL COMMIT;
return 0; -
Update Query with Results From another Procedure
I am not sure if you can do this or what the proper format of the command might look like.
I have a stored procedure which insert records into a database. I want to insert the records which are returned by calling another procedure. This other procedure returns a cursor object to a variable named o_rows. Can this be done using Oracle 8i?
Insert into MyTable
MyStoredProcedure(oRows);You have a couple of options.
1) You can turn your stored procedure into a pipelined table function. This would allow you to do something like
INSERT INTO myTable
SELECT *
FROM TABLE( myStoredProcedure() );I don't believe that pipelined table functions were available in 8i, however.
2) The other option would be to fetch rows from the cursor and insert those into your table. Something like
LOOP
FETCH oRows INTO col1, col2, col3, col4, ...
INSERT INTO myTable( <<column list>> )
VALUES( col1, col2, col3, col4 );Note that for simplicity I am omitting the declarations of the local variables col1, col2, etc. and the check to see whether the cursor was exhausted.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Best Way to call Dynamically an stored procedure
Hi Guys,
Here my question... I need to call dynamically to an stored procedure...
- the stored procedure can change, the name , the number of parameters
- the called stored procedure can contain output parameters.
lv_sql := 'BEGIN '|| lv_program_name || ' ( ' || get_parameters(lv_program_name) || '); END;';
get_parameters function generates an string depeding on the number of parameters that this function reads from the
oracle dictionary (i.e: ':1,:2,:3,:4......... )
then the dynamyc code must be executed as follow
execute immediate lv_sql
using .................................?????????
The issue that I am facing is how to handle the "using clause".... since before that I ran the program I dont know how many parameters the program will have...
Please your help... (or suggestion to solve in another way)
...:::OKMMAN:::...About "Satyaki_De " comment,
Since I dont know the stored procedure to be called, I cant know the number of parameters and its type to be returned... I mean.. to use the clause "using ...." in static way...
By now, I am creating dinamically a stored procedure... I am building a stored procedure that calls to the "unknown" stored procedure... reading the data dictionary and building dynamically the "Using...." clause... but I dont like ... since probably in production enviroment I will not have that kind of grants....
Regarding the link... I didn't know that new type... ! That's will solve the type issue... but still is pending the number of variable to provide to the "using" clause...
...:::OKMMMAN:::...
Edited by: okmman_cl on Feb 11, 2009 1:59 PM -
Calling a procedure dynamically in forms
Hi all
I'm using Oracle 6, is there anyway to call a procedure dynamically, i mean the procedure called differs according to a certain condition. The procedure is local in the form not in the database, how can this be achieved
ThanksHello,
user497979 wrote:
what i want is as the following
IF cond = 1 THEN
proc1;
ELSIF cond = 2 THEN
proc2;
ELSIF cond = 3 THEN
proc3;
.................. so onWell, i think the way you are showing with IF CONDITION is smart enough to call the procedures. And it will be also easy to understand.
I'm searching for a way to call the procedure as follows
proc||cond for exampleBut why? What is the purpose to do like this? Any efficiency or any logical reason?
Another option You can create one procedure and call the code depend on parameter you pass like
PROCEDURE MY_PROC(pCond IN NUMBER) IS
BEGIN
IF pCond=1 THEN
-- Do something here...
ELSIF pCond=2 THEN
-- Do something here...
ELSE
-- Do something here...
END IF;
END;And while calling the procedure you can call the procedure by passing the value of pCond upon your requirement like
MY_PROC(<parameter value>);But still the IF CONDITION exists either you use inside or outside the procedure.
-Ammad -
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 -
How to call a procedure with refcursor from another plsql unit
example I created a pkg with the a procedure that returns a REFCURSOR.
Now I need to call this procedure from another pkg and use the refcursor values in other pkg.
Help please.......
PROCEDURE CustomerSite_Get (p_Registry IN VARCHAR2,
p_CustomerNumber IN VARCHAR2, p_Cursor IN OUT t_cursor);
PROCEDURE CustomerSite_Get (p_Registry IN VARCHAR2,
p_CustomerNumber IN VARCHAR2, p_Cursor IN OUT t_cursor)
IS
-- 0903: Include BillToName
BEGIN
OPEN p_Cursor FOR
SELECT S.LOCATION CustomerSite, S.SITE_USE_ID CustomerSiteID, C.CUSTOMER_NAME BillToName
FROM RA_CUSTOMERS C,
RA_ADDRESSES A,
RA_SITE_USES S,
UWA_REGISTRY R,
UWA_REGISTRY_BILL_TO B
WHERE C.CUSTOMER_ID = A.CUSTOMER_ID
AND A.ADDRESS_ID = S.ADDRESS_ID
AND S.SITE_USE_ID = B.SITE_USE_ID
AND R.REGISTRY_ID = B.REGISTRY_ID
AND B.TRIP_BILLING != 'N'
AND R.DELETE_FLAG != 'Y'
AND R.Registry = p_Registry
AND R.CUSTOMER_NUM = p_CustomerNumber
ORDER BY S.LOCATION;
END CustomerSite_Get;
thanks,
Anitha.
Edited by: user521218 on May 6, 2009 1:24 PMHi Anitha,
try this,
-- PKG_A
Procedure CustomerSite_Get( p_Registry IN Varchar2
, p_CustomerNumber IN Varchar2
, p_Cursor IN OUT t_cursor) Is
Begin
PKG_B.CustomerSite_Get( p_Registry
, p_CustomerNumber
, p_Cursor );
End;
-- PKG_B
Procedure CustomerSite_Get(p_Registry IN Varchar2
,p_CustomerNumber IN Varchar2
,p_Cursor IN OUT t_cursor) Is
Begin
Open p_Cursor For
SELECT S.LOCATION CustomerSite
,S.SITE_USE_ID CustomerSiteID
,C.CUSTOMER_NAME BillToName
FROM RA_CUSTOMERS C
,RA_ADDRESSES A
,RA_SITE_USES S
,UWA_REGISTRY R
,UWA_REGISTRY_BILL_TO B
WHERE C.CUSTOMER_ID = A.CUSTOMER_ID
AND A.ADDRESS_ID = S.ADDRESS_ID
AND S.SITE_USE_ID = B.SITE_USE_ID
AND R.REGISTRY_ID = B.REGISTRY_ID
AND B.TRIP_BILLING != 'N'
AND R.DELETE_FLAG != 'Y'
AND R.Registry = p_Registry
AND R.CUSTOMER_NUM = p_CustomerNumber
Order BY S.LOCATION;
End CustomerSite_Get;regards,
Christian Balz
Maybe you are looking for
-
After upgrading to iOS 5 my music crash when i turn the iphone vertical to horizontal !!
after upgrading to iOS 5 my music crash when i turn the iphone vertical to horizontal !!
-
How to create a blank PDF using acrobat SDK in perl or c#
please help me with creating blank pdf using acrobat SDK in c# or in perl
-
2007 CD2 mini - monitor & TV out?
Can a CD2 mini drive both a monitor and RCA video out without having to plug things in and out every time? It doesn't matter if it mirrors or spans I am just wondering if I pick one up to replace a G4 tower that can do exactly this that a Mini would
-
Jdev database adapter config wizard
hi, i'm using JDeveloper 10.1.2 and mySQL Server 4.1 i realized that i have to use JDeveloper to be able to set up DBAdapters for my BPEL process .. anyway, i created a new PartnerLink, i click on the Define Adapter Service icon, then i get the ADAPT
-
Custom Transaction running slow on R/3 4.7 ,Oracle 10.2.0.4
Hi, We have a custom transaction for checking the roles related to an transaction. We have the same copy of the program in DEE, QAS and PRD(obvious). The catch is in DEE the transaction runs very slow, whereas in QAS and PRD the transaction is normal