My first procedure.
My first sproc isn't going too well. All I want to do is create something very simple. So I:
create or replace procedure oe.foo
as
begin
select * from oe.myCustomers
end;
and get the message: "Warning: Procedure created with compilation errors."
From Googling I discovered "sho err", and the message produced was "PLS-00103: Encountered the symbol "end-of-file" when expecting on e 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> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pi pe".
According to an example at: http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6009.htm#SQLRF01309
it seems as though my code should be working. Can someone please assist?
TIA, ChrisR
Hi there,
What you're trying to do doesn't really make sense. Simply put, if you are SELECTing records from a database table, you need somewhere to put them. This means you need a variable in which to store the result (if the query is going to return a single row), or you need to fetch into arrays (if there's going to be more than one row returned), or you need to define your query as an explicit cursor and use PL/SQL's cursor management features.
As a "hello, world" for PL/SQL, try the following:
[email protected](161)> create or replace procedure foo
2 as
3 begin
4 dbms_output.put_line('Hello, world!');
5 end;
6 /
Procedure created.
[email protected](161)> exec foo();
Hello, world!
PL/SQL procedure successfully completed.As a "hello, world" with a fetch, try the following:
[email protected](161)> create or replace procedure foo
2 as
3 l_row dual%rowtype;
4 begin
5 -- A query guaranteed to return a single row
6 select *
7 into l_row
8 from dual;
9
10 dbms_output.put_line('Dummy: '||l_row.dummy);
11 end;
12 /
Procedure created.
[email protected](161)> exec foo();
Dummy: X
PL/SQL procedure successfully completed.To continue learning, I'd recommend the PL/SQL Developer's guide, rather than the SQL Reference. Here's the link:
http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
cheers,
Anthony
Similar Messages
-
Speed test: PL/SQL vs. Java Stored Procedures
I performed tests on these two procedures:
===========================================
// Create a Statement
Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// Query the table
ResultSet rset = stmt.executeQuery ("select SIFOB, SIFRA_GU from sezko");
while (rset.next ()) {
salary = rset.getInt(1);
rset.updateInt (1, salary + 1);
salary = rset.getInt(2);
rset.updateInt (2, salary + 1);
rset.updateRow();
} // while
conn.commit();
// Close the RseultSet
rset.close();
// Close the Statement
stmt.close();
===========================================
procedure updateTable is
cursor c_updateTable is select rowid, SIFOB, SIFRA_GU from sezko;
begin
for r_updateTable in c_updateTable loop
update sezko set SIFOB = SIFOB + 1, SIFRA_GU = SIFRA_GU + 1 where rowid = r_updateTable.rowid;
end loop;
commit;
end;
===========================================
First procedure is written in Java (as Java Stored procedure) and second is PL/SQL.
Java is about 10x slower than PL/SQL code.
Can you explain bad performance results?
thank you
Matic & AlesHi,
I suppose the problem is not with the connection object,but with make connection to the database for every executeupdate or executeupdaterow called .Similarly for fetching the data from the database you
can use the fetch size technique.Please check the 8.1.6 Java Developers guide for using this.
Update Batching(For Batch updates and commits)
Fetch Size(For Batch fetching)
Oracle Row Pre-Fetching
Regards
Anand
null -
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 -
PL/SQL procedure to kill inactive session
Hi all ,
Please i am trying to write a procedure to kill inactive sessions of the shema 'TESTSCHEMA' .This is my first procedure , am not use to pl/sql but i went through many turtorial but have some errors at compliation .when i try to compile the procedure the errors are as below :
15:50:28 Start Find Objects [TESTSCHEMA@TESTDB_UNIX(2)] ...
15:50:28 End Find Objects [TESTSCHEMA@ TESTDB_UNIX(2)]
15:50:32 Start Compiling 1 object(s) ...
15:50:32 Executing ALTER PROCEDURE fib_dead_cnx_cleanup COMPILE ...
15:50:32 [13:2] PL/SQL: ORA-00933: SQL command not properly ended
15:50:32 [9:3] PL/SQL: SQL Statement ignored
15:50:32 [18:12] PLS-00103: Encountered the symbol "(" when expecting one of the following:
15:50:32 constant exception <an identifier>
15:50:32 <a double-quoted delimited-identifier> table LONG_ double ref
15:50:32 char time timestamp interval date binary national character
15:50:32 nchar
15:50:32 The symbol "<an identifier>" was substituted for "(" to continue.
15:50:32 [18:21] PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
15:50:32 := ; not null default character
15:50:32 The symbol "; was inserted before "LOOP" to continue.
15:50:32 [27:8] PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
15:50:32 begin case declare exit for goto if loop mod null pragma
15:50:32 raise return select update while with <an identifier>
15:50:32 <a double-quoted delimited-identifier> <a bind variable> <<
15:50:32 close current delete fetch lock insert open rollback
15:50:32 savepoint set sql execute commit forall merge pipe
15:50:32 Compilation complete - 5 error(s) found
15:50:32 End Compiling 1 object(s)
below is the procedure code :
CREATE OR REPLACE
PROCEDURE fib_dead_cnx_cleanup
AS
l_serial CHAR(100);
l_sid CHAR (100);
l_sid_serial CHAR(100);
l_count NUMBER(10,0);
CURSOR session_cur IS
SELECT sid,serial#,sid||','||serial# as sid_serial
FROM v$session
WHERE username='EBBFCAT' and schemaname='TESTSCHEMA'
and status='INACTIVE'
BEGIN
BEGIN
l_count := 0;
OPEN session_cur;
WHILE ( 1 = 1) LOOP
BEGIN
FETCH session_cur INTO l_sid ,l_serial,l_sid_serial ;
EXIT WHEN session_cur%NOTFOUND ;
BEGIN
alter system kill session 'l_sid_serial' ;
END;
END;
END;
CLOSE session_cur;
END;
END FIB_DEAD_CNX_CLEANUP;
ThanksHi,
Never write, let alone post, unformatted code.
When posting any formatted text on this site, type these 6 characters:
{code}
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
Among the benefits of formatting: you can indent to show the extent of blocks, such as BEGIN-END.
Different types of blocks need modifiers after the end, such as "END *IF* " and " END *LOOP* ". If each opening statement (BEGIN, IF, LOOP) is directly above its corresponding END, then it's easy to check if you got the right modifier.
Here's what you code looks like with some formatting, and a couple of corrections added. Look for -- comments.
CREATE OR REPLACE
PROCEDURE fib_dead_cnx_cleanup
AS
l_serial CHAR(100);
l_sid CHAR (100);
l_sid_serial CHAR(100);
l_count NUMBER(10,0);
CURSOR session_cur IS
SELECT sid
, serial#
, sid || ','
|| serial# as sid_serial
FROM v$session
WHERE username = 'EBBFCAT'
and schemaname = 'TESTSCHEMA'
and status = 'INACTIVE'; -- need semicolon here
BEGIN
BEGIN -- Why?
l_count := 0;
OPEN session_cur;
WHILE ( 1 = 1)
LOOP
BEGIN -- Why?
FETCH session_cur
INTO l_sid
, l_serial
, l_sid_serial ;
EXIT WHEN session_cur%NOTFOUND ;
BEGIN -- Why?
alter system kill session 'l_sid_serial' ; -- Not a PL/SQL command
END;
END;
END LOOP; -- LOOP ends with END LOOP
CLOSE session_cur;
END;
END FIB_DEAD_CNX_CLEANUP;Take baby steps.
I've been wrtiing PL/SQL for 20 years, and I would never write that much code at once. If you're a beginner, all the more reason to start small. Write as little as possible, test, debug and test again (if necessary). When you have someting working, add 2 or 3 more lines and test again.
It looks like you have three BEGIN statements that don't serve any purpose. You should get rid of them (and their corresponding END statements, of course).
One error I did not fix: ALTER SYSTEM is not a PL/SQL statement. It's a SQL statement. You can run a SQL statement inside PL/SQL by using dynamic SQL, where you construct a string containing the SQL statement, and then use dbms_sql or EXECUTE IMMEDIATE to run it.
Edited by: Frank Kulash on Aug 18, 2009 12:37 PM -
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> -
How to poll a PL/SQL procedure in BPEL?
Hi,
Normally in BPEL your start your process flows by receiving an event. You can only create a BPEL instance via a Receive or Pick activity. I have a couple of integrations where I have to continually call a PL/SQL procedure and then call another PL/SQL procedure with the output from the first procedure. This is done by invoking 2 partner links and a While activity. I got this working fine. The problem is how to create the instance. At the moment I start the flow by reading in a dummy file with a Receive event. This works for now but if the process has to be restarted it will not work since BPEL know that it has already read the file.
I have tried to start the flow with a receive activity that calls a PL/SQL procedure but I get the error “Operation is not specified” (http://theheat.dk/bpelDb1.jpg). Normally you would use a Invoke activity when calling a PL/SQL procedure, but when I try that I get an error because I don’t have a receive activity first (http://theheat.dk/bpelDb2.jpg)
So basically I need a way to have a receive activity call a PL/SQL procedure.
I have the exact same problem when I need to continually call a Web Service and send the output to a PL/SQL procedure. Here I need an Invoke activity that calls the Web Service and an Invoke that calls the PL/SQL procedure but to get the flow initiated BPEL wants a receive activity.
Regards PeteI found a simple solution that works but I would like to hear if anybody can see any problems with this approach:
I create a dummy table with one row. I create a partner link that polls the dummy table every 5 minutes. The operation on the table is an update, but the Read value and Unread value are the same!
Every 5 minutes BPEL kicks of a process that calls a PL/SQL procedure etc. There will always be a row in the dummy table and as long as my polling interval is longer than the processing time of the flow I will never have more than one process in-flight at a time. This should ensure that the solution is robust.
Regards Pete
Message was edited by:
Peter Lorenzen
Message was edited by:
Peter Lorenzen -
How to pass a CURSOR as an input in a Stored Procedure ?
Hi all
I am using Java to work with 2 Oracle DBs, using JDBC.
I've got a question about using a Oracle Stored Procedure with CURSORs :
A first stored procedure gets data from the first DB (returns a CURSOR) and I'd like to pass this CURSOR to the second stored procedure as a (Java) IN parameter, so using a "getObject()" then a "setObject()", to insert data from the CURSOR in the second DB.
This is the theory !
En reality, the first stored procedure works fine, and returns the cursor, but after that ... I can't even create the second stored procedure. I planed to do something like the following stuff :
CREATE OR REPLACE PROCEDURE proc_insert_data(cur_ref IN OUT types.ref_cursor) AS
BEGIN
LOOP
FETCH cur_ref INTO FIELD1, FIELD2;
INSERT INTO TABLENAME VALUES (FIELD1, FIELD2);
EXIT WHEN cur_ref%NotFound;
END LOOP;
END proc_insert_data;
with a LOOP for each row and then an INSERT.
But this doesn't seeem to be correct.
Has anybody an idea to make this stored procedure to work ?
Thx in advance
KrystoffffHi Chris,
When you want to pass a CURSOR to a procedure/function
you will have to employ a package here. Create a package
which contains both of your procedures.This package should have a global variable which is of type ref cursor.The IN parameter for the 2nd procedure and the OUT parameter of the first proc should be of type this global cursor var.
Now you call the first procedure and get the resulting cursor from it, pass it to the second procedure...
Good luck.
Regards,
Madhu -
Importance of object dependency type procedure
Hi Friend,
Good Morningu2026
Could any one explain the importance of object dependency type procedure and its uses with same scenario.
Thanks in advance,
Mohan MHi Mohan,
Procedures are used to infer values for charecterisitcs. These are a type of object dependencies used in VC.
Procedures can overwrite defualt values or they can set defualt values for charecterisitcs, several procedures can be assigned to an object (for eg. a BOM item or operation) and define processing sequence.
These are maintained in Charecteristics, Charecteristic values, configuration profiles, BOM item, Routing operation etc.
Eg: Processing Sequence:
A configurable material has characteristics COLOR and PRESSURE. The following procedures are allocated to the configuration profile of the material.
0010 $SELF.COLOR = u2018GREENu2019 IF PRESSURE >= 10
0020 $SELF.COLOR = u2018YELLOWu2019 IF PRESSURE >= 50
0030 $SELF.COLOR = u2018REDu2019 IF PRESSURE >= 100
The sort sequence ensures that pressure greater than or equal to 100 always sets the color u2018redu2019.
Inferring Charecteristic Values with procedures:
Let's assume Configurable material BIKE has the following characteristics:
CharacteristicS AND THEIR Values
WEIGHT
FRAME Aluminum 10 KG
Steel 14 KG
EXTRAS (multiple-value) Mudguard 0.5 kg
Luggage rack 1.0 kG
Procedure
1. Create a procedure for the weight of the BIKE, depending on the frame.
2. This procedure has the following source code:
$SELF. WEIGHT = 10 if FRAME = u2018Aluminumu2019,
$SELF. WEIGHT = 14 if FRAME = u2018Steelu2019.
3. Allocate the procedure to the configuration profile of material BIKE.
The weight of a bicycle increases if you select additional extras, such as mudguard or luggage
rack.
1. You define a procedure with the following source code:
$SELF.WEIGHT = $SELF.WEIGHT + 0.5 if EXTRAS = 'Mudguard',
$SELF.WEIGHT = $SELF.WEIGHT + 1 if EXTRAS = 'Luggage rack'
2. Allocate the procedure to the configuration profile of material BIKE.
Result
1. When you configure the bike, the value u2018Aluminumu2019 is selected for characteristic FRAME.
This triggers the first procedure, which sets the value 10 kg as the WEIGHT.
2. Characteristic EXTRAS has values u2018Mudguardu2019 and u2018Luggage racku2019. This triggers the
second procedure, which increases the value of characteristic WEIGHT to 11.5 kg.
You can also use procedures to count or summurize values of charecterisitics.
You can use procedure to change the values in master data such as BOM / routing. and also to maintain default values.
Hope this will be helpful to you. Any queries, Please post.
Regards,
Pavan -
Isolation Levels in ODI procedures
Hi,
I have a package with 1 interfaces and 2 procedures which I want to configure in as one transactional unit
The package executes the following sequence
1. Interface loads data from the source to target table
2. Procedure updates a statuscode on the source table to S
3. Procedure updates target table sequence number, but the procedure contains a where clause which filter records to updates
based on records in the source table with statuscode = S.
Step 3's execution is dependent on update in step 2. These steps behave as expected and all units tests pass when I
leave the transaction porperty of the procedures as AutoCommit.
However I want the interface and packages to be executed as a transcational unit so I configued them as follows.
The 2 procedures are configured to execute in the same Transaction (Transaction 0) with Commit property as "No Commit".
I based this on other forum entries.
With this configuration my unit tests seem to fail, the 3 step does not result in any record being updated.
I think the issue may be related to the isolation levels on the procedures, so I then configured the procedure's "Transaction Isolation" property to be "Read Uncommited".
When I ran the test in ODI I got the following error below.
Can you let me know if what I am trying to do is possible ?. Can you have a number of procedures in a single transactional unit,
where uncommited changes carried out in the first procedure(not committed), can be read in subsequent steps within that same transactional unit.
I am current using ODI Repository: Development_ODI_D8B4A_RC5
Any feedback would be appreciated.
Thanks,
Breda
ODI-1226: Step UPD REVN LSM fails after 1 attempt(s).
ODI-1232: Procedure UPD REVN LSM execution fails.
ODI-1228: Task UPD REVN LSM (Procedure) fails on the target ORACLE connection SALES_IMP_DATA_SERVER.
Caused By: java.sql.SQLException: ODI-10068: SnpsConnection: Isolation level not supported
at com.sunopsis.sql.SnpsConnection.setTransactionIsolation(SnpsConnection.java:905)
at com.sunopsis.sql.SnpsConnection.changeIsolationLevel(SnpsConnection.java:329)
at com.sunopsis.dwg.dbobj.SnpSession.changeIsolationLevel(SnpSession.java:3519)
at com.sunopsis.dwg.dbobj.SnpSessTask.getDefaultDwgConnectConnection(SnpSessTask.java:518)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.getExecutor(SnpSessTaskSql.java:2936)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2878)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2602)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:546)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:461)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1736)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1591)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$2.doAction(StartScenRequestProcessor.java:568)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:224)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor.doProcessStartScenTask(StartScenRequestProcessor.java:489)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$StartScenTask.doExecute(StartScenRequestProcessor.java:1062)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:118)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$1.run(DefaultAgentTaskExecutor.java:49)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor.executeAgentTask(DefaultAgentTaskExecutor.java:41)
at oracle.odi.runtime.agent.processor.TaskExecutorAgentRequestProcessor.doExecuteAgentTask(TaskExecutorAgentRequestProcessor.java:94)
at oracle.odi.runtime.agent.processor.TaskExecutorAgentRequestProcessor.process(TaskExecutorAgentRequestProcessor.java:85)
at oracle.odi.runtime.agent.RuntimeAgent.startScenario(RuntimeAgent.java:700)
at oracle.odi.runtime.agent.InternalRuntimeAgent.startScenario(InternalRuntimeAgent.java:52)
at com.sunopsis.dwg.tools.StartScen.startScenOnLocalAgent(StartScen.java:983)
at com.sunopsis.dwg.tools.StartScen.actionExecute(StartScen.java:245)
at com.sunopsis.dwg.function.SnpsFunctionBaseRepositoryConnected.execute(SnpsFunctionBaseRepos
Edited by: user807308 on 14-Jan-2011 01:04
Edited by: user807308 on 14-Jan-2011 01:04Similar issue has been discussed here:
Re: Transaction rollback...
Check that out -
Oracle Portal - Associated Procedures With Custom Item
Dear Gurus,
I need to ask a question, when i have a custom Item built using Oracle Portal 10.1.4.2.0. and we have two procedures associated with this item. I need to display this item in some place with the first procedure and in another place with the second prcoedure.
What i want to explain is written as an example
Custom Item Type asscoiated with two different procedures (News Custom Item Type with two different procedures "brief procedure" and "detail procedure").
In one page i need to invoke the first procedure to display the item in Detail view and the second procedure to diplay the item in Brief view.
How can i invoke different procedures associated with this custom item type or how can i apply different procedures on custom item type to gain different views.
Please can help me or if you need a details i can presents more details.
hint:
i know something in Oracle Portal called ("Associated procedures"). and we use "related funbctions" attribute when we need to invoke a procedure to render some Custom Item Type.
But i cannot do that and this question is very important
Best Regards,I've sorted this now - silly me, I'd left a <blank line> attribute in the display properties...
-
Call procedure within procedure
Hai
I have some question
1)
This below procedure create user at run time
============================================
create or replace procedure new_u1( p_name in varchar2,
p_pw in varchar2,
p_def_tblspace in varchar2 default 'users' )
as
begin
execute immediate 'create user ' || P_name || ' identified by ' ||
p_pw || ' default tablespace ' || p_def_tblspace ||
' temporary tablespace temp';
execute immediate 'grant create session to ' || p_name;
end;
This below procedure create tables at run time
==============================================
create or replace procedure M2 (table_name varchar2) as
cursor1 integer;
begin
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse(cursor1, 'DROP TABLE ' || table_name,
dbms_sql.v7);
dbms_sql.close_cursor(cursor1);
end;
I want ,when first procedure calls ,it calls second procedure and create tables in that schema (call procedure within procedure).How to do that?
2)What is diffrenece between row and statement level trigger?how many types of triggers?
3)what is mutating trigger or table?
4)dbms_stats.gather_table_stats package it collects the statistics about the tables .I want statistics to be collected at every day 9am and 7pm how to do that?
Thanks in advance
MohanYou could use an expression like this, to generate the run times:
SQL> create table times (dt date) ;
Table created.
SQL> BEGIN
2 FOR idx IN 1 .. 24
3 LOOP
4 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24));
5 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (1 / (24 * 60)));
6 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (59 / (24 * 60)));
7 END LOOP;
8 END;
9 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT to_char(dt,
2 'dd-mon-yyyy hh:mi:ss AM'),
3 to_char(decode(sign(to_number(to_char(dt,
4 'hh24MI')) - 900),
5 -1,
6 trunc(dt) + (9 / 24),
7 0,
8 trunc(dt) + (9 / 24),
9 decode(sign(to_number(to_char(dt,
10 'hh24MI')) - 1900),
11 -1,
12 trunc(dt) + (19 / 24),
13 0,
14 trunc(dt) + (19 / 24),
15 trunc(dt) + 1 + (9 / 24))),
16 'dd-mon-yyyy hh:mi:ss AM')
17 FROM times
18 ORDER BY dt
19 /
TO_CHAR(DT,'DD-MON-YYYY TO_CHAR(DECODE(SIGN(TO_
01-jan-2004 01:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 09:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 12:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:59:00 PM 02-jan-2004 09:00:00 AM
02-jan-2004 12:00:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:01:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:59:00 AM 02-jan-2004 09:00:00 AM
72 rows selected.
SQL> -
Call procedure's package from sql query ?
Hi,
I've write a package. In this package there is a procedure A with this parameters (in x, in y, out z).
In the second procedure B, i want te create a cursor like this :
'select * from table where table.fiels in ( A.(x,y) )'
Is it possible to do this ?
Thanks for the answer.I think so. Could you flesh out your code a little more? Yes of course, this is my PLSQL code :
/*This is the first procedure */
procedure Get_IDGeneriques(i_idfamille in generiquesliensfamilles.idfamille%type, i_idprofil in generiqueslienslistesmono.idlisteprofil%type, i_idconstitution in generiqueslienslistesmono.idlisteconstitution%type, i_idserie in generiqueslienslistesmono.idlisteseriefraises%type, i_idpas in generiqueslienslistesmono.idlistepasfraises%type, i_idtypeattache in generiqueslienslistesmono.idlisteattache%type, i_idlisteSensISO in generiqueslienslistesmono.idlisteSensISO%type, i_idlistearrosagecentre in generiqueslienslistesmono.idlisteArrosageCentre%type, i_listematieres in varchar2, i_listemachines in varchar2,i_listeopes in varchar2, o_idgenerique out tbl_bin_int)
is
BEGIN
DECLARE
TYPE TypeCursorReq IS REF CURSOR;
test TypeCursorReq;
sqlstm VARCHAR2(4000);
recordcount number default 0;
idgenerique generiqueslienslistesmono.idref%type;
BEGIN
sqlstm := 'SELECT GENERIQUESLIENSLISTESMULTI.IDGENERIQUE FROM GENERIQUESLIENSLISTESMULTI, GENERIQUESLIENSLISTESMULTI GENERIQUESLIENSLISTESMULTI1, GENERIQUESLIENSLISTESMULTI GENERIQUESLIENSLISTESMULTI2
WHERE GENERIQUESLIENSLISTESMULTI.IDGENERIQUE = GENERIQUESLIENSLISTESMULTI1.IDGENERIQUE AND GENERIQUESLIENSLISTESMULTI.IDGENERIQUE = GENERIQUESLIENSLISTESMULTI2.IDGENERIQUE AND (GENERIQUESLIENSLISTESMULTI.TYPE1 =''MT'')
AND GENERIQUESLIENSLISTESMULTI.IDLISTE IN (' || i_listematieres || ') AND (GENERIQUESLIENSLISTESMULTI1.TYPE1 =''OP'') AND GENERIQUESLIENSLISTESMULTI1.IDLISTE IN (' || i_listeopes || ') AND GENERIQUESLIENSLISTESMULTI2.TYPE1 =''MA''
AND GENERIQUESLIENSLISTESMULTI2.IDLISTE IN (' || i_listemachines || ')';
OPEN test for sqlstm;
LOOP
FETCH test INTO idgenerique;
EXIT WHEN test%NOTFOUND;
recordcount := recordcount+1;
o_idgenerique(recordcount) := idgenerique;
END LOOP;
END;
end;
/* This is the second procedure who call the first one */
procedure Get_IDOutils(i_idfamille in generiquesliensfamilles.idfamille%type, i_idprofil in generiqueslienslistesmono.idlisteprofil%type, i_idconstitution in generiqueslienslistesmono.idlisteconstitution%type, i_idserie in generiqueslienslistesmono.idlisteseriefraises%type, i_idpas in generiqueslienslistesmono.idlistepasfraises%type, i_idtypeattache in generiqueslienslistesmono.idlisteattache%type, i_idlisteSensISO in generiqueslienslistesmono.idlisteSensISO%type, i_idlistearrosagecentre in generiqueslienslistesmono.idlisteArrosageCentre%type, i_listematieres in varchar2, i_listemachines in varchar2,i_listeopes in varchar2, o_idoutil out tbl_bin_int)
is
BEGIN
DECLARE
TYPE TypeCursorReq IS REF CURSOR;
test TypeCursorReq;
sqlstm VARCHAR2(4000);
recordcount number default 0;
idoutil outilslienslistesmono.idref%type;
BEGIN
sqlstm := 'SELECT * FROM OUTILSLIENSLISTESMONO,LIENSGENERIQUESOUTILS
WHERE OUTILSLIENSLISTESMONO.IDRef = LIENSGENERIQUESOUTILS.IDRefOutilFabMati
AND LIENSGENERIQUESOUTILS.IDRefGeneFabMati in (Get_IDGeneriques(1,232,22,47,26,210,206,50,''10444,10448,10451'',''10337'',''10319'') )';
OPEN test for sqlstm;
LOOP
FETCH test INTO idoutil;
EXIT WHEN test%NOTFOUND;
recordcount := recordcount+1;
o_idoutil(recordcount) := idoutil;
END LOOP;
END;
end;
END TITAN2; -
Creating multiple procedures in one go
When I try to create multiple procedures in one go
All of the procedures are stored in the first procedure
When I run the following script:
create or replace
PROCEDURE CREATE_ITEM
(ITEM_id items.item_id %type,
ITEM_DESC items.item_description %TYPE,
ITEM_COST items.item_cost %TYPE,
ITEM_QUAN items.item_quantity %TYPE)
AS
BEGIN
if (ITEM_QUAN >=0)
THEN
insert into items values
(upper(item_id) || LPAD(seq_item_id.nextval, 4, '0'), upper(ITEM_DESC), ITEM_COST, ITEM_QUAN);
DBMS_OUTPUT.PUT_LINE (ITEM_DESC || ' was recorded');
else
DBMS_OUTPUT.PUT_LINE ('Quantity should be 0 or more!!');
end if;
END CREATE_ITEM;
CREATE OR REPLACE PROCEDURE CREATE_ORDER
(customer_id customer.customer_id %TYPE)
AS
BEGIN
insert into orders values
(seq_order_id.nextval, 0, customer_id, sysdate, 1);
END CREATE_ORDER;
It creates "CREATE_ITEM" procedure and store all the script in it..
Is there a solution for this problem?
regardsHi
Place a forward slash
between the two procedures on its own line.
SQL*Plus requires it as well.
Regards,
Dermot.
SQL Developer Team -
Open Cursor using other function/procedure
Hi
I have a procedure that return a cursor to Java, but if it send a parameter or other I wanted to call a procedure or function and return cursor to java , Is possible it ?
Example
PROCEDURE XYZ ( P_ORD IN NUMBER,
p_CURSOR OUT SYS_REFCURSOR)
IS
BEGIN
IF P_ORD =1 THEN
-- here I want to open cursor from other procedure/function
OPEN P_CURSOR
ELSIF P_ORD = 2 THEN
END IF;
END XYZ;Message was edited by:
muttleychessLooking at your example code, you say you want to open a cursor from another procedure.
I would suggest taking a step back and looking into the basics of procedural programming, especially in the area of variable scopes.
The scope of the cursor declared in another procedure will be that it exists within that procedure only.
In order to use another procedure's cursor you would have to call that procedure and have it return a SYS_REFCURSOR to your first procedure in the same manner you are trying to return a sys_refcursor to your Java code. -
Hello,
I wrote two procedues in PL/SQL. I use Oracle XE and Windows XP.
DECLARE
l_bfile BFILE;
l_blob BLOB;
BEGIN
INSERT INTO test_blob (id,file_name,image,timestamp)
VALUES (3,'descrbr',empty_blob(),sysdate)
RETURN image INTO l_blob;
l_bfile := BFILENAME('test', 'file.jpg');
DBMS_LOB.fileopen(l_bfile, Dbms_Lob.File_Readonly);
DBMS_LOB.loadfromfile(l_blob, l_bfile, DBMS_LOB.getlength(l_bfile));
DBMS_LOB.fileclose(l_bfile);
COMMIT;
END;
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
SELECT image
INTO l_blob
FROM test_blob
WHERE id = 3;
l_blob_len := DBMS_LOB.getlength(l_blob);
l_file := UTL_FILE.fopen('test','MyImage.jpg','w', 32767);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
UTL_FILE.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
RAISE;
END;
First procedure is to write file to blob, second is to read blob to file.
I tested on many pictures, but I got distorted pictures.
For example:
This is oryginal picture:
http://img51.imageshack.us/img51/9999/dogvx.jpg
but after:
http://img41.imageshack.us/img41/3410/dog2wy.jpg
another example
oryginal:
http://img43.imageshack.us/img43/4539/catwh.png
after:
http://img688.imageshack.us/img688/1382/cat2q.png
What is wrong with these two procedures? I should get the same pictures... :(For your first procedure you can look at my demo here:
http://www.morganslibrary.org/reference/dbms_lob.html
of READFROMFILE.
But I doubt that is the source of your issue. I really don't like your second anonymous block because it hides failures.
Consider the following code:
EXCEPTION
WHEN OTHERS THEN
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
RAISE;
END;
/If there is an exception raise it closes the file.
If the file is closed successfully there is no exception to raise.
Try again without the exception handler or recode to capture failure information into variables, then close the file, then use RAISE_APPLICATION_ERROR to display the captured information.
Just occurred to me what is wrong though. You need to open the file you are writing to in BYTE mode not CHARACTER mode. Like this:
l_output := utl_file.fopen('ORALOAD', pfname, 'WB', 32760);http://www.morganslibrary.org/reference/utl_file.html
Maybe you are looking for
-
Folders on the root level of boot drive
Hello. I'm wondering if anyone can tell me if there are long-term or detrimental consequences to keeping a folder called "C/" located on the root directory of my boot drive in Snow Leopard. An explanation: I work at a television station, and one of o
-
Can't recall the Airport Express password
I've not been using my base station since Verizon came and installed FIOS and said I shouldn't use the base station in conjunction with their modem/router. I am aware this is not true and will get to that later. Tonight I want to listen to iTunes ove
-
GRC Process Control Workflow error
Dear all, After creation of Self-Assessment Test Plan, or any other plan, it gets "error" status. At transaction SWI1 the task has status "completed" but the task wasn´t performed by any agent. So the task doesn´t appear on user's inbox. Does anyone
-
Software Updates: Microsoft Office, Quicken, Macromedia Flash Player fail
Over the past three months or so I have been prompted to install updates of Microsoft office, Quiken for Mac and now yesterday Adobe Flash Player. In each instance I have been unsuccessful in installation due to the fact that the installation reaches
-
Joining 2 Wireless Networks Wirelessly: AExtreme & Other
I have a need to join two wireless (N grade) networks and have not had much success after many hours. Am hoping someone may know a way forward. Network 1: Telephone Cable ---> ADSL Modem ----> Airport Extreme N Gigabyte The AE is setup to Create a Wi