Plsql cursor help
i was writing a plsql block using cursors.
the main theme is that is have a table circle(radius, area) and i just wanted to get the sum of the areas in the table "in the traditional way using a while loop but i get errors like"
declare
sum number(6,2) :=0;
area circle.area%type;
cursor selector is select area from circle;
begin
open selector;
if selector%isopen then
while selector%found
loop
fetch selector into area;
sum := sum+area;
end loop;
dbms_output.put_line(area);
close selector;
else
dbms_output.put_line('error opening cursor');
end if;
end;
the errors that come up are
that sum :=sum+area .. error at '+' expecting (
and several others .. can anyone help me
i know i can use the sum aggregate function to get the sum.. but i am practicing plsql...
Hmm. I disagree in part, in that it's useful to know that these methods exist and how they work. I agree that you need to know where and when is best to use (and conversely, not use!) them.
I've learnt about While loops, for example, and could code one if I had to, but I think I've used it at most once, if at all. Still, I know that it's there should I need it.
Perhaps the OP could have used a better example to practise on, but I think they'll learn from it none-the-less; if only that it's not a commonly used technique, and that SQL would be much better suited to the task! *{;-)
Similar Messages
-
Cursor help and Max and min help
hello I have a couple of simple questions on cursors. I am gathering data from an oscilloscope to determine amplitude. I would like to set a cursor for a reference point. however, when I set the cursor to the specific number BEFORE the sweep takes place, the cursor gets erased and I have to reset it after. Also, my x-axis goes from 0-240. is their anyway to get a high precision? When I input (154) for the position, it rounds up to 160 and its essential for me to keep as much precision as possible. I attaching some pictures.
Another problem I am having is I want to gather the position where the max point is. I need this position to subtract it from a reference point so I can determine how far I am from the desired reference point. I am currently using the express VI statistics.
Attachments:
Max and Min.JPG 162 KB
Cursor Help.JPG 82 KBAt the risk of sounding like a grumpy old man.
Post you code please- You have a lot of issues with your coding style and it might take a bit of work to help you out. I'm not sure from your pictures where your question is pointing.
Also please post .png files they are prefered on this forum. And what LabVIEW version are you using?
Jeff -
Hi All,
I need to insert values into a table A of similar structure of other table B.(both havin same no of colums and same type).
Im using a cursor to fetch the values from the table B and in loop im fetching the values from the cursor to the temporary variable of the same type as the table B and im trying to insert values into table A using the following statement
insert into table A values(temp variable);
when i tried executing the procedure it is showing an error "Not enough values".
I not clear whether we can use the insert statement as above or is there any other way to achieve the same.
Please help.
Regards,
MohanYou can use an INSERCT..SELECT instead of a PL/SQL procedure:
Insert into TableA(col1, col2, col3)
select column1, column2,column3
from tableB;But if you do need (want) use PL/SQL write it this way:
declare
cursor cb is
select select column1, column2,column3
from tableB;
begin
for recB in cb loop
Insert into TableA(col1, col2, col3)
values (recB.column1,recB.column2,recB.column3);
end loop;
end;Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/10/crittografia-in-plsql-utilizzando-dbms_crypto/] -
Database table has two columns category and products.
Table: catalog
category products
fruit apple
vegetable carrot
soda pepsi
vegetable potato
fruit grapes
fruit orange
vegetable cabbage
soda coke
i need to read the records from table catalog and store them in some sort of plsql collection. I then have to read from that collection and write output as follows:
Note: the categories and products should be sorted alphabetically in output.
OUTPUT
fruit apple, grapes, orange
soda coke, pepsi
vegetable cabbage, carrot, potato
please help me as how this can be done?
Thanks
GWithout collections:
SQL> DECLARE
2 CURSOR c
3 IS
4 WITH t AS (
5 SELECT 'fruit' category,'apple' product FROM dual UNION ALL
6 SELECT 'vegetable','carrot' FROM dual UNION ALL
7 SELECT 'soda','pepsi' FROM dual UNION ALL
8 SELECT 'vegetable','potato' FROM dual UNION ALL
9 SELECT 'fruit','grapes' FROM dual UNION ALL
10 SELECT 'fruit','orange' FROM dual UNION ALL
11 SELECT 'vegetable','cabbage' FROM dual UNION ALL
12 SELECT 'soda','coke' FROM dual
13 )
14 SELECT category,
15 ltrim(sys_connect_by_path(product,', '),', ') product_list
16 FROM (
17 SELECT category,
18 product,
19 row_number() over(partition by category order by product) rn
20 FROM t
21 )
22 WHERE connect_by_isleaf = 1
23 START WITH rn = 1
24 CONNECT BY category = PRIOR category
25 AND rn = PRIOR rn + 1
26 ORDER BY category;
27 BEGIN
28 FOR v_rec IN c LOOP
29 DBMS_OUTPUT.PUT_LINE(rpad(v_rec.category,10) || v_rec.product_list);
30 END LOOP;
31 END;
32 /
fruit apple, grapes, orange
soda coke, pepsi
vegetable cabbage, carrot, potato
PL/SQL procedure successfully completed.
SQL> And in plain SQL:
SQL> COLUMN PRODUCT_LIST FORMAT A50
SQL> WITH t AS (
2 SELECT 'fruit' category,'apple' product FROM dual UNION ALL
3 SELECT 'vegetable','carrot' FROM dual UNION ALL
4 SELECT 'soda','pepsi' FROM dual UNION ALL
5 SELECT 'vegetable','potato' FROM dual UNION ALL
6 SELECT 'fruit','grapes' FROM dual UNION ALL
7 SELECT 'fruit','orange' FROM dual UNION ALL
8 SELECT 'vegetable','cabbage' FROM dual UNION ALL
9 SELECT 'soda','coke' FROM dual
10 )
11 SELECT category,
12 ltrim(sys_connect_by_path(product,', '),', ') product_list
13 FROM (
14 SELECT category,
15 product,
16 row_number() over(partition by category order by product) rn
17 FROM t
18 )
19 WHERE connect_by_isleaf = 1
20 START WITH rn = 1
21 CONNECT BY category = PRIOR category
22 AND rn = PRIOR rn + 1
23 ORDER BY category
24 /
CATEGORY PRODUCT_LIST
fruit apple, grapes, orange
soda coke, pepsi
vegetable cabbage, carrot, potato
SQL> SY. -
Urgent - How to call a Web Services from PLSQL - Please help
Hello,
I am very much new to WebServices, need to call web services through PLSQL. I have a urgent requirement, where i need to call the web services by passing from some paramters to it and the web services will return a varchar values as 'PASSED' or 'FAILED'.
Can you please approch me the best way to start with.
Thanks,
Srikanth.Hi,
I need to do it from PLSQL API's not from JAVA.
I have started developing the code through UTIL_HTTP. Getting lots of error.
Can you please guide me through these error.
Below is the wsdl and a blcok where i am trying to retrive the value from webservice.
Hope this will help you.
Code:
declare
soap_request varchar2(30000);
soap_respond varchar2(30000);
http_req utl_http.req;
http_resp utl_http.resp;
resp XMLType;
i integer;
begin
soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:soapCheckRequest1 wsdl:ns1="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<FirstName xsi:type="xsd:string">saddam</FirstName>
<LastName xsi:type="xsd:string">hussein</LastName>
<companyName xsi:type="xsd:string">samueladams</companyName>
<address1 xsi:type="xsd:string">123 APT</address1>
<address3 xsi:type="xsd:string">Atlanta</address3>
<city xsi:type="xsd:string">uk</city>
<stateOrRegion xsi:type="xsd:string">GA</stateOrRegion>
<postalCode xsi:type="xsd:string">30338</postalCode>
<email xsi:type="xsd:string">sj@samueladams</email>
<isoCountryCode xsi:type="xsd:string">US</isoCountryCode>
<endUserIP xsi:type="xsd:string">209.134.168.203</endUserIP>
</ns1:soapCheckRequest1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
http_req:= utl_http.begin_request
( 'http://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService'
, 'POST'
, 'HTTP/1.1'
utl_http.set_header(http_req, 'Content-Type', 'text/xml'); -- since we are dealing with plain text in XML documents
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
utl_http.set_header(http_req, 'SOAPAction', ''); -- required to specify this is a SOAP communication
utl_http.write_text(http_req, soap_request);
http_resp:= utl_http.get_response(http_req);
DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response---------------------');
DBMS_OUTPUT.PUT_LINE('http_resp.status_code is :'||http_resp.status_code );
DBMS_OUTPUT.PUT_LINE('http_resp.reason_phrase is :'||http_resp.reason_phrase);
DBMS_OUTPUT.PUT_LINE('http_resp.http_version is :'||http_resp.http_version);
DBMS_OUTPUT.PUT_LINE('http_resp.private_hndl is :'||http_resp.private_hndl);
DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response----------------------');
utl_http.read_text(http_resp, soap_respond);
utl_http.end_response(http_resp);
resp:= XMLType.createXML(soap_respond);
resp:= resp.extract('/soap:Envelop/soap:Body/child::node()'
, 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'
i:=0;
loop
dbms_output.put_line(substr(soap_respond,1+ i*255,250));
i:= i+1;
if i*250> length(soap_respond)
then
exit;
end if;
end loop;
end;
Error Message
http_resp.reason_phrase is :Internal Server Error
http_resp.http_version is :HTTP/1.1
http_resp.private_hndl is :0
-------utl_http.get_response----------------------
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultco
apenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXParseException: The prefix "ns1" for element "ns1:soapCheckRequest1" is not bound.</faultstring><detail><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">atlcms
2.iss.net</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:intf="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <!--
WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
-->
- <wsdl:message name="soapCheckResponse1">
<wsdl:part name="soapCheckReturn" type="soapenc:string" />
</wsdl:message>
- <wsdl:message name="soapCheckRequest1">
<wsdl:part name="firstName" type="soapenc:string" />
<wsdl:part name="lastName" type="soapenc:string" />
<wsdl:part name="companyName" type="soapenc:string" />
<wsdl:part name="address1" type="soapenc:string" />
<wsdl:part name="address2" type="soapenc:string" />
<wsdl:part name="address3" type="soapenc:string" />
<wsdl:part name="city" type="soapenc:string" />
<wsdl:part name="stateOrRegion" type="soapenc:string" />
<wsdl:part name="postalCode" type="soapenc:string" />
<wsdl:part name="email" type="soapenc:string" />
<wsdl:part name="phone" type="soapenc:string" />
<wsdl:part name="isoCountryCode" type="soapenc:string" />
<wsdl:part name="endUserId" type="soapenc:string" />
<wsdl:part name="endUserIP" type="soapenc:string" />
<wsdl:part name="endUserSession" type="soapenc:string" />
<wsdl:part name="performGovCheck" type="xsd:boolean" />
<wsdl:part name="sendEmailNotification" type="xsd:boolean" />
<wsdl:part name="screeningLevelBasedOnSuppliedCountryCode" type="xsd:boolean" />
<wsdl:part name="screeningLevelBasedOnEndUserIP" type="xsd:boolean" />
<wsdl:part name="soundexMatch" type="xsd:boolean" />
</wsdl:message>
- <wsdl:message name="soapCheckRequest">
<wsdl:part name="firstName" type="soapenc:string" />
<wsdl:part name="lastName" type="soapenc:string" />
<wsdl:part name="companyName" type="soapenc:string" />
<wsdl:part name="address1" type="soapenc:string" />
<wsdl:part name="address2" type="soapenc:string" />
<wsdl:part name="address3" type="soapenc:string" />
<wsdl:part name="city" type="soapenc:string" />
<wsdl:part name="stateOrRegion" type="soapenc:string" />
<wsdl:part name="postalCode" type="soapenc:string" />
<wsdl:part name="email" type="soapenc:string" />
<wsdl:part name="phone" type="soapenc:string" />
<wsdl:part name="isoCountryCode" type="soapenc:string" />
<wsdl:part name="endUserId" type="soapenc:string" />
<wsdl:part name="endUserIP" type="soapenc:string" />
<wsdl:part name="endUserSession" type="soapenc:string" />
<wsdl:part name="performGovCheck" type="xsd:boolean" />
<wsdl:part name="sendEmailNotification" type="xsd:boolean" />
<wsdl:part name="screeningLevelBasedOnEndUserIP" type="xsd:boolean" />
<wsdl:part name="soundexMatch" type="xsd:boolean" />
</wsdl:message>
- <wsdl:message name="soapCheckResponse">
Thanks and Regard,
Srikanth -
hi,
i have error at the cursor at the end and can u tell me is the pacakage correct which i have written can any one change as per the syntax and to get the correct out put
create or replace
PACKAGE BODY SF_CSD_CreateOrder
AS
G_PKG_NAME CONSTANT VARCHAR2(30) :='SF_CSD_CreateOrder';
PROCEDURE Create_Order
p_api_version_number IN NUMBER,
p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
p_commit IN VARCHAR2 := FND_API.G_FALSE,
x_return_status OUT NOCOPY VARCHAR2,
x_msg_count OUT NOCOPY NUMBER,
x_msg_data OUT NOCOPY VARCHAR2,
p_order_rec IN ORDER_HDR_REC,
p_order_lines IN ORDER_LINE_REC_TBL )
IS
l_api_name CONSTANT VARCHAR2(30) := 'Create_Order';
l_api_version_number CONSTANT NUMBER := 1.0;
lx_incident_id NUMBER(10);
lx_incident_number VARCHAR2(50);
lx_return_status VARCHAR2(1);
lx_msg_count NUMBER(10);
lx_msg_data VARCHAR2(2000);
l_incident_id NUMBER;
l_repair_line_id NUMBER;
l_repair_number NUMBER;
x_ro_status VARCHAR2;
xl_return_status VARCHAR2(1);
xl_msg_count NUMBER;
xl_msg_data VARCHAR2(2000);
l_order_line_id NUMBER;
l_order_header_id NUMBER;
xx_return_status VARCHAR2(1);
xx_msg_count NUMBER;
xx_msg_data VARCHAR2(2000);
BEGIN
-- Standard Start of API savepoint
SAVEPOINT Create_Order;
-- Standard call to check for call compatibility.
IF NOT FND_API.Compatible_API_Call(l_api_version_number, p_api_version_number, l_api_name, G_PKG_NAME) THEN
RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
END IF;
-- Initialize message list if p_init_msg_list is set to TRUE.
IF FND_API.to_Boolean(p_init_msg_list) THEN
FND_MSG_PUB.initialize;
END IF;
-- Initialize API return status to success
x_return_status := FND_API.G_RET_STS_SUCCESS;
-- call SF_CSD_CREATEORDER_UTIL.Create_SR
-- this outputs incident_id (l_incident_id)
l_createsr_rec :=SF_CSD_CREATEORDER_UTIL.CREATESR_REC;
l_sr_notes_tbl :=cs_servicerequest_pub.notes_table;
l_createsr_rec.party_id :=p_order_rec.party_id;
l_createsr_rec.cust_account_id :=p_order_rec.cust_account_id;
SF_CSD_CREATEORDER_UTIL.create_sr (
P_createsr_rec =>l_createsr_rec,
P_sr_notes_tbl =>l_sr_notes_tbl,
X_incident_id =>lx_incident_id,
X_incident_number =>lx_incident_number,
X_return_status =>lx_return_status,
X_msg_count =>lx_msg_count,
X_msg_data =>lx_msg_data
l_incident_id :=lx_incident_id;
l_order_lines :=SF_CSD_CreateOrder.ORDER_LINE_REC_TBL;
FOR I IN l_order_line
LOOP
--- Use the incidentid returned by the above call (l_incident_id)
-- Create RO
l_createro_rec :=SF_CSD_CREATEORDER_UTIL.CREATERO_REC;
l_createro_rec.INVENTORY_ITEM_ID :=p_order_lines.inventory_item_id;
l_createro_rec.SERIAL_NUMBER :=p_order_lines.serial_number;
l_createro_rec.PROBLEM_DESCRIPTION :=p_order_lines.PROBLEM_DESCRIPTION;
SF_CSD_CREATEORDER_UTIL.create_ro (
p_CREATERO_REC =>l_createro_rec,
x_repair_line_id =>l_repair_line_id,
x_repair_number =>l_repair_number,
x_ro_status => x_ro_status,
x_return_status => xl_return_status,
x_msg_count => xl_msg_count,
x_msg_data =>xl_msg_data
-- Call SF_CSD_CREATEORDER_UTIL.Create_repair_order
--- This outputs repair line id.(l_repair_line_id)
l_repair_line_id :=lx_repair_line_id;
l_auto_rcv :=SF_CSD_CREATEORDER_UTIL.AUTORCV_REC;
CURSOR c_get_rma(p_repair_line_id) IS
SELECT cpt.order_line_id,
cpt.ORDER_HEADER_ID
FROM csd_product_transactions cpt,
csd_repairs cr
WHERE cpt.repair_line_id=p_repair_line_id
AND cr.repair_line_id= cpt.repair_line_id
AND cpt.action_type='RMA';
l_order_line_id :=null;
l_order_header_id :=null;
OPEN c_get_rma(l_auto_rcv.REPAIR_LINE_ID);
FETCH c_get_rma INTO l_order_line_id, l_order_header_id;
CLOSE c_get_rma;
l_auto_rcv.REPAIR_LINE_ID :=l_repair_line_id;
l_auto_rcv.ORDER_LINE_ID := l_order_line_id;
l_auto_rcv.ORDER_HEADER_ID := l_order_header_id;
SF_CSD_CREATEORDER_UTIL.auto_receive (
p_autorcv_tbl => l_auto_rcv,
x_return_status => xx_return_status,
x_msg_count => xx_msg_count,
x_msg_data => xx_msg_data );
-- Get the order line id for the RMA created above. use query to select from csd_product_txns table.
-- Select order_line_id from csd_product_txns where repair_line_Id = l_repair_line_id and action_type = 'RMA'
--- Call SF_CSD_CREATEORDER_UTIL.Auto_receive to receive the item for the rma created above
END LOOP;
END;
END SF_CSD_CreateOrder;hi this is the latest code plzzz help me i am new to PL/SQL
create or replace
PACKAGE BODY SF_CSD_CreateOrder
AS
G_PKG_NAME CONSTANT VARCHAR2(30) :='SF_CSD_CreateOrder';
PROCEDURE Create_Order
p_api_version IN NUMBER,
p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
p_commit IN VARCHAR2 := FND_API.G_FALSE,
x_return_status OUT NOCOPY VARCHAR2,
x_msg_count OUT NOCOPY NUMBER,
x_msg_data OUT NOCOPY VARCHAR2,
p_order_rec IN ORDER_HDR_REC,
p_order_lines IN ORDER_LINE_REC_TBL)
IS
l_api_name CONSTANT VARCHAR2(30) := 'Create_Order';
l_api_version_number CONSTANT NUMBER := 1.0;
/*lx_incident_id NUMBER(10);
lx_incident_number VARCHAR2(50);
lx_return_status VARCHAR2(1);
lx_msg_count NUMBER(10);
lx_msg_data VARCHAR2(2000);
l_incident_id NUMBER;
l_repair_line_id NUMBER;
l_repair_number NUMBER;
xx_ro_status VARCHAR2(1);
xl_return_status VARCHAR2(1);
xl_msg_count NUMBER;
xl_msg_data VARCHAR2(2000);
xx_return_status VARCHAR2(1);
xx_msg_count NUMBER;
xx_msg_data VARCHAR2(2000);*/
l_order_line_id NUMBER;
l_order_header_id NUMBER;
l_incident_id NUMBER;
l_order_line ORDER_LINE_REC_TBL;
l_createsr_rec SF_CSD_CREATEORDER_UTIL.CREATESR_REC;
l_sr_notes_tbl cs_servicerequest_pub.notes_table;
l_order_lines SF_CSD_CreateOrder.ORDER_LINE_REC_TBL;
CURSOR c_get_rma(p_repair_line_id NUMBER) IS
SELECT cpt.order_line_id,
cpt.ORDER_HEADER_ID
FROM csd_product_transactions cpt,
csd_repairs cr
WHERE cpt.repair_line_id=p_repair_line_id
AND cr.repair_line_id= cpt.repair_line_id
AND cpt.action_type='RMA';
BEGIN
-- Standard Start of API savepoint
SAVEPOINT Create_Order;
-- Standard call to check for call compatibility.
IF NOT FND_API.Compatible_API_Call(l_api_version_number, p_api_version, l_api_name,G_PKG_NAME) THEN
RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
END IF;
-- Initialize message list if p_init_msg_list is set to TRUE.
IF FND_API.to_Boolean(p_init_msg_list) THEN
FND_MSG_PUB.initialize;
END IF;
-- Initialize API return status to success
x_return_status := FND_API.G_RET_STS_SUCCESS;
-- call SF_CSD_CREATEORDER_UTIL.Create_SR
-- this outputs incident_id (l_incident_id)
l_createsr_rec.party_id :=p_order_rec.party_id;
l_createsr_rec.cust_account_id :=p_order_rec.cust_account_id;
SF_CSD_CREATEORDER_UTIL.create_sr (
p_createsr_rec =>l_createsr_rec,
p_sr_notes_tbl =>l_sr_notes_tbl,
x_incident_id =>X_incident_id,
x_incident_number =>X_incident_number,
x_return_status =>X_return_status,
x_msg_count =>X_msg_count,
x_msg_data =>X_msg_data
l_incident_id :=x_incident_id;
FOR I IN l_order_line
LOOP
--- Use the incidentid returned by the above call (l_incident_id)
-- Create RO
l_createro_rec :=SF_CSD_CREATEORDER_UTIL.CREATERO_REC;
l_createro_rec.INVENTORY_ITEM_ID :=p_order_lines.inventory_item_id;
l_createro_rec.SERIAL_NUMBER :=p_order_lines.serial_number;
l_createro_rec.PROBLEM_DESCRIPTION :=p_order_lines.PROBLEM_DESCRIPTION;
SF_CSD_CREATEORDER_UTIL.create_ro (
p_CREATERO_REC =>l_createro_rec,
x_repair_line_id =>x_repair_line_id,
x_repair_number =>x_repair_number,
x_ro_status => x_ro_status,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data =>x_msg_data
-- Call SF_CSD_CREATEORDER_UTIL.Create_repair_order
--- This outputs repair line id.(l_repair_line_id)
l_repair_line_id :=x_repair_line_id;
l_auto_rcv :=SF_CSD_CREATEORDER_UTIL.AUTORCV_REC;
l_order_line_id :=null;
l_order_header_id :=null;
OPEN c_get_rma(l_auto_rcv.REPAIR_LINE_ID);
FETCH c_get_rma INTO l_order_line_id, l_order_header_id;
CLOSE c_get_rma;
l_auto_rcv.REPAIR_LINE_ID :=l_repair_line_id;
l_auto_rcv.ORDER_LINE_ID := l_order_line_id;
l_auto_rcv.ORDER_HEADER_ID := l_order_header_id;
SF_CSD_CREATEORDER_UTIL.auto_receive (
p_autorcv_tbl => l_auto_rcv,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data );
-- Get the order line id for the RMA created above. use query to select from csd_product_txns table.
-- Select order_line_id from csd_product_txns where repair_line_Id = l_repair_line_id and action_type = 'RMA'
--- Call SF_CSD_CREATEORDER_UTIL.Auto_receive to receive the item for the rma created above
END LOOP;
END;
END SF_CSD_CreateOrder;
Error(72,17): PLS-00201: identifier 'X_INCIDENT_ID' must be declared
Error(79,17): PLS-00201: identifier 'X_INCIDENT_ID' must be declared
Error(80,10): PLS-00456: item 'L_ORDER_LINE' is not a cursor
plzzz can anyone give the code without errors
plz help me its urgent -
Hi everyone,
I am sorry for what all mistakes I have done earlier. As, I am a new member, I didn't learn all the FAQ in OTN. But now, I read all the FAQ's developed by Blueshadow and I need anyone to help me modifying the code for my new business rule. Once again I am sorry to Venkadesh, ACE, Gary, Etbin and Blueshadow for all my mistakes.
Sara DeeCN_DEFAULT_LANGUAGE_ID cad_languages.language_id%type default toe$translate.fn_get_language_id;
GKV_SLI_SITE_CHAMP_URL constant cad_parameters.text_value%type default cad$param.get_parameter_text_value('TUP_SLI_SITE_CHAMP_URL',GCN_DEFAULT_COMPANY_ID);
GKV_SLI_SEARCH_COUNT constant cad_parameters.number_value%type default cad$param.get_parameter_number_value('TUP_SLI_SEARCH_COUNT',GCN_DEFAULT_COMPANY_ID);
GKV_SLI_XML_PATH constant cad_parameters.text_value%type default cad$param.get_parameter_text_value('TUP_SLI_XML_PATH',GCN_DEFAULT_COMPANY_ID);
GKV_SLI_XML_NODE1_NAME constant cad_parameters.text_value%type default cad$param.get_parameter_text_value('TUP_SLI_XML_NODE1_NAME',GCN_DEFAULT_COMPANY_ID);
GKV_SLI_XML_NODE2_NAME constant cad_parameters.text_value%type default cad$param.get_parameter_text_value('TUP_SLI_XML_NODE2_NAME',GCN_DEFAULT_COMPANY_ID);
gv_ip_redirect_url varchar2(1000);
gv_refer_url varchar2(1000);
gv_sli_search_url varchar2(1000);
gv_page_ref_url varchar2(1000);
gv_procedure_name varchar2(100);
gv_item_number varchar2(30);
gv_category_code varchar2(30);
gv_category_page_num varchar2(3);
gv_section varchar2(30);
gv_user varchar2(30);
gv_lang varchar2(30);
gv_gift_code varchar2(30);
gv_fname varchar2(50);
gv_lname varchar2(50);
gv_email varchar2(100);
gv_message varchar2(2000);
gv_face_amount tup_gift_certificates.face_value_amount%type;
gv_error_message varchar2(2000);
gv_def_category varchar2(30) := null;
gv_categ_description varchar2(1000);
gn_company_id number default cad$user_api.get_user_company_id;
gn_language_id number default toe$translate.fn_get_language_id;
gn_script_id number := -1;
gn_retail_price_list_id number := coe$item.get_event_price_list_id;
gn_gift_certificate number;
gn_page_number number;
gn_page_count number;
gn_order_id number;
gn_start_price number;
gn_end_price number;
gi_heading_index binary_integer;
gn_total_items number := 0;
gkn_page_item_max constant number := 14;
gkn_items_per_row constant number := 7;
gb_gifts_found boolean := false;
gb_pk_details_found boolean := false;
gb_show_pdc boolean := false;
gb_show_item_photo boolean := false;
gb_show_item_host boolean := false;
ge_ip_address_restricted exception;
ge_no_parent_item exception;
gcv_registry varchar2(30) default common_global.f_get_cookie_value('registry');
gcv_registry_status varchar2(30) default common_global.f_get_cookie_value('registry_status');
gcv_highlight_class varchar2(50) default common_defaults.f_get_class_name('highlight',gcv_registry_status);
gcv_hyp_color_class varchar2(50) default common_defaults.f_get_class_name('hyp_color',gcv_registry_status);
gcv_headline_class varchar2(50) default common_defaults.f_get_class_name('headline',gcv_registry_status);
gcv_form_class varchar2(50) default common_defaults.f_get_class_name('form',gcv_registry_status);
cursor gcr_item_data ( cfv_item_category_code varchar2,
cpn_script_id number,
cpn_relship_type_id number)
is
select /*+ ordered use_nl( cic, cicm, cmi) */
cicm.sort_order,
cmi.item_number master_item_number,
cmi.small_image_description detail,
cmi.image_filename image_filename,
cmi.long_description long_description,
cmi.short_description short_desc,
cmi.small_image_filename small_image_filename,
cmi.numeric_item_number,
1 relationship_type
from coe_item_categories cic,
coe_item_category_mappings cicm,
coe_master_items cmi
where sysdate between nvl (cmi.start_date, sysdate - 1) and nvl (cmi.end_date, sysdate + 1)
and cmi.inactive_flag = 0
and exists (select 'x'
from coe_item_relationships cir,
coe_event_item_prices eip
where cir.parent_master_item_id = cmi.master_item_id
and cir.child_master_item_id = eip.master_item_id
and cir.company_id = eip.company_id+0
and eip.event_price_list_id+0 = gn_retail_price_list_id
and eip.inactive_flag = 0
and sysdate between eip.start_time_date and nvl(eip.end_time_date, sysdate)
and cir.item_relationship_type_id+0 = cpn_relship_type_id
and cir.inactive_flag = 0
and sysdate between nvl (cir.start_time_date, sysdate - 1) and nvl(cir.end_time_date, sysdate + 1) --TSR 32282
--and cir.company_id+0 = gn_company_id
and cmi.master_item_id = cicm.master_item_id
and nvl(cicm.script_id, cpn_script_id) = cpn_script_id
and (sysdate) between nvl (cicm.start_time_date, sysdate - 1) and nvl (cicm.end_time_date, sysdate + 1)
and cicm.inactive_flag = 0
and cic.item_category_code = cicm.item_category_code
and cic.display_heading_flag = 1
and cic.item_category_code = cfv_item_category_code
union all
select /*+ ordered use_nl( cic, cicm, cmi) */
cicm.sort_order,
cmi.item_number master_item_number,
cmi.small_image_description detail,
cmi.image_filename image_filename,
cmi.long_description long_description,
cmi.short_description short_desc,
cmi.small_image_filename small_image_filename,
cmi.numeric_item_number,
0 relationship_type
from coe_item_categories cic,
coe_item_category_mappings cicm,
coe_master_items cmi
where sysdate between nvl (cmi.start_date, sysdate - 1) and nvl (cmi.end_date, sysdate + 1)
and cmi.inactive_flag = 0
and exists (select 'x'
from coe_event_item_prices eip
where cmi.master_item_id = eip.master_item_id
and eip.event_price_list_id+0 = gn_retail_price_list_id
and eip.inactive_flag = 0
and sysdate between eip.start_time_date and eip.end_time_date
and cmi.master_item_id = cicm.master_item_id
and nvl(cicm.script_id, cpn_script_id) = cpn_script_id
and sysdate between nvl (cicm.start_time_date, sysdate - 1) and nvl (cicm.end_time_date, sysdate + 1)
and cicm.inactive_flag = 0
and cic.item_category_code = cicm.item_category_code
and cic.display_heading_flag = 1
and cic.item_category_code = cfv_item_category_code
order by 1, 2; -
Plsql procedure help..
Hi There,
We're developing a procedure that takes a string, a delimiter, assign the individual tokens to variables, and return the variables to the calling program.
Since I'm new to pl/sql, I'm not quite sure how to do the last bit (assign the tokens to the variables and return them to the calling program), and we we're looking at some help please. In other words, I have a loop, fetch a cursor into variable.. and we're wondering how can we assign the 1st value of the cursor to the 1st defined OUT variable in the procedure heading (the 2nd cursor value to the 2nd OUT variable, ..etc)?
Here is the code:
procedure string_to_tokens (in_str IN varchar2,
delim IN varchar2,
VENDOR_ID OUT number,
CCF_ID OUT number,
PRR_ID OUT number,
CON_NAME OUT VARCHAR2,
CONT_TYPE_ID OUT number,
DEPOSIT_DATE OUT VARCHAR2,
CON_YEAR OUT VARCHAR2,
CHG_NAME OUT VARCHAR2,
CON_AMOUNT OUT number,
TOT_AMOUNT OUT number)
is
mystring varchar2(100);
cursor str_cur is
SELECT
SUBSTR
( in_str
, DECODE(LEVEL, 1, 1, INSTR(in_str, delim, 1, LEVEL-1)+1)
, INSTR(in_str, delim, 1, LEVEL) -
DECODE(LEVEL, 1, 1, INSTR(in_str, delim, 1, LEVEL-1)+1)
FROM DUAL
CONNECT BY INSTR(in_str, delim, 1, LEVEL)>0
ORDER BY LEVEL ASC;
begin
open str_cur;
loop
fetch str_cur into mystring;
exit when str_cur%NOTFOUND;
dbms_output.put_line ('mystring is '||mystring);
end loop;
close str_cur;
end string_to_tokens;a sample input string would be:
'22|||1334502 RegXL Ltd|18|10032011|2011|John Joe|2000.00|2000.00'The delimiter would be '|'.
Thanks in advance for your help.
Thanks
Edited by: rsar001 on Oct 26, 2011 7:39 AM
Edited by: rsar001 on Oct 26, 2011 7:40 AMHi,
You can do something like this:
CREATE OR REPLACE procedure string_to_tokens
( in_str IN varchar2,
delim IN varchar2,
VENDOR_ID OUT number,
CCF_ID OUT number,
PRR_ID OUT number,
CON_NAME OUT VARCHAR2,
CONT_TYPE_ID OUT number,
DEPOSIT_DATE OUT VARCHAR2,
CON_YEAR OUT VARCHAR2,
CHG_NAME OUT VARCHAR2,
CON_AMOUNT OUT number,
TOT_AMOUNT OUT number,
encloser IN VARCHAR2 := '"' -- new argument added
is
mystring VARCHAR2 (32767) := in_str || delim; -- Remining text to process
sub_str VARCHAR2 (32767); -- Nth delimited item
loop_cntr PLS_INTEGER := 0;
delimiter_pos PLS_INTEGER := -1; -- position of 1st delimiter in remaining text
begin
WHILE delimiter_pos != 0
AND loop_cntr <= 10
LOOP
loop_cntr := loop_cntr + 1;
IF SUBSTR (mystring, 1, 1) = encloser -- Changes start here
THEN -- Next token is enclosed; next token ends with encloser
delimiter_pos := INSTR (mystring, encloser, 2);
sub_str := SUBSTR ( mystring
, 2
, delimiter_pos - 2
mystring := SUBSTR ( mystring
, delimiter_pos + 2
ELSE -- Usual situation: next token ends with delim
delimiter_pos := INSTR (mystring, delim);
sub_str := SUBSTR ( mystring
, 1
, delimiter_pos - 1
mystring := SUBSTR ( mystring
, delimiter_pos + 1
END IF;
IF delimiter_pos > 0
THEN
-- Changes end here
IF loop_cntr = 1
THEN
vendor_id := TO_NUMBER (sub_str);
ELSIF loop_cntr = 2
THEN
ccf_id := TO_NUMBER (sub_str);
ELSIF loop_cntr = 3
THEN
prr_id := TO_NUMBER (sub_str);
ELSIF loop_cntr = 4
THEN
con_name := sub_str;
ELSIF loop_cntr = 5
THEN
cont_type_id := TO_NUMBER (sub_str);
ELSIF loop_cntr = 6
THEN
deposit_date := TO_NUMBER (sub_str); -- Should this be a DATE, rather than a NUMBER?
ELSIF loop_cntr = 7
THEN
con_year := sub_str;
ELSIF loop_cntr = 8
THEN
chg_name := sub_str;
ELSIF loop_cntr = 9
THEN
con_amount := TO_NUMBER (sub_str);
ELSIF loop_cntr = 10
THEN
tot_amount := TO_NUMBER (sub_str);
END IF;
END IF;
END LOOP;
end string_to_tokens;
{code}
I added an optional argument after tot_amount, and changed a few lines of code at the beginning of the loop. The rest of the procedure is unchanged. -
Simple PHP and PLSQL Bind help needed
HI,
I am learning php and oracle I am trying to bind my plsql code with php but have little idea can anyone plese help?.
my code is
plsql prcoedure
CREATE OR REPLACE PROCEDURE get_width (
img_id IN arm_photos.id%TYPE
AS
image ORDSYS.ORDImage;
width INTEGER;
BEGIN
SELECT p.image INTO image FROM arm_photos p
WHERE p.id = img_id;
-- Get the image width:
width := image.getWidth();
DBMS_OUTPUT.PUT_LINE('Width is ' || width);
COMMIT;
END;
PHP code
<?php
$c =oci_connect('user', 'pass' , '//localhost/orcl');
$s = oci_parse($c, " begin
get_width(:id :width)");
oci_bind_by_name($s, ':id', $id);
oci_bind_by_name($s, ':width', $width);
$id= 1235;
oci_execute($s);
?>Variable width is a local variable. You can't get its value from outside SP. Either change your procedure to a function returning image width or add a second out parameter:
CREATE OR REPLACE PROCEDURE get_width (
img_id IN arm_photos.id%TYPE,width OUT INTEGER
AS
image ORDSYS.ORDImage;
BEGIN
SELECT p.image INTO image FROM arm_photos p
WHERE p.id = img_id;
-- Get the image width:
width := image.getWidth();
DBMS_OUTPUT.PUT_LINE('Width is ' || width);
COMMIT;
END;SY. -
Hi All,
I have a set of tables Orig_tab1 ... Orig_tab30 and tmp_tab1... tmp_tab30, I have migrating the data to sqlserver from oracle 10g, by creating the tmp_tabs for 30 Orig_tabs
and changing the data type of date,number to char in tmp_tabs tables coz number and date were having issue in migration.
Now I as I have migrated them, need to perform a quality check on data ( esply date and number) by taking max and min of all date columns and sum of number columns
compareing the Orig_tabs tables with tmp_tabs table and finally comparing it with sqlserver results.
SQL server part is ok, i'll take care of it. I need some help in writing sp/function/Anonymous block,
1. what do you suggest for this, would be good to write.
2. Thinking of one cursor for table nested with another cursor for colums, then creating one table which holds all these min max and sum of number values for both Org and tmp tables
I do not have any tools like toad etc, need to work on sqlprompt only, which is taking time for me.
Any Idea or help in this regard would be helpful.
Regards,
aakWhen you post a question it's a good idea to provide:
a) your database version
b) an example of your table structures
c) an example of your data
d) an example of your expected output
e) the logic behind the process you want
f) ensure you enclose code and data inside {noformat}{noformat} tags so that it retains formatting on the forum.
As your post currently stands, I don't think many people will have much idea how to help you. -
Ref cursor help in Reports/pl sql
Hello , i am new to this , please help!
From oracle forms, we have a table and one of the columns from that table returns rows and the result are like ( select name, messaging_id, listing_id from dynamic_message group_query) ..I am trying to join this table with other tables based on a group type, based on if it returns 'D' or 'S' to other groups in report.
I am getting the following error when I uncomment the open cursor statemnt
PLS-00455: cursor 'TEMP_GRP_REC_REFCUR' cannot be used in dynamic
SQL OPEN statement
This is what i have so faar:
create or replace PACKAGE grp IS
TYPE grp_rec IS RECORD
(listing_id varchar2(16 ),
messaging_id varchar2(16 ),
name varchar2(256 ) ,
group_number Number);
TYPE grp_rec_refcur is REF CURSOR RETURN grp_rec;
function grprefc(P_group_number NUMBER, P_group_type CHAR) return grp_rec_refcur;
END;
CREATE OR REPLACE PACKAGE BODY grp IS
function grprefc(p_group_number Number )
return grp_rec_refcur
IS
temp_grp_rec_refcur grp.grp_rec_refcur;
v_stmt_str VARCHAR2(2000) := NULL;
v_cov_name listing.name%TYPE := NULL;
v_cov_mid listing.messaging_id%TYPE := NULL;
v_cov_lid listing.listing_id%TYPE := NULL;
v_grpnum message_group.group_number%TYPE := NULL;
BEGIN
v_stmt_str:='SELECT dmgq.resolved_query
INTO v_stmt_str
FROM dynamic_message_group_query dmgq
WHERE dmgq.group_number = p_group_number';
OPEN temp_grp_rec_refcur FOR v_stmt_str;
LOOP
FETCH temp_grp_rec_refcur INTO v_cov_lid , v_cov_mid ,v_cov_name, v_grpnum ;
EXIT WHEN temp_grp_rec_refcur %NOTFOUND;
END Loop;
RETURN temp_grp_rec_refcur;
END;
END;
show errors;
if there are any examples done by someone in reoprts or if you can help me solve the above, i would higghly appreciate it .
Thanks and Good Day!Maybe something like my second example "Dynamic Table in the Second Query with Oracle Reports"
- ref cursor or "simple" query Q1, which has a column "group_type", linked to a ref cursor query Q2.
Ref cursor query Q2 - pseudo code for function:
CREATE OR REPLACE PACKAGE BODY grp IS
FUNCTION A_join_B_or_A_join_C_join_D
(p_group_type CHAR(1), p_group_number NUMBER)
RETURN dynamic_refcur
IS
l_refcur dynamic_refcur;
l_stmt_str VARCHAR2(2000) := NULL;
BEGIN
IF p_group_type = 'S' THEN
-- join A and B
OPEN l_refcur FOR
SELECT ...
FROM A, B
WHERE A.x = B.y;
ELSE -- p_group_type = 'D'
SELECT resolved_query
INTO l_stmt_str
FROM dynamic_message_group_query
WHERE group_number = p_group_number;
-- join A, C and D (= dynamically created SELECT)
OPEN l_refcur FOR
'SELECT ...
FROM A, C, (' || l_stmt_str || ') D
WHERE A.x = C.y
AND A.z = D.t';
END IF;
RETURN l_refcur;
END;
END; Regards,
Zlatko -
I need somebody to help me with sql cursors, in JSP.
This is my peace of code what is wrong with it?
Statement stmt = myConn.createStatement();
stmt.executeQuery("BEGIN WORK");
stmt.executeQuery("DECLARE item_cursor CURSOR FOR SELECT user_name FROM admin_info");
stmt.executeQuery("FETCH 10 FROM item_cursor");
ResultSet rs = stmt.getResultSet();
while(rs.next()){
if(rs.getString(1) != null){
user_name = rs.getString(1).trim();
%><P><%= user_name %></P><%
stmt.executeQuery("CLOSE item_cursor");
stmt.executeQuery("COMMIT WORK");
and this is the error that a get: No results where returned by the query
Please help anybody
thanx guysIf you are using ORACLE drivers and classes.
This sample program shows Oracle JDBC REF CURSOR functionality, creating a PL/SQL package that includes a stored function that returns a REF CURSOR type. The sample retrieves the REF CURSOR into a result set object.
* This sample shows how to call a PL/SQL function that opens
* a cursor and get the cursor back as a Java ResultSet.
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class RefCursorExample
public static void main (String args [])
throws SQLException
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");
// Create the stored procedure
init (conn);
// Prepare a PL/SQL call
CallableStatement call =
conn.prepareCall ("{ ? = call java_refcursor.job_listing (?)}");
// Find out all the SALES person
call.registerOutParameter (1, OracleTypes.CURSOR);
call.setString (2, "SALESMAN");
call.execute ();
ResultSet rset = (ResultSet)call.getObject (1);
// Dump the cursor
while (rset.next ())
System.out.println (rset.getString ("ENAME"));
// Close all the resources
rset.close();
call.close();
conn.close();
// Utility function to create the stored procedure
static void init (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
stmt.execute ("create or replace package java_refcursor as " +
" type myrctype is ref cursor return EMP%ROWTYPE; " +
" function job_listing (j varchar2) return myrctype; " +
"end java_refcursor;");
stmt.execute ("create or replace package body java_refcursor as " +
" function job_listing (j varchar2) return myrctype is " +
" rc myrctype; " +
" begin " +
" open rc for select * from emp where job = j; " +
" return rc; " +
" end; " +
"end java_refcursor;");
stmt.close(); -
Return cursor help Required-urgent
Hi All
I need to show 2 column list which is a formula calculation
these now i am getting in dbms output
but i need return cursor , please help
ITEM RATIO
asd v_asd
zyx v_zyx
afd v_afd
xcv v_xcv
ITEM RATIO
asd 23.90
zyx 24.6
afd 43.67
xcv 78.67
Regards,Select the variables over dual in Union query under a REF CURSOR.
Like
OPEN RefCursor FOR
SELECT 'asd' col1, v_asd col2 FROM Dual
UNION
SELECT 'zyx', v_zyx FROM Dual
.... -
I am trying to figure out how to get the following code to work.
I am using a cursor to run a SELECT statement with a group function. How do I get the information from the group function to print out with a dbms_output.put_line statement? Just for my knowledge, is there some way to reference the next/previous cursor field as part of the wf_country_spoken_rec variable?
DECLARE
CURSOR wf_country_spoken_cur IS SELECT c.country_name, COUNT(s.language_id)
FROM wf_countries c, wf_spoken_languages s
WHERE c.country_id = s.country_id
GROUP BY country_name
HAVING COUNT(s.language_id) > 6;
wf_rowcount INTEGER;
BEGIN
FOR wf_country_spoken_rec IN wf_country_spoken_cur
LOOP
DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id);
wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
END LOOP;
DBMS_OUTPUT.PUT_LINE(wf_rowcount);
END;
Thanks,
JohnThe only problem I think your code has is how it's referencing the language_id. If it suppose to print out the count of language_ids then you just need to add an alias to it. just like this:
DECLARE
CURSOR wf_country_spoken_cur IS
SELECT c.country_name,
COUNT(s.language_id) language_id_cnt
FROM wf_countries c,
wf_spoken_languages s
WHERE c.country_id = s.country_id
GROUP BY country_name
HAVING COUNT(s.language_id) > 6;
wf_rowcount INTEGER;
BEGIN
FOR wf_country_spoken_rec IN wf_country_spoken_cur
LOOP
DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id_cnt);
wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
END LOOP;
DBMS_OUTPUT.PUT_LINE(wf_rowcount);
END;
/ -
I have this SELECT below which i have to run it in a LOOP for every activity_id(record) that i get from the join.
Also,this SELECT has to be run in multiple places in a procedure to get details and for that records-->I run the assign_course or assign_test as below.
Can anyone please help me write a function which would have this select.inputs are strtplanid,strPersonid,p_objective_id
FOR activity_id( IN
(SELECT objact.activity_id, objact.activity_type,objact.IS_REQUIRED
FROM test_training_plan tp,
test_tp_objective tp_obj,
test_train_obj_activity objact
WHERE tp.tplan_id = tp_obj.tplan_id
AND tp.tplan_id = strtplanid
AND tp_obj.t_objective_id = p_objective_id
AND tp_obj.t_objective_id = objact.t_objective_id
AND objact.activity_id NOT IN (
SELECT tplplr.activity_id
FROM test_learning_record lr,
test_learning_record lr1,
test_tp_learning_activity tplplr
WHERE lr.lr_catalog_history_id = tplplr.activity_id
AND lr.learning_record_id =
tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id = lr1.learning_record_id
AND lr1.lr_catalog_history_id =
strtplanid
AND lr.lr_person_id = strPersonid
AND lr1.lr_person_id = strPersonid
AND lr.status IN
('PASSED', 'WAIVED', 'TESTED_OUT'))
AND objact.activity_id NOT IN (
SELECT event_id
FROM test_train_obj_activity toa,
test_event_sessions sessions,
test_learning_record lr1,
test_tp_learning_activity tplearnact,
test_learning_record tplr
WHERE toa.activity_id = sessions.event_id
AND sessions.event_session_id =
lr1.lr_catalog_history_id
AND lr1.learning_record_id =
tplearnact.activity_lp_lr_id
AND tplearnact.tp_lp_lr_id =
tplr.learning_record_id
AND tplr.lr_catalog_history_id =
strtplanid
--AND toa.is_required = 1
AND toa.t_objective_id = obj.t_objective_id
AND tplr.lr_person_id = strPersonid
AND lr1.lr_person_id = strPersonid
AND lr1.status IN
('PASSED', 'WAIVED', 'TESTED_OUT')))
LOOP
IF (activity.activity_type = 'Course')
THEN
SP_ASSIGN_COURSETP(strPersonid,activity.activity_id,strPersonid,activity.activity_type,
activity.IS_REQUIRED,strtplanid,v_straccreditingorg);
ELSif (activity.activity_type ='Test')
THEN
SP_ASSIGN_TESTTP(strPersonid,activity.activity_id,strPersonid,activity.activity_type,
activity.IS_REQUIRED,strtplanid,v_straccreditingorg);
END IF;Hi all,
I am back again and requesting your help on this.I want your help to properly write the below code because now i feel-that its very confusing and not easily readable.
I want to replace the same looping done in many places using a function.Then,need all your important suggestions in any other ways,approach...i can do the same
which would be very good for performance and best practices.
CREATE OR REPLACE PROCEDURE "TEST_PROCEDURE" (
p_strtplanid test_training_plan.tplan_id%TYPE,
p_strpersonid test_person.person_id%TYPE,
p_strorg_id test_org.org_id%TYPE
IS
/*Here declarartion of variables */
BEGIN
/*Since TP is presently in LR,verify if its completed or not*/
SELECT COUNT (learning_record_id)
INTO v_inttpcompltd
FROM test_learning_record lr
WHERE lr.catalog_item_type = 'training-plan'
AND lr.status IN ('PASSED', 'WAIVED', 'TESTED_OUT')
AND lr.lr_catalog_history_id = p_strtplanid
AND lr.lr_person_id = p_strpersonid
AND lr.lr_org_id = p_strorg_id;
/*Credit based */
SELECT is_credit_based
INTO v_intcreditbased
FROM test_training_plan
WHERE tplan_id = p_strtplanid;
IF (v_inttpcompltd > 0)
THEN
IF (v_intcreditbased = 1)
THEN
DBMS_OUTPUT.put_line ('Starting Credit based ');
v_inttotreqactcompltd :=
fn_tp_get_cmpltd_act_cnt (p_strtplanid,
p_strpersonid,
p_strorg_id
SELECT NVL (EXTRACT (tplan_xml_data, '//numberOfCredits/text()').getstringval
0
NVL (EXTRACT (tplan_xml_data, '//accreditingOrg/text()').getstringval
0
INTO v_intrequiredcredits,
v_straccreditingorg
FROM test_training_plan
WHERE tplan_id = p_strtplanid;
SELECT accred_org_id
INTO v_straccreditingorg
FROM test_tp_acc_org
WHERE tplan_id = p_strtplanid;
IF (v_intrequiredcredits > v_inttotreqactcompltd)
THEN
DBMS_OUTPUT.put_line ('test_tp_acc_org ');
FOR obj IN (SELECT t_objective_id,
NVL (required_credits, 0) required_credits
FROM test_tp_objective
WHERE tplan_id = p_strtplanid)
LOOP
DBMS_OUTPUT.put_line
( ' Looping each Objective******************************'
|| obj.t_objective_id
SELECT NVL (SUM (lcdt.credit_hours), 0)
INTO v_inttotreqacttobecompltd
FROM test_train_obj_activity toa,
test_tp_objective tpobj,
test_learningactivity_credits lcdt,
test_tp_acc_org acc_org
WHERE lcdt.learning_activity_id = toa.activity_id
AND lcdt.acc_org_id = v_straccreditingorg
AND toa.t_objective_id = tpobj.t_objective_id
AND tpobj.tplan_id = acc_org.tplan_id
AND toa.t_objective_id = obj.t_objective_id
AND tpobj.tplan_id = p_strtplanid
AND tpobj.t_objective_id = obj.t_objective_id
AND toa.is_required = 1;
DBMS_OUTPUT.put_line
( 'Total credits for required activities****'
|| v_inttotreqacttobecompltd
--get credits for non event activities
SELECT NVL (SUM (credit_hours), 0)
INTO v_intnoneventbasedactcredit
FROM test_tp_objective tobj,
test_train_obj_activity toa,
test_learningactivity_credits lac,
test_learning_record lr,
test_tp_learning_activity tplplr,
test_learning_record tplr
WHERE tobj.t_objective_id = obj.t_objective_id
AND toa.t_objective_id = tobj.t_objective_id
AND toa.activity_id = lac.learning_activity_id
AND toa.activity_id = lr.lr_catalog_history_id
AND toa.is_required = 1
AND lr.learning_record_id = tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id = tplr.learning_record_id
AND tobj.tplan_id = p_strtplanid
AND tplr.lr_catalog_history_id = p_strtplanid
AND acc_org_id = v_straccreditingorg
AND lr.lr_person_id = p_strpersonid
AND tplr.lr_person_id = p_strpersonid
AND lr.status IN ('PASSED', 'WAIVED', 'TESTED_OUT');
--Get credits for events
SELECT NVL (SUM (credit_hours), 0)
INTO v_inteventbasedactcredit
FROM test_learningactivity_credits lac
WHERE lac.learning_activity_id IN (
SELECT event_id
FROM test_tp_objective tobj,
test_train_obj_activity toa,
test_learning_record lr,
test_event_sessions sessions,
test_tp_learning_activity tplplr,
test_learning_record tplr
WHERE tobj.t_objective_id = obj.t_objective_id
AND tobj.t_objective_id = toa.t_objective_id
AND toa.activity_id = sessions.event_id
AND toa.is_required = 1
AND sessions.event_session_id =
lr.lr_catalog_history_id
AND lr.learning_record_id =
tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id = tplr.learning_record_id
AND tplr.lr_catalog_history_id = p_strtplanid
AND tobj.tplan_id = p_strtplanid
AND tplr.lr_person_id = p_strpersonid
AND lr.lr_person_id = p_strpersonid
AND lr.status IN
('PASSED', 'WAIVED', 'TESTED_OUT'))
AND acc_org_id = v_straccreditingorg;
v_inttotreqactcompltd :=
v_intnoneventbasedactcredit + v_inteventbasedactcredit;
DBMS_OUTPUT.put_line
( ' Total credits of reqd. completed activities'
|| v_inttotreqactcompltd
IF (v_inttotreqacttobecompltd <= v_inttotreqactcompltd)
THEN
DBMS_OUTPUT.put_line
( '****** START INSIDE OBJ-COUNT COMPLETED************** '
|| obj.required_credits
v_strreturnval :=
fn_tp_obj_comp_act_cdt (p_strpersonid,
p_strtplanid,
obj.t_objective_id,
v_intcreditbased
DBMS_OUTPUT.put_line ( 'FN_TP_GET_CMPLTD_ACT_CNT'
|| v_strreturnval
IF (obj.required_credits > v_strreturnval)
THEN
DBMS_OUTPUT.put_line
|| obj.required_credits
*I want to write a function to do the below looping and SELECT functionality and return certain values selected.*
*Most importantly- this query being run in several places throughout the whole main program and everytime I have to put this SQL there and*
*which has increased the code by huge amount.*
**Another thing is-I want to remove the NOT IN below and use a different approach.
/*Start processing of new activity */
FOR activity IN
(SELECT objact.activity_id, objact.activity_type,
objact.is_required
FROM test_training_plan tp,
test_tp_objective tp_obj,
test_train_obj_activity objact
WHERE tp.tplan_id = tp_obj.tplan_id
AND tp.tplan_id = p_strtplanid
AND tp_obj.t_objective_id = obj.t_objective_id
AND tp_obj.t_objective_id = objact.t_objective_id
AND objact.activity_id NOT IN (
SELECT tplplr.activity_id
FROM test_learning_record lr,
test_learning_record lr1,
test_tp_learning_activity tplplr
WHERE lr.lr_catalog_history_id =
tplplr.activity_id
AND lr.learning_record_id =
tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id =
lr1.learning_record_id
AND lr1.lr_catalog_history_id =
p_strtplanid
AND lr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr.status IN
('PASSED', 'WAIVED',
'TESTED_OUT'))
AND objact.activity_id NOT IN (
SELECT event_id
FROM test_train_obj_activity toa,
test_event_sessions sessions,
test_learning_record lr1,
test_tp_learning_activity tplearnact,
test_learning_record tplr
WHERE toa.activity_id = sessions.event_id
AND sessions.event_session_id =
lr1.lr_catalog_history_id
AND lr1.learning_record_id =
tplearnact.activity_lp_lr_id
AND tplearnact.tp_lp_lr_id =
tplr.learning_record_id
AND tplr.lr_catalog_history_id =
p_strtplanid
---AND toa.is_required = 1
AND toa.t_objective_id =
obj.t_objective_id
AND tplr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr1.status IN
('PASSED', 'WAIVED',
'TESTED_OUT')))
LOOP
/*The function should return data so that i can validate them as the below ones*/
IF (activity.activity_type = 'Course')
THEN
sp_test_assign_coursetp (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id,
v_strlpid
ELSIF (activity.activity_type = 'Test')
THEN
sp_assign_testtp (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('Case of Optional Activity');
ELSE
/*Start processing of new activity */
FOR activity IN
(SELECT objact.activity_id, objact.activity_type,
objact.is_required
FROM test_training_plan tp,
test_tp_objective tp_obj,
test_train_obj_activity objact
WHERE tp.tplan_id = tp_obj.tplan_id
AND tp.tplan_id = p_strtplanid
AND tp_obj.t_objective_id = obj.t_objective_id
AND objact.is_required = 1
AND tp_obj.t_objective_id = objact.t_objective_id
AND objact.activity_id NOT IN (
SELECT tplplr.activity_id
FROM test_learning_record lr,
test_learning_record lr1,
test_tp_learning_activity tplplr
WHERE lr.lr_catalog_history_id =
tplplr.activity_id
AND lr.learning_record_id =
tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id =
lr1.learning_record_id
AND lr1.lr_catalog_history_id =
p_strtplanid
AND lr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr.status IN
('PASSED', 'WAIVED',
'TESTED_OUT'))
AND objact.activity_id NOT IN (
SELECT event_id
FROM test_train_obj_activity toa,
test_event_sessions sessions,
test_learning_record lr1,
test_tp_learning_activity tplearnact,
test_learning_record tplr
WHERE toa.activity_id = sessions.event_id
AND sessions.event_session_id =
lr1.lr_catalog_history_id
AND lr1.learning_record_id =
tplearnact.activity_lp_lr_id
AND tplearnact.tp_lp_lr_id =
tplr.learning_record_id
AND tplr.lr_catalog_history_id =
p_strtplanid
AND toa.is_required = 1
AND toa.t_objective_id =
obj.t_objective_id
AND tplr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr1.status IN
('PASSED', 'WAIVED',
'TESTED_OUT'))
LOOP
/*Move the TP only for required ids */
IF (activity.activity_type = 'Course')
THEN
SP_TEST_ASSIGN_COURSETP (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id,
v_strlpid
ELSIF (activity.activity_type = 'Test')
THEN
sp_assign_testtp (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id
END IF;
END LOOP;
END IF;
ELSE
DBMS_OUTPUT.put_line
('*********/*No of required credits is more then completed
******Start processing of new activity */'
/*Start processing of new activity */
FOR activity IN
(SELECT objact.activity_id, objact.activity_type,
objact.is_required
FROM test_training_plan tp,
test_tp_objective tp_obj,
test_train_obj_activity objact
WHERE tp.tplan_id = tp_obj.tplan_id
AND tp.tplan_id = p_strtplanid
AND tp_obj.t_objective_id = obj.t_objective_id
AND objact.is_required = 1
AND objact.t_objective_id = tp_obj.t_objective_id
AND objact.activity_id NOT IN (
SELECT tplplr.activity_id
FROM test_learning_record lr,
test_learning_record lr1,
test_tp_learning_activity tplplr
WHERE lr.lr_catalog_history_id =
tplplr.activity_id
AND lr.learning_record_id =
tplplr.activity_lp_lr_id
AND tplplr.tp_lp_lr_id =
lr1.learning_record_id
AND lr1.lr_catalog_history_id =
p_strtplanid
AND lr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr.status IN
('PASSED', 'WAIVED', 'TESTED_OUT'))
AND objact.activity_id NOT IN (
SELECT event_id
FROM test_train_obj_activity toa,
test_event_sessions sessions,
test_learning_record lr1,
test_tp_learning_activity tplearnact,
test_learning_record tplr
WHERE toa.activity_id = sessions.event_id
AND sessions.event_session_id =
lr1.lr_catalog_history_id
AND lr1.learning_record_id =
tplearnact.activity_lp_lr_id
AND tplearnact.tp_lp_lr_id =
tplr.learning_record_id
AND tplr.lr_catalog_history_id =
p_strtplanid
AND toa.is_required = 1
AND toa.t_objective_id = obj.t_objective_id
AND tplr.lr_person_id = p_strpersonid
AND lr1.lr_person_id = p_strpersonid
AND lr1.status IN
('PASSED', 'WAIVED', 'TESTED_OUT')))
LOOP
/*Move the TP only for required ids */
IF (activity.activity_type = 'Course')
THEN
sp_assign_coursetp (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id,
v_strlpid
ELSIF (activity.activity_type = 'Test')
THEN
sp_assign_testtp (p_strpersonid,
activity.activity_id,
p_strpersonid,
activity.activity_type,
activity.is_required,
p_strtplanid,
v_straccreditingorg,
obj.t_objective_id
END IF;
END LOOP;
END IF;
FOR lr_lp_act IN (SELECT tplplr.activity_id,
tplplr.tp_lp_lr_id
FROM test_tp_objective tp_obj,
test_train_obj_activity toa,
test_learning_record lr,
test_tp_learning_activity tplplr,
test_learning_record tplr
WHERE tplplr.activity_lp_lr_id =
lr.learning_record_id
AND lr.lr_catalog_history_id =
toa.activity_id
AND tplplr.tp_lp_lr_id =
tplr.learning_record_id
AND tp_obj.t_objective_id =
toa.t_objective_id
AND tp_obj.tplan_id = p_strtplanid
AND tplplr.lp_lr_flag = 'LR'
AND tp_obj.t_objective_id =
obj.t_objective_id
AND lr.status IN
('PASSED', 'WAIVED', 'TESTED_OUT')
AND lr.lr_person_id = p_strpersonid
AND tplr.lr_person_id = p_strpersonid)
LOOP
DBMS_OUTPUT.put_line
( 'Get data for the activity to update TPs LP id****'
|| v_strlpid
DBMS_OUTPUT.put_line
( 'Values which I am updating----lr_lp_act.activity_id---'
|| obj.t_objective_id
DBMS_OUTPUT.put_line
( 'Values which I am updating----lr_lp_act.activity_id---'
|| lr_lp_act.activity_id
DBMS_OUTPUT.put_line
( 'Values which I am updating----lr_lp_act.tp_lp_lr_id---'
|| lr_lp_act.tp_lp_lr_id
UPDATE test_tp_learning_activity
SET tp_lp_lr_id = v_strlpid
WHERE activity_id = lr_lp_act.activity_id
AND tp_lp_lr_id = lr_lp_act.tp_lp_lr_id;
UPDATE test_learning_record
SET is_for_training_plan = 'NO'
WHERE learning_record_id IN (
SELECT activity_lp_lr_id
FROM test_tp_learning_activity
WHERE tp_lp_lr_id =
lr_lp_act.tp_lp_lr_id);
END LOOP;
END LOOP;
DELETE FROM test_learning_record_details
WHERE learning_record_id =
(SELECT learning_record_id
FROM test_learning_record
WHERE lr_catalog_history_id = p_strtplanid
AND lr_person_id = p_strpersonid
AND status = 'PASSED');
DBMS_OUTPUT.put_line
('UPDATE
test_learning_record_details'
DELETE FROM test_learning_record
WHERE learning_record_id =
(SELECT learning_record_id
FROM test_learning_record
WHERE lr_catalog_history_id = p_strtplanid
AND lr_person_id = p_strpersonid
AND status = 'PASSED');
END IF;
Maybe you are looking for
-
I have firefox 20.0.1 This iminent thing must have ridden in on some download but it is all over the browser trying to put up spammy stuff in facebook, gmail, pinterest. I t may be partially blocked by some other add-ons like adblock-plu or better pr
-
Personas 2 SP2: field values disappear after entry?
Hi Folks - we made a couple of changes to our Personas 2.0 flavors for IMA1N and IMA2N. The flavors work fine in our development system. After transporting the flavors to our QA system we now see a problem with data entry. When data is entered into c
-
JSP + MySQL + Linux + Tomcat4.1 Chinese display problem
Hello all! I have a problem to use JSP to display Chinese which is read from MySQL database. It works well under Windows XP. But when I move the code to Linux. The Chinese can't be displayed any more. The only way to display Chinese correctly is to r
-
Regarding the radio function.
Anyone know if there is there a way to switch from fm to am? Solved! Go to Solution.
-
Your credit card information cannot be verified at this time.
After a dozen attempts (within a timespan of 24 hours) to purchase a book that I created using iPhoto, I continue to receive the error message, "Your credit card information cannot be verified at this time. Please try again." Of course, I verified my