Line break in pl/sql block
Here's my code, which indeed, may be cumbersome, but works:
declare
v_id NUMBER;
v_iso VARCHAR2(30);
v_title VARCHAR2(60);
v_approval_req VARCHAR2(10);
v_approved VARCHAR2(10);
v_job_desc VARCHAR2(60);
v_user VARCHAR2(30);
v_get_user VARCHAR2(60) := :P101_USERNAME;
v_get_user2 VARCHAR2(60) := :P101_USERNAME;
v_num_docs NUMBER;
v_num_rejected NUMBER;
v_count NUMBER := 0;
BEGIN
CASE v_get_user
WHEN :P101_USERNAME THEN
SELECT COUNT(*) into v_num_docs
FROM doc_info, sh_job_description, sh_employees
WHERE doc_info.owner = sh_job_description.job_desc
and sh_job_description.job_desc_id = sh_employees.job_desc_id
and UPPER(doc_info.approval_req) = 'YES'
and (doc_info.approved is null
or UPPER(doc_info.approved) = 'NO')
and sh_employees.user_name = :P101_USERNAME
and sh_employees.user_name <> 'SH_LOCAL';
if v_num_docs > 0 then
htp.bold('You have '||v_num_docs||' document(s) to approve. Please click on the Approve Documents button below to do so.');
end if;
END CASE;
CASE v_get_USER2
WHEN :P101_USERNAME THEN
SELECT COUNT(*) into v_num_rejected
FROM doc_info, sh_job_description, sh_employees
WHERE doc_info.owner = sh_job_description.job_desc
and sh_job_description.job_desc_id = sh_employees.job_desc_id
and UPPER(doc_info.approval_req) = 'YES'
and UPPER(doc_info.approved) = 'REJECTED'
and sh_employees.user_name = :P101_USERNAME
and sh_employees.user_name <> 'SH_LOCAL';
if v_num_rejected > 0 then
htp.bold('You have '||v_num_rejected ||' rejected document(s) that have had updates made per your request. Please click on the Approve Documents button below to review the changes, then approve if all changes are accepted.');
end if;
END CASE;
exception when others then null;
END;Here's the output:
You have 4 document(s) to approve. Please click on the Approve Documents button below to do so. *\n*You have 1 rejected document(s) that have had updates made per your request. Please click on the Approve Documents button below to review the changes, then approve if all changes are accepted. I have entered a bold /n where I need a line break. Silly, but I've tried many combos of \n and the break with a br and this < and this > (I can't get the real thing to post), concatenating and not, but haven't come up with it.
Off to lunch now, back in an hour.
TIA!!!!!
userRRRYB wrote:
Here's my codeFrom where? APEX version? Region? Process? Example on apex.oracle.com?
Fixed. I split it up into two different items, created a region for each, and placed the regions in position 1.Sounds like a lot of extra work.
I have entered a bold /n where I need a line break. Silly, but I've tried many combos of \n and the break with a br and this < and this > (I can't get the real thing to post), concatenating and not, but haven't come up with it.
How about instead of the \n, trying a chr(10) and possibly adding a chr(13)?
I've tried your exampleand htp.p(chr(13)); and suggestions?The HTML specification instructs user agents to collapse white space characters, so however many spaces, tabs, new lines, or carriage returns you add, using whatever notation, only a single space will actually be displayed.
>
htp.bold('<p>You have '||v_num_docs||' document(s) to approve. Please click on the Approve Documents button below to do so.</p>');
htp.bold('<p>You have '||v_num_rejected ||' rejected document(s) that have had updates made per your request. Please click on the Approve Documents button below to review the changes, then approve if all changes are accepted.</p>');It's also specified that inline elements can't contain block-level elements. <tt>b</tt> (as generated by <tt>htp.bold</tt>) is an inline element, while <tt>p</tt></a> is block-level.
In 2011 don't use any <tt>htf/htp</tt> element methods: the HTML generated by these packages is based on an archaic, unadopted HTML version and produces mark-up that is not valid for the XHTML DOCTYPEs used in APEX 4.0 themes. APEX itself stopped using them years ago.
Not knowing where in the page this information is intended to display, it's always safer to assume there is no open block-level container and provide one (such as <tt>div</tt> or <tt>p</tt>) in the emitted mark-up. Does
htp.p('<p>You have '||v_num_docs||' document(s) to approve. Please click on the Approve Documents button below to do so.</p>');
htp.p('<p>You have '||v_num_rejected ||' rejected document(s) that have had updates made per your request. Please click on the Approve Documents button below to review the changes, then approve if all changes are accepted.</p>');produce the required layout?
exception when others then null;Disaster waiting to happen.
http://tkyte.blogspot.com/2006/08/ouch-that-hurts.html
http://tkyte.blogspot.com/2007/03/dreaded-others-then-null-strikes-again.html
http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html
http://tkyte.blogspot.com/2008/06/when-others-then-null-redux.html
Similar Messages
-
How to line break in an SQL Report
I have a simple SQL report with many columns that make the window very wide and the use has to scroll horizontally quite a lot.
How can I make the line break after some column?
Can someone give me a live example for that?Custom report template then is your answer.. Without seeing your initial report it would be hard to give you the code fully. However, if you open the standard report template for your theme, you could save it as a new template and edit it accordingly. You would find the column you wish to break on and create a new <tr> .. </tr> under the <td> definition..
Thank you,
Tony Miller
Webster, TX -
Unwanted Line Breaks in PL/SQL CODE after 'CREATE OR REPLACE' statements
Does anybody know how to keep SQL Developer from automatically editing PL/SQL code and adding line breaks after 'CREATE OR REPLACE' statements?
It keeps taking:
CREATE OR REPLACE PACKAGE DEVELOPER AUTHID DEFINER
And turns it into:
create or replace
package developer AUTHID DEFINER
This unwanted linebreak causes our autodeployment processes to break.
Thanks,
Michael Dunn
University of Notre Dame
Edited by: user9133268 on Feb 21, 2012 8:00 AMHi Michael,
I believe nothing for this issue has progressed since it was asked here:
2.1 RC Extra Line Breaks
As there may be approval for some planned improvements to the SQL Formatter feature in 3.2, I logged an enhancement request for you:
Bug 13744858 - FORUM: UNWANTED LINE BREAK AFTER CREATE OR REPLACE SYNTAX
Regards,
Gary
SQL Developer Team
Edited by: Gary Graham on Feb 21, 2012 4:19 PM
But if you have control over your auto-deployment process code, it might be quicker to enhance that to deal with CREATE OR REPLACE on the same or the preceding line. Also, note that if you edit the package DDL to put the CREATE OR REPLACE on the same line with the package name in the code editor, then immediately use Export or Save Package Spec and Body to save it to disk, then PACKAGE <name> will appear on the same line as the CREATE OR REPLACE syntax. -
Unexpected line breaks in output of a sql query
Hi,
I have a query which looks like:
set pages 0
set feed off
set newp 0
set lines 350
select LPAD(SUBSTR(COLUMN1,1,23),23),LPAD(SUBSTR(COLUMN2,1,42),42), SUBSTR(TO_CHAR(START_TIME,'HH24:MI:SS'),1,8),SUBSTR(TO_CHAR(END_TIME,'HH24:MI:SS'),1,8)
FROM TABLE1;
When executed using SQL*Plus this query puts a line break after each column and hence I get a record on several rows on the screen.
But the last two columns are printed on the same line. I suspect the LPAD is causing some problem.
I have two databases. It works perfectly on one and not on the other.
Is there a oracle parameter due to which the result is affected?
T&R,
BRKTry this:
set pages 0 feed off newp 0 lines 350 trims on
select LPAD(SUBSTR(COLUMN1,1,23),23)
, LPAD(SUBSTR(COLUMN2,1,42),42)
, TO_CHAR(START_TIME,'HH24:MI:SS')
, TO_CHAR(END_TIME,'HH24:MI:SS')
FROM TABLE1; -
Convert rows to columns and put line break in between using t-sql
Hi,
I have a table with 5 columns..and my source data looks like this..
RecordID ID Display AddressType EmailAddress
1 1 GeneratedBy From
[email protected]
1 1 ReceivedBy To
[email protected]
1 1 ReceivedBy To
[email protected]
2 1
3 1 GeneratedBy From
[email protected]
3 1 GeneratedBy From [email protected]
3 1 ReceivedBy To
[email protected]
I need t-sql to show output as..
RecordID ID FullDisplay
1 1 GeneratedBy From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected] ; To -
[email protected]
2 1 Null
3 1 GeneratedBy From -
[email protected] ; From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected]
Display field will have 3 values - "GeneratedBy" , "ReceivedBy" or Null
AddresType field will have 3 values - "From" , "To" and Null.
In the above example, Those 7 records belongs to ID=1.
Whenever RecordID is same I want to show everything in one line with line breaks in between.
In the above example RecordID=1 has 3 rows, display it as 1 row. But Whenever 'ReceivedBy' is there for same recordID put a line break before "ReceivedBy"
create Statement:
Create Table SampleTest
(RecordID int null, ID int null , Dispplay varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
Thanks!
sqlTry below
drop table SampleTest
GO
Create Table SampleTest
(RecordID int null, ID int null , Display varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
--Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
with CTE1 as
select ROW_NUMBER() over(PARTITION by RecordID ,ID,Display order by EmailAddress)rno,* From SampleTest
), CTE2 as (
select RecordID ,ID,'GeneratedBy '+ STUFF(( SELECT '; From - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'GeneratedBy'
FOR XML PATH('')
), 1, 2, '' ) GeneratedBy,
'ReceivedBy '+ STUFF(( SELECT '; To - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'ReceivedBy'
FOR XML PATH('')
), 1, 2, '' ) ReceivedBy
From CTE1 a
group by RecordID ,ID
select RecordID ,ID,GeneratedBy +CHAR(13)+ ReceivedBy as FullDisplay from CTE2
Thanks
Saravana Kumar C -
Why would white space and line breaks in sql query increase runtime
Using 11.2.0.3.0 on unix sprac server, 8 cpus 32 cores 12TB storage. We have 16 batch servers doing inserts and ~100 users doing mostly queries.
We have a wierd issue, we have a long query that takes 30 seconds to run 1st time then 10-20 secs every other time. Based on knowledge of DB we expected it to take a lot less. Then a developer reformatted it by taking removing extra white space and line breaks. all of sudden query takes 6 secs first time and 0.8 every other time. we tripled checked to ensure they are identical and that only difference is white space and line breaks. We tried it with SQLDeveloper, TOAD, SQLPLUS, from out desktops, appserver. we could reproduce it every time, with white space 10-20 secs without it 0.8 secs. Query is 200 lines long with white space 30 without it.
Why would having white space make such a dramatic difference? because the query is longer eventhough its identical? We checked parsing times, etc, no difference. Is there some network setting, oracle parameter, sqlnet setting? We spent hours looking on google and found nother
Slow:
SELECT grt_student.student_id
AS student_id,
grt_student.last_name
AS last_name,
grt_student.first_name
AS first_name,
grt_buyerinstance.buyerinstance_id
AS buyerinstance_id,
grt_buyerinstance.buyerfamily_id
AS buyerfamily_id,
grt_buyer.buyerfamily_acronym
AS buyerfamily_acronym,
grt_reporting_utls_pkg.convert_gmrt_battery(grt_buyerinstance.buyerfamily_id,grt_buyer.battery)
AS battery,
fast:
SELECT grt_student.student_id
AS student_id, grt_student.last_name
AS last_name, grt_student.first_name AS first_name, grt_buyerinstance.buyerinstance_id AS buyerinstance_id, grt_buyerinstance.buyerfamily_id
AS buyerfamily_id,
grt_buyer.buyerfamily_acronym AS buyerfamily_acronym, grt_reporting_utls_pkg.convert_gmrt_battery(grt_buyerinstance.buyerfamily_id,grt_buyer.battery) AS battery,Do you have some sort of horrific network connection between the client and the database such that it would take 8.5 seconds to transmit a few kb of SQL to the server? That seems most unlikely.
How are you determining the query plan? Are you absolutely sure that both SQL statements have the same plan_hash_value when they are actually executed (not just when you generate a query plan without executing it)? What are the differences in wait events when you execute the two?
The sql_id will change when you add or remove whitespace. There are various methods of modifying query plans that are tied to a sql_id. My wager would be that you have a profile/ outline/ etc. that is not there for the reformatted one which is causing a query plan difference. My next guess is that you have an accepted plan for the old statement, you haven't set up a process to let the plan evolve, and the reformatted statement starts with the plan that the old statement would get if you allowed the plan to evolve.
Justin -
How to use the WHENEVER SQLERROR EXIT statement in a PL/SQL block.
Hi,
I am getting the following error when trying to add the following statement in an PL/SQL block.
WHENEVER SQLERROR EXIT SQL.SQLCODE
[exec] ERROR at line 23:
[exec] ORA-06550: line 23, column 12:
[exec] PLS-00103: Encountered the symbol "SQLERROR" when expecting one of the
[exec] following:
[exec] := . ( @ % ;
How can i use the above statement in the PL/SQL Block? I have only IF statement in that block( between BEGIN and END).
ThanksHi,
Usually there's always more than one solution.
Can you post an example of what you're trying to accomplish?
That would be useful.
(Place the tag before and after your example to maintain formatting en spacing, see the [fac|http://forums.oracle.com/forums/help.jspa] regarding available tags) -
Call to concurrent program in a pl/sql block does not COMMIT data to table
I have the following PL/SQL block.
apps.create_po(x_org_id,x_document_num,x_agent_name,x_vendor_id,x_vendor_site_id,x_ship_to_location,x_bill_to_location,x_creation_date,new_isbn,new_print_key,new_unit_setup_cost,new_unit_run_cost,x_item,x_category_id,x_item_description,x_unit_of_measure,x_quantity,x_unit_price,x_ship_to_org_id,x_promise_date,x_qty_rcv_tolerance, x_deliver_to_location,x_destination_org_id, x_destination_subinventory,x_segment2,x_segment4);
COMMIT;
FND_GLOBAL.APPS_INITIALIZE(v_user_id,v_resp_id,201);
v_po_req_id := apps.fnd_request.submit_request('PO','POXPOPDOI',NULL,NULL,NULL,
NULL,'STANDARD',NULL,'Y',NULL,'APPROVED',NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_po_req_id);
IF v_po_req_id <> 0 THEN
dbms_lock.sleep(60);
dbms_output.Put_line('Sleep executed');
COMMIT;
select PHASE_CODE,STATUS_CODE INTO v_phase_code,v_status_code
FROM FND_CONCURRENT_REQUESTS
WHERE REQUEST_ID = v_po_req_id;
dbms_output.put_line('After commit Phase and status codes are = '||v_phase_code || v_status_code);
ELSE
ROLLBACK;
END IF;
dbms_output.put_line('New Po is' || x_document_num);
dbms_output.put_line('Quantity Is'|| x_quantity);
apps.receive_po(x_document_num,x_quantity);
v_rcv_req_id := apps.fnd_request.submit_request('PO','RVCTP',NULL,NULL,NULL,
'BATCH',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_rcv_req_id);
IF v_rcv_req_id <> 0 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('COMMITED RECEIVING');
ELSE
ROLLBACK;
END IF;
Presently when this block runs, i can see the new PO number created. Commit is also successfully executed. The last output for the program is
New Po is 20651
Quantity Is 450
But due to some reason, the receiving program(receive_po) cannot retrieve the same PO from the base table.
But once this pl/sql block is complete, and i call the receving procedure from a different session, the Po is retrieved and receiving against the PO is executed successfully.
Can someone please suggest a work around ? Is the code missing something ? Since POXPOPDOI is a concurrent program which is executed as an asyncronous process, the commit statement after the call to concurent program does not work but the commit is executed only after it exits the pl/sql block.Thanks for responding.
receive_po() program just inserts the data into RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE tables based on the PO that is created in the previous step. So basically the new PO created has to be received and the receive_po() just inserts data into the interface tables so that RVCTP can be called after that for receiving.
Here is the code for the procedure.
SET SERVEROUTPUT ON;
--FND_GLOBAL.APPS_INITIALIZE(3,20707,201);
--Procedure for receiving interface to load data to RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE
CREATE OR REPLACE PROCEDURE receive_po (x_ponum IN VARCHAR2,x_quantity IN NUMBER) AS
v_vendor_site_id NUMBER;
v_vendor_id NUMBER;
v_agent_id NUMBER;
v_ship_to_organization_id NUMBER;
v_item_id NUMBER;
v_uom_code varchar2(25);
v_subinventory varchar2(25);
v_ship_to_location_id NUMBER;
BEGIN
--header information in variables
dbms_output.put_line('Entering Receiving Insert Procedure');
dbms_output.put_line('Po number ='||x_ponum||'$');
dbms_output.put_line('Quantity is ='||x_quantity||'$');
select pvsa.vendor_site_id into v_vendor_site_id
FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
where pha.vendor_id = pv.vendor_id
and pv.vendor_id = pvsa.vendor_id
and pha.segment1 = x_ponum;
dbms_output.put_line('Vendor Site ID is' ||v_vendor_site_id);
select pv.vendor_id into v_vendor_id
FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
where pha.vendor_id = pv.vendor_id
and pv.vendor_id = pvsa.vendor_id
and pha.segment1 = x_ponum;
dbms_output.put_line('Vendor ID is' ||v_vendor_id);
select plla.SHIP_TO_ORGANIZATION_ID into v_ship_to_organization_id
from PO_HEADERS_ALL pha, PO_LINE_LOCATIONS_ALL plla
where pha.PO_HEADER_ID = plla.PO_HEADER_ID
and pha.segment1 = x_ponum;
dbms_output.put_line('Ship to org is' ||v_ship_to_organization_id);
select agent_id into v_agent_id
FROM po_headers_all
WHERE segment1 = x_ponum;
dbms_output.put_line('Agent ID is' ||v_agent_id);
--printing header table information
dbms_output.put_line('vendor id is:'||v_vendor_id);
dbms_output.put_line('vendor site id is:'||v_vendor_site_id);
dbms_output.put_line('agent id is:'||v_agent_id);
dbms_output.put_line('ship to organization id is:'||v_ship_to_organization_id);
--line information in variables
--derive item id
select pla.item_id into v_item_id
from po_headers_all pha, po_lines_all pla
where pha.po_header_id = pla.po_header_id
and pha.org_id = pla.org_id
and pha.segment1 = x_ponum;
--derive uom
select pla.unit_meas_lookup_code into v_uom_code
from po_headers_all pha, po_lines_all pla
where pla.po_header_id = pha.po_header_id
and pla.org_id = pha.org_id
and pha.segment1 = x_ponum;
--derive subinventory
select pda.destination_subinventory into v_subinventory
from po_headers_all pha, po_lines_all pla,po_distributions_all pda
where pha.po_header_id = pla.po_header_id
and pla.po_header_id = pda.po_header_id
and pla.po_line_id = pda.po_line_id
and pha.org_id = pla.org_id
and pla.org_id = pda.org_id
and pha.segment1 = x_ponum;
--derive ship to location id
select ship_to_location_id into v_ship_to_location_id
from po_headers_all
where segment1 = x_ponum;
--printing transaction table details
dbms_output.put_line('item id is:'||v_item_id);
dbms_output.put_line('UOM is:'||v_uom_code);
dbms_output.put_line('subinventory is:'||v_subinventory);
dbms_output.put_line('ship to location id is:'||v_ship_to_location_id);
--insert data into the receiving interface header table
INSERT INTO RCV_HEADERS_INTERFACE
HEADER_INTERFACE_ID ,
GROUP_ID ,
PROCESSING_STATUS_CODE ,
RECEIPT_SOURCE_CODE ,
TRANSACTION_TYPE ,
LAST_UPDATE_DATE ,
LAST_UPDATED_BY ,
LAST_UPDATE_LOGIN,
CREATION_DATE ,
CREATED_BY ,
VENDOR_ID ,
VENDOR_SITE_ID ,
SHIP_TO_ORGANIZATION_ID ,
EXPECTED_RECEIPT_DATE ,
EMPLOYEE_ID ,
VALIDATION_FLAG
SELECT
RCV_HEADERS_INTERFACE_S.NEXTVAL,
RCV_INTERFACE_GROUPS_S.NEXTVAL,
'PENDING',
'VENDOR',
'NEW', -- 'CANCEL',
sysdate,
3,
3,
sysdate,
3,
v_vendor_id,
v_vendor_site_id,
v_ship_to_organization_id,
sysdate+5,
v_agent_id,
'Y'
FROM DUAL;
commit;
--insert data into the interface transaction table
for i in 1..1 loop
INSERT INTO RCV_TRANSACTIONS_INTERFACE
(INTERFACE_TRANSACTION_ID ,
HEADER_INTERFACE_ID ,
GROUP_ID ,
LAST_UPDATE_DATE ,
LAST_UPDATED_BY ,
CREATION_DATE ,
CREATED_BY ,
LAST_UPDATE_LOGIN,
TRANSACTION_TYPE ,
TRANSACTION_DATE ,
PROCESSING_STATUS_CODE ,
PROCESSING_MODE_CODE ,
TRANSACTION_STATUS_CODE ,
QUANTITY ,
UNIT_OF_MEASURE ,
ITEM_ID ,
AUTO_TRANSACT_CODE ,
RECEIPT_SOURCE_CODE ,
SOURCE_DOCUMENT_CODE ,
SUBINVENTORY ,
DOCUMENT_NUM ,
SHIP_TO_LOCATION_ID ,
VALIDATION_FLAG
SELECT
RCV_TRANSACTIONS_INTERFACE_S.NEXTVAL,
RCV_HEADERS_INTERFACE_S.CURRVAL,
RCV_INTERFACE_GROUPS_S.CURRVAL,
SYSDATE,
3,
SYSDATE,
3,
3,
'RECEIVE', --'RECEIVE', -- 'SHIP', --'06-JAN-1998',--question here
sysdate,
'PENDING',
'BATCH',
'PENDING',
x_quantity,
v_uom_code,
v_item_id,
'DELIVER', -- 'RECEIVE', --'DELIVER',
'VENDOR',
'PO',
v_subinventory,
x_ponum,
v_ship_to_location_id,
'Y'
FROM DUAL;
end loop;
commit;
END receive_po;
I am really stuck and looking out for work arond. Please help.
Thanks,
Natasha -
Can someone help me?
I just wanna make a line break in a txt file...
I tried it this way
FileWriter fw = new FileWriter("W:\\write.txt");
fw.write(string1 + "\n" + string2);
fw.close();
I don't know why it doesn't work.
in the file it apears just a black block, but if i copy it in this text area, theres automaticly a line break
thx for your support
GuardianEverything has been said, but I thought I'll just make it more clearly :-)
The thing is:
Unix use a line break; <or was it vice versa>
Afterwards someone decided text had to be devided in linebreaks and paragraph;
That's why you have <p> and <br> in html
Now line break just means, I'm on the end of a line and i must break but i don't want to
so please if you can, hold it on the same line when displaying.
So to keep multiple platform oparability it's a good thing to use both:
newline character + carriage return = break to other line -
How to add a new line in SMS(Line Break).
Hi All,
I need to send SMS from PL\SQL Procedure
The problem i have been facing is that the string being passed in as sms content is not parsing a newline character.
It shows all content in one line.
I need to break them in several lines.
Give me a direction how to add a new line in SMS.
Regards,
Raj.Hi,
Sure, Here it is
CREATE OR REPLACE PROCEDURE APPS.AUTO_SMS_RTV_REPORT
IS
sender VARCHAR2(1000);
recipient VARCHAR2(1000);
message VARCHAR2(4000);
sub VARCHAR2(1000) := 'HELLO';
dt1 varchar2(1000) := to_char(sysdate,'DD-MON-YY');
mailhost VARCHAR2(30) := '10.7.7.xxx';
mail_conn UTL_SMTP.CONNECTION;
v_crlf VARCHAR2(2) := CHR(13)||CHR(10);
CURSOR cur_Rejection_Records IS
SELECT DISTINCT
rt.VENDOR_SITE_ID ,
pvs.email_address VENDOR_MAIL_ID ,
pvs.PHONE vendor_contact_no ,
hre.EMAIL_ADDRESS Employee_mail_id ,
hre.FULL_NAME
FROM apps.rcv_transactions rt,
apps.po_vendors pv,
apps.po_vendor_sites_all pvs,
apps.mtl_transaction_reasons mtr,
apps.fnd_user fu,
apps.hr_employees hre
WHERE transaction_type = 'RETURN TO VENDOR'
--AND TRUNC(rt.transaction_date) = TRUNC(SYSDATE)
AND rt.vendor_id = pv.vendor_id
AND rt.vendor_site_id = pvs.vendor_site_id
AND rt.REASON_ID = mtr.REASON_ID(+)
AND fu.user_id = rt.last_updated_by
AND hre.EMPLOYEE_ID = fu.EMPLOYEE_ID
AND TRANSACTION_ID IN (
11902189,
11902253,
11902148)
BEGIN
FOR rec_Rejection_Records IN cur_Rejection_Records
LOOP
Begin
sender := '<[email protected]>';
recipient := rec_Rejection_Records.vendor_contact_no || '@aaaa.com';
mail_conn := utl_smtp.open_connection(mailhost, 8025);
utl_smtp.helo(mail_conn, mailhost);
utl_smtp.mail(mail_conn, sender);
utl_smtp.rcpt(mail_conn, recipient);
utl_smtp.DATA( mail_conn,
'Date: ' || TO_CHAR(SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || utl_tcp.crlf ||
'From: ' || sender || utl_tcp.crlf ||
'Subject: '|| sub || utl_tcp.crlf ||
'To: ' || recipient || utl_tcp.crlf ||
utl_tcp.crlf ||
'Dear Supplier,'||CHR(10)|| utl_tcp.crlf ||'\\\0x0A'|| -- HERE I NEED LINE BREAK
'Please.'|| utl_tcp.crlf
DBMS_OUTPUT.PUT_LINE('Yep !!! SMS Sent Sucessfully :) ');
utl_smtp.quit(mail_conn);
EXCEPTION
WHEN UTL_SMTP.PERMANENT_ERROR THEN
dbms_output.put_line('Error - ' || SQLCODE || ' - ' || SQLERRM);
WHEN OTHERS THEN
dbms_output.put_line('Error - ' || SQLCODE || ' - ' || SQLERRM);
END;
END LOOP;
END AUTO_SMS_RTV_REPORT;
/ -
Error while invoking webservice using UTL_HTTP from PL/SQL Block
Hi All,
I am invoking a webservice (SOAP Request) from a PL/SQL block using UTL_HTTP package.
I am able to send the complete request and am getting the required instance on the BPEL Console, but the process is erroring out while getting response back.
and the PL/SQL Block is ending in error mentioned below:
ERROR at line 1:
ORA-29266: end-of-body reached
ORA-06512: at "SYS.UTL_HTTP", line 1321
ORA-06512: at "APPS.CSM_BPEL_TEST_PKG", line 34
ORA-06512: at line 1
Package is completing successfully if i test in local DB and local BPEL.
But giving above error in client's.
Can anyone let me know what is the cause of this.
Thanks in advanceI got it working by making process Synchronous.
But with asynchronous process it is still same error.
Thanks... -
What is the wrong in this PL/SQL block
Hi a...
Can you please tell what is the wrong in this pl/sql block.
declare
TYPE TYP_NT_NUM IS TABLE OF NUMBER ;
v_tab TYP_NT_NUM := TYP_NT_NUM();
TYPE uname is VARRAY(30) of varchar2(100) ;
usr uname := uname ( 'u1','u2','u3','u4' );
TYPE pwd is VARRAY(30) of varchar2(100) ;
psw pwd := pwd('p1','p2','p3','p4');
x number(10):=0;
Cursor fcid IS Select distinct FC_ID From FCMASTER ;
Begin
Open fcid ;
--for ii in usr.first .. usr.last loop
Loop
Fetch fcid Into x ;
Exit When fcid%NOTFOUND ;
v_tab(fcid%ROWCOUNT) := x ;
End loop ;
For iii IN v_tab.FIRST .. v_tab.LAST Loop
dbms_output.put_line(v_tab(iii).FC_ID) ;
End loop ;
End loop; End of outer loop
End;
The error is
Error
[row:28,col:36] ORA-06550: line 28, column 36:
PLS-00487: Invalid reference to variable 'NUMBER'
ORA-06550: line 28, column 4:
PL/SQL: Statement ignored
Thanks in advance,
Palv_tab(iii).FC_ID
declare
type typ_nt_num is table of number;
v_tab typ_nt_num;
begin
select distinct object_id bulk collect into v_tab from all_objects where rownum <= 10;
for i in 1 .. v_tab.count loop
dbms_output.put_line(v_tab(i)) ;
end loop ;
end;
/ -
Read Only TextAreas with Carriage Return, Line Breaks and Word Wrapping
Hi all,
I know there are a few posts around this subject but I cannot find the answer to the exact problem I have.
I have a page that has a 'TextArea with Character Counter' (4000 Chars) that is conditionally read only based on the users credentials (using the 'Read Only' attributes of the TextArea item).
When the field is editable (not Read Only) everything works fine but when I make the field Read Only I start to have problems:
The first problem is that the Carriage Return and Line Breaks are ignored and the text becomes one continuos block. I have managed to fix this by adding pre and post element text of pre and /pre tags. This has made the Carriage Return and Line Breaks word nicely and dispaly correctly.
However, it has introduced a second problem. Long lines, with no Carriage Returns or Line Breaks, now extend to the far right of the page with no word wrapping, making my page potentially 4000+ characters wide.
How can I get the field to be display only, with recognised Carriage Returns and Line Breaks, and Word Wrapping inside a fixed width of, say, 150 characters?
Many thanks,
MartinHi,
Just a cut and paste of yours with the field name changed:
htp.p('<script>');
htp.p('$x("P3_COMMENTS").readonly=true;');
htp.p('</script>');I also have the following in the page HTML Header, could they be conflicting?
<script type="text/javascript" language="JavaScript">
function setReleaseToProd(wpTypeCode){
//setReleaseToProd($v(this))
var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=set_release_to_prod',0);
get.addParam('x01',wpTypeCode);
gReturn = get.get();
if(gReturn) {
$s('P3_RELEASE_TO_PROD',gReturn);
get = null;
</script>I am a long way from knowing much about Javascript (this page code was written by someone else) so all help is much appreciated.
Martin -
Can some one please tell me what is the problem in the below pl/sql block
Hi, I have problem with the following pl/sql block, I need this with bulk operation.
-- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
-- dept ( for all the validation errors, even if we have any validation at child it has to update the header record with error message),
-- upon successful validation insert the data into dept3, and emp3 interms of batches
-- I have give the sample example with dept and emp, but i have around 10 million records which has around 30-40 validations,
-- I would like to process them in terms of batches using bulk collection as this would do fast processing
-- Can some one please tell me how to insert them in terms of bulk with every set of 1000 records in each batch in this example,for every set of 1000 records
-- i need update batch id with unique number in dept table
-- with current data i can have 50 batches , I need to pass, deptno as parameter to my emp cursor.
-- can some one please tell me how to make this validation and insertion more efficient. so that while inserting the data for every batch it should insert batch id
-- Tried with LIMIT clause as well but not working
-- I am correcting the code as per your comments Request you to please suggest me so that I can correct , I am new to PL/sql, started learning now.
step - 1:
CREATE TABLE DEPT
(DEPTNO NUMBER(6) primary key,
DNAME VARCHAR2(25),
LOC VARCHAR2(23),
batch_id number );
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK', null);
INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS', null);
INSERT INTO DEPT VALUES (30, 'SALES', 'CHICAGO', null);
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON', null);
step - 2:
declare
begin
for i in 1..50000 loop
insert into dept values(40+i, 'OPERATIONS'||i,'BOSTON'||i, null);
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception occured:'||SQLERRM);
end;
step - 3:
create sequence emp_seq start with 1 increment by 1;
step - 4:
CREATE TABLE EMP
(EMPNO NUMBER(15) NOT NULL primary key,
ENAME VARCHAR2(20),
JOB VARCHAR2(20),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(6));
INSERT INTO EMP VALUES
(7369, 'SMITH', 'CLERK', 7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20);
INSERT INTO EMP VALUES
(7499, 'ALLEN', 'SALESMAN', 7698,
TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);
INSERT INTO EMP VALUES
(7521, 'WARD', 'SALESMAN', 7698,
TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
INSERT INTO EMP VALUES
(7566, 'JONES', 'MANAGER', 7839,
TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
INSERT INTO EMP VALUES
(7654, 'MARTIN', 'SALESMAN', 7698,
TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
INSERT INTO EMP VALUES
(7698, 'BLAKE', 'MANAGER', 7839,
TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
INSERT INTO EMP VALUES
(7782, 'CLARK', 'MANAGER', 7839,
TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
INSERT INTO EMP VALUES
(7788, 'SCOTT', 'ANALYST', 7566,
TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7839, 'KING', 'PRESIDENT', NULL,
TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
INSERT INTO EMP VALUES
(7844, 'TURNER', 'SALESMAN', 7698,
TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, NULL, 30);
INSERT INTO EMP VALUES
(7876, 'ADAMS', 'CLERK', 7788,
TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
INSERT INTO EMP VALUES
(7900, 'JAMES', 'CLERK', 7698,
TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30);
INSERT INTO EMP VALUES
(7902, 'FORD', 'ANALYST', 7566,
TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7934, 'MILLER', 'CLERK', 7782,
TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);
commit;
step :- 5
declare
cursor c1 is select * from dept;
k number:=0;
m number:=0;
begin
for i in c1 loop
k:=k+1;
--dbms_output.put_line('k:'||k);
--dbms_output.put_line('i.deptno:'||i.deptno);
m:=0;
for j in 1..5 loop
m:=m+1;
--dbms_output.put_line('m:'||m);
--dbms_output.put_line('i.deptno:'||i.deptno);
insert into emp values
(9000+emp_seq.nextval, 'SMITH'||'_'||emp_seq.currval, 'CLERK'||'_'||emp_seq.currval, 7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, i.deptno);
end loop;
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception occured:'||sqlerrm);
end;
step :-6
create table dept3 as select * from dept where 1=2;
create table emp3 as select * from emp where 1=2;
alter table dept add object_id number;
alter table dept add status varchar(20);
alter table dept add err_msg varchar2(200);
alter table emp add object_id number;
-- I have not included the alter statements in the inital creation because i dont want them to insert into dept3 and emp3
CREATE OR REPLACE
PACKAGE test_b
AS
g_batch_id NUMBER;
PROCEDURE emp_ins(
p_EMPNO NUMBER,
p_ENAME VARCHAR2,
p_JOB VARCHAR2,
p_MGR NUMBER,
p_HIREDATE DATE,
p_SAL NUMBER,
p_COMM NUMBER,
p_DEPTNO NUMBER);
PROCEDURE dept_ins(
p_DEPTNO NUMBER,
p_dname VARCHAR2 ,
p_LOC VARCHAR2,
p_batch NUMBER);
PROCEDURE validate_prc;
PROCEDURE main;
TYPE dept_t
IS
TABLE OF dept%ROWTYPE;
hdr_tbl dept_t;
TYPE emp_t
IS
TABLE OF emp%ROWTYPE;
line_tbl emp_t;
TYPE dept_i_t
IS
TABLE OF dept3%ROWTYPE;
hdr_ins_tbl dept_i_t;
TYPE emp_i_t
IS
TABLE OF emp3%ROWTYPE;
line_ins_tbl emp_i_t;
END;
-- pacakge body
CREATE OR REPLACE
PACKAGE body test_b
AS
PROCEDURE emp_ins(
p_EMPNO NUMBER,
p_ENAME VARCHAR2,
p_JOB VARCHAR2,
p_MGR NUMBER,
p_HIREDATE DATE,
p_SAL NUMBER,
p_COMM NUMBER,
p_DEPTNO NUMBER)
IS
BEGIN
INSERT
INTO EMP3
EMPNO ,
ENAME ,
JOB ,
MGR ,
HIREDATE ,
SAL ,
COMM ,
DEPTNO
VALUES
P_EMPNO ,
P_ENAME ,
P_JOB ,
P_MGR ,
P_HIREDATE ,
P_SAL ,
P_COMM ,
P_DEPTNO
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT EMP INSERT'||SQLERRM);
END;
PROCEDURE dept_ins
p_DEPTNO NUMBER,
p_dname VARCHAR2 ,
p_LOC VARCHAR2,
p_batch NUMBER
IS
BEGIN
INSERT
INTO DEPT3
DEPTNO ,
DNAME ,
LOC ,
batch_id
VALUES
p_DEPTNO ,
p_DNAME ,
p_LOC ,
p_batch
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT DEPT INSERT'||SQLERRM);
END ;
PROCEDURE validate_prc
IS
CURSOR c1
IS
SELECT * FROM dept WHERE status IS NULL ;--AND rownum <25;
CURSOR c2(p_dept NUMBER )
IS
SELECT * FROM emp WHERE deptno=p_dept;
e_validation EXCEPTION;
BEGIN
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO hdr_tbl limit 5000;
SELECT emp_seq.nextval INTO g_batch_id FROM dual;
EXIT
WHEN hdr_tbl.count = 0;
dbms_output.put_line('batch'||g_batch_id);
END LOOP;
CLOSE c1;
dbms_output.put_line('C1 closed');
--------- Loading data into the inv line table type -------------------------------
FOR i IN 1 .. hdr_tbl.count
LOOP
dbms_output.put_line('started validation');
-- do header level validations
IF hdr_tbl(i).dname IS NULL THEN
hdr_tbl(i).status := 'ERROR';
hdr_tbl(i).err_msg :=',DNAME is null';
END IF;
OPEN c2(hdr_tbl(i).deptno);
LOOP
FETCH c2 BULK COLLECT INTO line_tbl;
-- EXIT WHEN c2%NOTFOUND;
END LOOP;
CLOSE c2;
FOR j IN 1 .. line_tbl.count
LOOP
-- do line validations
IF line_tbl(j).ename IS NULL THEN
hdr_tbl(i).status := 'ERROR';
hdr_tbl(i).err_msg :=',ENAME is null';
END IF;
BEGIN
FORALL j IN line_tbl.FIRST .. line_tbl.LAST
SAVE EXCEPTIONS
UPDATE EMP
SET object_id =3
-- I have multiple columns to update based on validations
WHERE deptno =hdr_tbl(i).deptno------------
AND empno =line_tbl (j).empno;
COMMIT;
line_tbl.DELETE;
dbms_output.put_line( 'Successfully updated emp temp table.');
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line( 'Error while updating line temp table. ' || sqlerrm );
FOR j IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
END LOOP;
raise e_validation;
END;
END LOOP; -- j
--CLOSE c2;
IF hdr_tbl(i).err_msg IS NULL THEN
hdr_tbl (i).status := 'VALID';
hdr_tbl (i).err_msg := NULL;
END IF;
-- even if I have line validation failed I have to update header status and erorr msg
BEGIN
FORALL i IN hdr_tbl.FIRST .. hdr_tbl.LAST
SAVE EXCEPTIONS
UPDATE DEPT
SET object_id =4,
status = hdr_tbl (i).status,
err_msg = hdr_tbl (i).err_msg
-- batch_id =
-- I have multiple columns to update based on validations
WHERE deptno = hdr_tbl (i).deptno
AND status IS NULL; ------------
COMMIT;
hdr_tbl.DELETE;
dbms_output.put_line( 'Successfully updated dept temp table.');
--close c1;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
dbms_output.put_line( 'Error while updating hdr temp table. ' || sqlerrm );
FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
END LOOP;
raise e_validation;
END;
END LOOP; --i
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('EXCEPTION AT validate'||SQLERRM);
END ;
PROCEDURE main
IS
CURSOR dept_ins_cur
IS
SELECT * FROM dept WHERE status='VALID';
CURSOR emp_ins_cur(p_deptno NUMBER)
IS
SELECT * FROM emp WHERE deptno= p_deptno;
BEGIN
validate_prc;
OPEN dept_ins_cur;
LOOP
FETCH dept_ins_cur BULK COLLECT INTO hdr_ins_tbl limit 1000
EXIT
WHEN dept_ins_cur%NOTFOUND;
END LOOP;
CLOSE dept_ins_cur;
--------- Loading data into the inv line table type -------------------------------
FOR i IN 1 .. hdr_tbl.count
loop
dept_ins(hdr_ins_tbl(i).deptno ,
hdr_ins_tbl(i).DNAME ,
hdr_ins_tbl(i).LOC , emp_seq.nextval);
commit;
OPEN emp_ins_cur(hdr_ins_tbl(i).deptno);
LOOP
FETCH emp_ins_cur BULK COLLECT INTO line_ins_tbl;
--EXIT WHEN emp_ins_cur%NOTFOUND;
END LOOP;
CLOSE emp_ins_cur;
for j in 1..line_ins_tbl.count loop
emp_ins(line_ins_tbl(j).EMPNO ,
line_ins_tbl(j).ENAME ,
line_ins_tbl(j).JOB ,
line_ins_tbl(j).MGR ,
line_ins_tbl(j).HIREDATE ,
line_ins_tbl(j).SAL ,
line_ins_tbl(j).comm ,
line_ins_tbl(j).DEPTNO );
end loop;
end loop;
commit;
BEGIN
forall i IN hdr_ins_tbl.first .. hdr_ins_tbl.last
SAVE exceptions
UPDATE dept
SET status = 'INSERTED',
err_msg = null
WHERE deptno=hdr_ins_tbl (i).deptno
AND status = 'VALID';
COMMIT;
hdr_ins_tbl.delete;
dbms_output.put_line( 'inserting into temp tables.');
EXCEPTION
WHEN OTHERS THEN
rollback;
end;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('exception in main' ||SQLERRM);
END ;
END;
Thanks in advance...
Message was edited by: 888025Hi, I have problem with the following pl/sql block
Well, as Hoek already said, that is the understatement of the century.
I can't be absolutely certain but I think that set of DDL and code that you posted has just about every possible error and design issue that there is! It would make an excellent addition to BluShadow's FAQs an an example of what NOT to do.
I don't think it is even possible to 'fix the basics first' as Hoek suggested. IMHO the first step needs to be to create a functional requirements document (FRD) that explains in detail WHAT needs to be done. That doc should also contain info about how any errors/recovery/restart is to be handled. It is premature to try to implement ANY solution without first knowing what is needed functionally.
Once the FRD is done you should do a walk-through based on your current architecture and sample data to make sure that the document really covers ALL of the steps that need to be performed and that it adequately explains how to deal with any processing or data issues that might arise.
The next document you need is the TRD - Technical Requirements Doc that covers the different technical implementions of the FRD that can be done and the advantages/disadvantages of each.
Then you can start working on a prototype.
1. The DDL you posted isn't coherent - there are CREATE table statements and then later ALTER statements that add additional columns. There doesn't appear to be any reason for not including ALL of the columns in the CREATE table statement.
2. You are using PL/SQL types instead of SQL types. That makes it impossible to use those types in SQL statements and makes it much more difficult to test since it is much easier to test a query in SQL (e.g. using sql*plus) that to embed the query in PL/SQL.
3. You are defining the same type twice but giving it different names.
TYPE dept_t
IS
TABLE OF dept%ROWTYPE
INDEX BY binary_integer;
TYPE dept_i_t
IS
TABLE OF dept%ROWTYPE
INDEX BY binary_integer;
Those are both based on the same DEPT table! Why the duplication?
Also you are using associative arrays instead of just using nested tables. Get rid of the INDEX BY clause.
4. You have some serious architectural and data model issues
-- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
-- dept ( for all the validation errors, even if we have any validation at child it has to update the header record with error message),
Why would you do that? You say 'it has to update the header record ...'. Says who? That is just one indication that you are trying to implement a 'solution' before you have adequately defined the 'problem'.
Typically you would NOT alter any of the data tables; any validation errors/issues would get inserted into a table specifically designed to hold/log those issues. That table would contain key field values to correlate with the source of the error.
Those 'master' and 'child' entities are two SEPARATE things. Issues with a 'master' row have NOTHING to do with any possible child rows.
And issues with a 'child' row have NOTHING to do with any possible master rows. The ONLY connection between 'child' and 'master' is the foreign key that correlates them.
So you don't necessarily have to validate the 'child' rows in sync with their 'master' row. In many cases you would have a procedure that performs validation of the entire set of 'master' rows and log those issues/problems. You would use a different procedure to validate the entire set of 'child' rows and log their issues.
Those validation procedures can often work with ALL of the data using SQL statements instead of bulk processing.
5. You are using loop constructs that are not valid for the type of processing you are using
LOOP
FETCH c1 BULK COLLECT INTO hdr_tbl;
EXIT
WHEN c1%NOTFOUND;
END LOOP;
There can be NO exit since the bulk collect with either get EVERYTHING or NOTHING. Possibly that is just a holdover from your attempt to use the LIMIT clause but you removed that clause from the FETCH; I don't know.
There is so much wrong with what you posted it is really rather pointless to try to 'fix' it.
I suggest you start over and clarify and DOCUMENT the actual requirements without prejudice about the solution that someone seems to want to force on you. -
How to handle line break embeded inside CSV column
Hi there,
I am under the pressure to make it work. I already put this question on APEX forum, but on second thought, I think it relates more to PL/SQL rather than APEX since APEX 4.1 already have utility to handle CSV Upload.
If you read it already in APEX forum, please ignore.
I am sorry for that. Thanks for reading.
I need to develop an app that allows user to upload CSV file to a interface table.
The APEX version at my workplace is 4.0.2.
I used the code from
http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:11000346061523
It all works well till recently I find out
If a column in a CSV file cotain a line break (or new line) e.g. (The tester copy and paste this text which has line break into a column in a spreadsheet)
This is the first sentence.
This is the second sentence.
It will break the “This is the second sentence”. To a new column.
The contents of the CSV viewed in Notepad look as below
Assessment Date,Scheduled Date,Assessment Provider,Assessor Name,Court,First Name,Middle Name,Last Name,PRN Person Record Number,NHI Number,Defendant Attended Y/N,Is Dependent Y/N,Notes,Primary Ethnicity,"Ethnicity Other, please specify",Gender,Currently in Treatment Y/N,Substance of Concern 5,Other Substance Specified
22/09/2012,,Provider Co Name,Warren Edgley,Wellington,,,Salty,2545554,dgsdf,ergerg,,"This is the first sentence.
This is the second sentence.",Japanese,,Female,b,,
Here is the code from the CSV UTIL, please help me to find out how can I replace the line break to a space so that the uploading process is correct.
CREATE OR REPLACE PACKAGE BODY "CSV_UTIL"
AS
--strip the beginning and the end quotes, then replace double quotation with single
FUNCTION de_quote (p_str IN VARCHAR2, p_enc_by IN VARCHAR2)
RETURN VARCHAR2
IS
v_str VARCHAR2(32767) := p_str;
BEGIN
IF (p_enc_by IS NULL)
THEN
RETURN p_str;
ELSE
IF SUBSTR(p_str,-1) = p_enc_by THEN
v_str := SUBSTR(p_str,1,LENGTH(p_str)-1);
END IF;
IF SUBSTR(p_str,1,1) = p_enc_by THEN
v_str := SUBSTR(v_str,2);
END IF;
RETURN REPLACE (v_str,
p_enc_by || p_enc_by,
p_enc_by
END IF;
END de_quote;
PROCEDURE parse (p_str IN VARCHAR2, p_enc_by IN VARCHAR2, p_sep IN VARCHAR2)
IS
l_n NUMBER DEFAULT 1;
l_in_quote BOOLEAN DEFAULT FALSE;
l_ch NCHAR (1);
l_len NUMBER DEFAULT NVL (LENGTH (p_str), 0);
BEGIN
IF (l_len = 0)
THEN
RETURN;
END IF;
g_words := g_empty;
g_words (1) := NULL;
FOR i IN 1 .. l_len
LOOP
l_ch := SUBSTR (p_str, i, 1);
IF (l_ch = p_enc_by)
THEN
l_in_quote := NOT l_in_quote;
END IF;
IF (l_ch = p_sep AND NOT l_in_quote)
THEN
l_n := l_n + 1;
g_words (l_n) := NULL;
ELSE
g_words (l_n) := g_words (l_n) || l_ch;
END IF;
END LOOP;
g_words (l_n) := de_quote (g_words (l_n), CHR(10));
g_words (l_n) := de_quote (g_words (l_n), CHR(13));
FOR i IN 1 .. l_n
LOOP
g_words (i) := de_quote (g_words (i), p_enc_by);
END LOOP;
END parse;
Author: Oleg Lihvoinen
Company: DbSWH
Changes:
10.02.2011, There was a miscalculation of the file line last position in case it is the end of file
PROCEDURE upload (p_file_name VARCHAR2, p_collection_name VARCHAR2, p_enc_by IN VARCHAR2, p_sep_by IN VARCHAR2, p_rows NUMBER)
IS
v_blob_data BLOB;
v_clob_data CLOB;
v_clob_len NUMBER;
v_position NUMBER;
v_char NCHAR (1);
c_chunk_len NUMBER := 1;
v_line VARCHAR2 (32767) := NULL;
v_data_array vcarray;
v_rows NUMBER := 0;
n_seq NUMBER := 1;
dest_offset NUMBER := 1;
src_offset NUMBER := 1;
amount INTEGER := DBMS_LOB.lobmaxsize;
blob_csid NUMBER := DBMS_LOB.default_csid;
lang_ctx INTEGER := DBMS_LOB.default_lang_ctx;
warning INTEGER;
l_sep VARCHAR2(100) := CASE WHEN p_sep_by = '\t' THEN chr(9) ELSE p_sep_by END;
BEGIN
htmldb_collection.create_or_truncate_collection
(p_collection_name => p_collection_name);
-- Read blob from wwv_flow_files
SELECT blob_content
INTO v_blob_data
FROM wwv_flow_files
WHERE NAME = p_file_name;
v_position := 1;
DBMS_LOB.createtemporary (lob_loc => v_clob_data,
CACHE => TRUE,
dur => DBMS_LOB.SESSION
DBMS_LOB.converttoclob (v_clob_data,
v_blob_data,
amount,
dest_offset,
src_offset,
blob_csid,
lang_ctx,
warning
v_clob_len := DBMS_LOB.getlength (v_clob_data);
IF v_clob_len = 0 THEN
RETURN;
END IF;
WHILE (v_position <= v_clob_len + 1)
LOOP
v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
v_line := v_line || v_char;
v_position := v_position + c_chunk_len;
-- When the whole line is retrieved and not end of file or end of file
IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
THEN
parse (p_str => v_line, p_enc_by => p_enc_by, p_sep => l_sep);
v_data_array := g_words;
FOR i IN 1..g_words.count LOOP
IF i <= 50 THEN
v_data_array(i) := g_words(i);
ELSE
exit;
END IF;
END LOOP;
FOR i IN g_words.count + 1..50 LOOP
v_data_array(i) := null;
END LOOP;
v_rows := v_rows + 1;
-- exit if uploaded specified number of rows
IF p_rows IS NOT NULL AND v_rows > p_rows THEN
EXIT;
END IF;
-- Store data to collection
n_seq :=
htmldb_collection.add_member
(p_collection_name => p_collection_name,
p_c001 => v_data_array
(1),
p_c002 => v_data_array
(2),
p_c003 => v_data_array
(3),
p_c004 => v_data_array
(4),
p_c005 => v_data_array
(5),
p_c006 => v_data_array
(6),
p_c007 => v_data_array
(7),
p_c008 => v_data_array
(8),
p_c009 => v_data_array
(9),
p_c010 => v_data_array
(10),
p_c011 => v_data_array
(11),
p_c012 => v_data_array
(12),
p_c013 => v_data_array
(13),
p_c014 => v_data_array
(14),
p_c015 => v_data_array
(15),
p_c016 => v_data_array
(16),
p_c017 => v_data_array
(17),
p_c018 => v_data_array
(18),
p_c019 => v_data_array
(19),
p_c020 => v_data_array
(20),
p_c021 => v_data_array
(21),
p_c022 => v_data_array
(22),
p_c023 => v_data_array
(23),
p_c024 => v_data_array
(24),
p_c025 => v_data_array
(25),
p_c026 => v_data_array
(26),
p_c027 => v_data_array
(27),
p_c028 => v_data_array
(28),
p_c029 => v_data_array
(29),
p_c030 => v_data_array
(30),
p_c031 => v_data_array
(31),
p_c032 => v_data_array
(32),
p_c033 => v_data_array
(33),
p_c034 => v_data_array
(34),
p_c035 => v_data_array
(35),
p_c036 => v_data_array
(36),
p_c037 => v_data_array
(37),
p_c038 => v_data_array
(38),
p_c039 => v_data_array
(39),
p_c040 => v_data_array
(40),
p_c041 => v_data_array
(41),
p_c042 => v_data_array
(42),
p_c043 => v_data_array
(43),
p_c044 => v_data_array
(44),
p_c045 => v_data_array
(45),
p_c046 => v_data_array
(46),
p_c047 => v_data_array
(47),
p_c048 => v_data_array
(48),
p_c049 => v_data_array
(49),
p_c050 => v_data_array
(50)
-- Clear the line
v_line := NULL;
END IF;
END LOOP;
END;
END;In my apps, I save these straight into a table rather than an APEX collection because the number of columns can be longer than 50.
I want to find out how can replace these line break inside a column to a space.
If any one has any ideas, please let me know.
Thanks a lot in advance.
AnnAnn586341 wrote:
I think the code split the whole thing by this line
-- When the whole line is retrieved and not end of file or end of file
IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
THEN
Yes, exactly. That piece of code believes all CHR(10) occurences are record delimiters.
It is not smart enough to recognize that a CHR(10) within quotation marks are part of the data.
Optimally a solution should keep the CHR(10) rather than replacing with spaces, but that will be a bigger rewrite of the UTL_CSV code ;-)
If you are happy with replacing with spaces, a "simple" solution could be something like:
Declare a boolean variable in upload procedure:
v_within_text_column boolean := false;And use it like this:
WHILE (v_position <= v_clob_len + 1)
LOOP
v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
IF v_char = '"' THEN
v_within_text_column := NOT v_within_text_column;
ELSIF v_char = CHR(10) AND v_within_text_column THEN
v_char := ' ';
END IF;
v_line := v_line || v_char;
v_position := v_position + c_chunk_len;
-- When the whole line is retrieved and not end of file or end of file
IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
THEN
v_within_text_column := false; -- To be safe always set this on "true" linebreaks
{code}
+(This is untested code just written here in the text editor.)+
It should work by toggling a flag whether you are "within" the quotes or not and then replacing CHR(10) with a space if you are within a text column.
This way we avoid having to go through the clob more than once (it is enough that this code walks the clob one character at a time...)
It will not handle if the clob contains situations like:
{code}
abc,123,"This is a text with a quote from a man who said \"To Be,
or Not To Be\" some hundred years ago",123,xyz
{code}
Escaped quotes would need separate attention ;-)
Maybe you are looking for
-
Has anyone heard of putting fibre optic camera into iphone4 to check for damage
HHas anyone ever heard of using fibre optic camera to look inside iphone 4 for damage without taking the phone apart
-
i got a creative zen for ny birthday and was asking for a ipod but oh well. i have a lot of music on my itunes. and for the life of my i cant figure out how to get my music in itunes over to my mp3 help me please someone
-
I'm trying out SDK 3.6 with ASC2 on OS X, and am having an issue with ANEs. Running my project in adl on OS X, everything is fine until I include an ANE in the project. This causes an immediate "VerifyError: Error #1079: Native methods are not allowe
-
APEXExport character set bug?
Hello, I'm having problems with the APEXExport utility. The resulting application is exported into some strange character set ... The character I am having problems with is U+2019, RIGHT SINGLE QUOTATION MARK, ' The character is represented in the ex
-
I have EHP4 running on two different machines on same network. Each one has different host name, SID and instance number. I am not able to join them and create transport routes. In STMS I am choosing u201CExternal Systemsu201D!!!. I am not sure what