Alter table then Update in PL/SQL block
I am trying to alter the table then update it :
declare
colCount number;*
begin*
select count(*) into colCount from all_tab_cols where table_name = 'TEST' and owner = 'TEST_OWNER';*
dbms_output.put_line('No of Columns in the table : ' || colCount);*
if colCount = 2 then*
dbms_output.put_line('Table needs upgrade');*
execute immediate('ALTER TABLE TEST ADD COL1 VARCHAR2(100) NULL');*
UPDATE TEST SET COL1 = '123';*
commit;*
else*
dbms_output.put_line('No Changes Required');*
end if;*
end;*
Oracle complains that "COL1" is an invalid identifier.
I also tried substitute the UPDATE statement with
** execute immediate('UPDATE TEST SET VCHCHARSET_OUT='UTF8' WHERE VCHCHARSETNAME='UTF8'');**
and there is something wrong with the construction of an Update statement in the parenthesis.
Am I taking the right approach and just need to figuire out the syntax of single quotes or something else is wrong?
thanks in advance.
Yes, you are absolutely right, I shouldn't alter the table and then update the values.
The reason I need to do it relates to the migration process we utilize in our company. Initially I had a set of SQL commands which I executed migrating from one environment to another and eventually to Production. I had an error in the last SQL command which caused migration process to produce "Failure", however the table was already altered and all the rows except the last one were updated. Since I can't successfully migrate to Production with the failed process I have to generate a PL/SQL block which will take in consideration that in one environment the table has already been modified and in the other one is still needs to be changed.
Similar Messages
-
Delete the data in table then update succesful
I write some code is work, then the update is fail , but if I delete the data in table then update succesful again, what is the possible reason??
Then you need to find out what you did wrong.
As you haven't even posted what you did, let alone what you did wrong, I don't know what magical process you're expecting forum members to engage in now.
This is the second meaningless question you have posted here today. I am locking them both.
In future if you want help here, you will need to provide a description of what you are trying to do, the code, what happened instead, and any error messages and stack traces, complete, cut and pasted rather than transcribed or otherwise mangled. Otherwise posting here is just a complete waste of everybody's time, including your own.
Moderator -
Alter database statement in anonymous pl/sql block
Is it possible to include an alter database statement in an anonymous pl/sql block?
When I execute this code to query user_tables for all table names, disable their constraints and drop the table, I got the following error:
***MY CODE
-- DECLARE VARIABLE(S)
DECLARE
v_TABLE_NAME TABLE_NAME.USER_TABLE%TYPE;
-- DECLARE AND DEFINE CURSOR
CURSOR c_GETTABLES is
SELECT TABLE_NAME from USER_TABLES;
BEGIN
OPEN c_GETTABLES;
LOOP
FETCH c_GETTABLES into v_TABLE_NAME;
EXIT when c_GETTABLES%notfound;
ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
DROP TABLE v_TABLE_NAME;
END LOOP;
CLOSE c_GETTABLES;
END;
***RESPONSE FROM SERVER
ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
ERROR at line 15:
ORA-06550: line 15, column 1:
PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
ThanksWhen you want to perform ddl statements in a (anonymous) PL/SQL block, you have to use dynamic SQL because ddl is not possible in pl/sql.
Dynamic sql means that you sort of execute ddl statements in a sql manner. To use dynamic sql, two options exist:
- dbms_sql package : for oracle before 8i. To use this package is not always easy. Read about it carefully first before using.
- Native Dynamic SQL : implemented in 8i and very easy to use. An example would be :
declare
lv_statement varchar2(32676);
begin
lv_statement := 'ALTER TABLE MY_TABLE DISABLE CONSTRAINT MY_TABLE_CK1';
execute immediate lv_statement;
lv_statement := 'ALTER TABLE MY_TABLE ENABLE CONSTRAINT MY_TABLE_CK1';
execute immediate lv_statement;
end;
Good luck.
Edwin van Hattem -
Table not updating while command button is held down
Hi guys,
My application obtains data and then outputs this into a table which updates after each set of data is read. This part works fine, however I also require the user to be able to hold down one of two buttons to control control the function of an actuator (forwards and rearwards). To explain this further, when one of these buttons are pressed a voltage is output, when released the voltage is reset to zero. However, while the button is held down the table does not continue to update, when the button is released the table then updates through all the queued values. I understand that this is most likely a problem with the holding of the button causing the other user interface events to not be processed. I have therefore tried using ProcessSystemEvents(), ProcessDrawEvents(), and experimented with using an async timer to control the updating of the UI through the use of PostDeferredCallback(), all without success.
If anyone can help with a solution that would allow me to perform both of these required functions simultaneously it would be greatly appreciated!
Thanks in advance
Ben
Solved!
Go to Solution.Could you use a toggle button instead of a simple button to be hold down? If yes, then in the button callback you could simple test the value of the toggle (1 if pressed, 0 if released) and operate turn on/off the output voltage to the actuator. You'll have a commit event every time the operator changes button state. (you may need to apply some security limit switch or timeput on the control in case the user forgets to turn the toggle off: the situation is similar to a three-state switch that controls a motorized window blind).
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Table schema not being updated after a SQL 'alter'
Hi all,
I have a problem to do with altering table columns and queries relating to that table thereafter.
I have a table which has been queried using an OracleDataAdapter.Fill(DataSet), if I add a column using say using an OracleCommand.ExecuteNonQuery() or sqlplus session (and doing a 'commit' after) the column does not show up on subsequant 'Fill' queries unless I reopen the DB connection.
Just as an example, here is my test table which is defined as:
create table steveTest
id numeric,
name varchar(15),
address varchar(25)
with a few rows of data in...
If I query the table using ODP.NET (10 & 11)
OracleDataAdapter oraDap = new OracleDataAdapter("select * from steveTest",oraCon);
oraDap.Fill(ds);
Everything is fine until I add/remove a column with say sqlplus or via an OracleCommand.ExecuteNonQuery()
e.g "alter table steveTest add address2 varchar2(30)"
Subsequent Fill or data reader queries only show the unchanged table schema, without the newly added column. If I remove a column the symptoms are worse and I receive a "ORA-01007: variable not in select list"
I can only think that ODP.NET is caching the schema for that table on that particular connection. Is there anyway to forcefully clear this out?
I have tried OracleConnection.PurgeStatementCache(); but this doesn't seem to help me.
My connection string is defined as:
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.27)(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));
User Id=system;
Password=mypass;
HA Events=true;
Validate Connection=true;
Pooling=false;
Enlist=false;
Statement Cache Purge=true;
Statement Cache Size=0;
The application I am writing is a middle tier application which handles various DB drivers and maintains several 'connection queues' which multiple lightweight client applications can use concurrently. As you can imagine, a possible scenario may arise where a table is queried, altered and then queried again which causes the above issue. The only way I can stop this from happening is if I close/open the DB connection but I don't want to do this after every alter statement.
I have tried this on Oracle Express 10g and Oracle 10g servers with ODP.NET clients (10.2.0.100/2.111.6.0). Just a point I thought worth mentioning, this does not happen in sqlplus.
Any help would be much appreciated.
Regards,
Stevemaybe u can check by debuggin the incoming idoc in we19.
1. check the data u are sending from the source system
2. check for the field before and ater change in the target system.
maybe the field is update with the same content. also check the status record of the idoc
Message was edited by:
Prabhu S -
OAF Update of Custom Table causing ORA-600 with database block corruption?
Using OA Framework 12.1.3, running under EBusiness Suite 12.1.3
Created Custom Web page operating against Custom Tables
ISSUE
On about 2% of new records, when OAF is UPDATING a record in a certain table, it is failing with
java.sql.SQLException: ORA-00607: Internal error occurred while making a change to a data block
ORA-00600: internal error code, arguments: [kddummy_blkchk], [815], [26412], [6110], [], [], [], []
ORA-06512: at line 1
Before the DBA turned on 10.2.0.4.0 DB_BLOCK_CHECKING parameter, this actually
resulted in corrupted data blocks in the database and corrupted indexes that
eventually crashed the database and we had to do a full recovery with 2 days downtime.
Now that we have turned on DB_BLOCK_CHECKING, it simply errors out and puts things
in the alert log, but the records still fail to update as the writes are blocked.
Then oddly, a few days later.. the records become editable. And others fail.
This is ONLY happening on the one particular table being updated by OAF. Other custom pages
posting to other custom tables are having no problems. We've CTAS'd the table back and
forth and recreated the indexes, and that did not help.
Support says to post to the Forum ( So I am! ) or hire Oracle consulting.. which doesn't make
much sense given the error. The Recovery Team that helped us in a separate SR ( we had
to do db_repairs not just recovery ) felt it was an important problem the OAF team needed to
strongly review.
Anyone else encounter this already and know of a solution?
TIA
KarlAfter MANY hours of trial and error and research, we've identified ONE use case that seems to apply to 90% of the issue we have encountered.
YMMV.
The BC4J generated SQL which is generating the ORA-600 is
BEGIN UPDATE XXRETURNHEADER ReturnHeaderEO SET INTERNAL_TEXT=?,LAST_MOD_USERNAME=?,OBJECT_VERSION_NUMBER=?,LAST_UPDATE_DATE=?,LAST_UPDATED_BY=?,LAST_UPDATE_LOGIN=? WHERE RMA_NUMBER=? AND ORGANIZATION_ID=? RETURNING TROUBLESHOOT_DATE, FAA_TAG_DATE, FAILURE_ANALYSIS_DATE, LAST_MOD_DATE, FAA_REVISED_DATE, TTE_TECH_SEND_DATE, TTE_REP_RESPONSE_DATE, TTE_REP_APPROVED, TTE_RMA_RANDOM_KEY, OBJECT_VERSION_NUMBER, LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN INTO ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?; END;".
We determined that if TTE_RMA_RANDOM_KEY was not a null value, we would get an ORA-600 error whenever we did an APPLY from the OAF Page to update the record.
If we set that table attribute to NULL for the record using SQL.. then used the OAF Page to APPLY.. it worked fine and the record saved without error.
We then modified the EO to NOT "Refresh After Update" ( thus removing it from the RETURNING clause generated )... and even if the TTE_RMA_RANDOM_KEY
had a value... the OAF Page APPLY worked and the record saved without error.
I cannot identify anything from the User programming side that is wrong ( and neither could Oracle ), and it REALLY should be in the RETURNING clause list of
attributes.. but this is the only workaround I've found that doesn't crash the Page and irritate the user to no end.
I have reported my findings via the SR back to Oracle to do with it what they may... but it looks strongly ,to me, to be an error in the BC4J/JDBC/Database
coordination and passing data between those black boxes. -
Pl/sql block reading reading table data from single point in time
I am trying to figure out whether several cursors within a PL/SQL block are executed from within a Single Point In Time, and thus do not see any updates to tables made by other processes or procedures running at the same time.
The reason I am asking is since I have a block of code making some data extraction, with some initial Sanity Checks before the code executes. However, if some other procedure would be modifying the data in between, then the Sanity Check is invalid. So I am basically trying to figure out if there is some read consistency within a PL/SQL, preventing updates from other processes to be seen.
Anyone having an idea?.
BR,
Cenk"Transaction-Level Read Consistency
Oracle also offers the option of enforcing transaction-level read consistency. When a transaction runs in serializable mode, all data accesses reflect the state of the database as of the time the transaction began. *This means that the data seen by all queries within the same transaction is consistent with respect to a single point in time, except that queries made by a serializable transaction do see changes made by the transaction itself*. Transaction-level read consistency produces repeatable reads and does not expose a query to phantoms."
http://www.oracle.com/pls/db102/search?remark=quick_search&word=read+consistency&tab_id=&format=ranked -
Creating tables in pl/sql block
I have the following piece of code that I execute in sqlplusw as @c:\process.sql
On running @c:\process.sql, an input is provided as prompted. There is a
declare and begin that processes some code. What I am looking for is -- Is there
a way that I can check the all_tables view for the following 3 tables :
TABLE1, TABLE2, TABLE3. Only on finding these tables, this
anonymous sql (that is inside starting from declare ... should execute).
If these tables are not found, I want to attempt creating the tables. If the attempt
was successful, then process. If creating tables attempt fails, exit with a dbms_output.put_line message and don't process
anything....
Can this be done ? If so, any hints would be great.....
Thanks
ACCEPT input_ssn prompt 'Enter SSN :'
SET feedback off
SET serveroutput on
SET echo off
SET term off
SET heading off
SET pagesize 0
SET linesize 10000
SET verify off
undefne sdate input_ssn
COL sdate new_value sdate
COL input_ssn new_value input_ssn
SELECT TO_CHAR (SYSDATE, 'YYYYMMDD') sdate
FROM DUAL;
SPOOL C:\SCRUB_DATA_&&sdate._&&input_ssn..TXT
SELECT 'REPORT GENERATED ON : ' || SYSDATE
FROM DUAL;
ALTER TRIGGER TRIG1 DISABLE;
DECLARE
BEGIN
FOR i IN .........
LOOP
END LOOP;
BEGIN
SELECT ..........
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...........
FOR i IN .....
LOOP
UPDATE ....
BEGIN
SELECT ...
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...
BEGIN
SELECT ....
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
ecode := SQLCODE;
emesg := SQLERRM;
DBMS_OUTPUT.put_line ('Error code is : '||' - '|| ecode);
DBMS_OUTPUT.put_line ('Error message is :' || ' - ' || emesg);
END;
COMMIT ;
ALTER TRIGGER TRIG1 ENABLE;
SET term on
SET HEADING on
SELECT 'Processing complete for ' || '&&input_ssn'
FROM DUAL;
SPOOL off;
SET verify on
SET feedback on
----------------------------------------------------------This is what I am doing :
ACCEPT input_ssn prompt 'Enter SSN :'
SET feedback on
SET serveroutput on
SET echo on
SET term on
SET heading on
SET pagesize 0
SET linesize 10000
SET verify on
undefne sdate input_ssn
COL sdate new_value sdate
COL input_ssn new_value input_ssn
SELECT TO_CHAR (SYSDATE, 'YYYYMMDD') sdate
FROM DUAL;
SPOOL C:\TEMP_DATA_&&sdate._&&input_ssn..TXT
ALTER TRIGGER TRIG1 DISABLE;
DECLARE
v_postal cheque.postal%TYPE;
v_count NUMBER;
l_tabexist NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('HELLO THERE');
BEGIN
DBMS_OUTPUT.PUT_LINE('HI THERE');
SELECT 1 INTO l_tabexist FROM all_tables
WHERE table_name = 'TABLE1_TEMP' AND owner='HARPER';
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'CREATE TABLE TABLE1_TEMP AS SELECT * FROM TABLE1 WHERE 1=2';
EXECUTE IMMEDIATE 'ALTER TABLE TABLE1_TEMP ADD(TEMP_STATUS VARCHAR2(1))';
END;
BEGIN
SELECT 1 INTO l_tabexist FROM all_tables
WHERE table_name = 'TABLE2_TEMP' AND owner='HARPER';
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'CREATE TABLE TABLE2_TEMP AS SELECT * FROM TABLE2 WHERE 1=2';
EXECUTE IMMEDIATE 'ALTER TABLE TABLE2_TEMP ADD(TEMP_STATUS VARCHAR2(1))';
END;
BEGIN
<my code that uses TABLE1_TEMP and TABLE2_TEMP supposed to be created above>
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('No Data Found Exception encountered');
END;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.Put_Line('Something bad happened');
RAISE;
END;
COMMIT ;
ALTER TRIGGER TRIG1 ENABLE;
SET term on
SET HEADING on
SPOOL off;
SET verify on
SET feedback on
What is happening here is that until ALTER TRIGGER DISABLE, things are fine.
Then, it tries to process <my code> and cries saying 'Table or view not found'. Finally it enables the trigger back.
It is not even displaying either the 'HELLO THERE' or 'HI THERE' - which I suppose is the first thing it should have done.
Thanks -
Pl/sql block updating orderId, itemID
lol here i am again!
This time its like this:
i have a table (orderId, itemId, CustomerId, productId, quantity, start_date, end_date, oldRef)
here are some of the values:
2477, 1, 201, 111, 1,19-MAR-93,14-APR-93
2477,2,201,112,1,19-MAR-93,14-APR-93
2478,1,201,113,1,19-MAR-93,14-APR-93
2478,2,201,110,19-Mar-93,14-APR-93
Now as you can see that order_Id is different however order_date and ship_date both match. Now what i want to do is to give them a new orderId, re-arrange itemId if ship_date and order_date match for each customer so the ex above should come out like this:
1, 1, 201, 111, 1,19-MAR-93,14-APR-93
1,2,201,112,1,19-MAR-93,14-APR-93
1,3,201,113,1,19-MAR-93,14-APR-93
1,4,201,110,19-Mar-93,14-APR-93
I have created a pl/sql block. It has a cursor that loops around each row of table. Then it stores orderdate, shipdate and customerId. it also has a itemId variable and orderDate variable. OrderDate variable takes its value from orderId sequence and itemId is just a number that increments itself.
NOW when orderdate,shipdate&customerId are the same, i just update the itemId, if they differ or customer_id changes i get a new order_id, update the variables (orderdate,shipdate,customerid,itemId) but for some reason i dont think it is working!!
DECLARE
cursor c1 is
SELECT
FROM
ph2_item
order by
customer_id,
ship_date,
order_date
for update;
new_order_id number(8,0) := 0;
new_item_id number(4,0) := 1;
temp_odate date := '11-JUN-08';
temp_sdate date:= '11-JUN-08';
temp_cId number(8,0) := 1;
BEGIN
FOR rec in c1 LOOP
IF rec.customer_id = temp_cId THEN
IF (rec.order_date <> temp_odate OR
rec.ship_date <> temp_sdate) THEN
new_item_id:= 1;
SELECT orderid.nextVal into new_order_id from dual;
temp_odate :=rec.order_date;
temp_sdate :=rec.ship_date;
END IF;
ELSE
new_item_id:= 1;
SELECT orderid.nextVal into new_order_id from dual;
temp_cid := rec.customer_id;
temp_odate :=rec.order_date;
temp_sdate :=rec.ship_date;
END IF;
update ph2_item
set order_id = new_order_id, item_id = new_item_id
where current of c1;
new_item_id := new_item_id + 1;
END LOOP;
END;
commit;PS> this is not a real life database and just a college assignment!
just corrected a mistake in one of the example code i posted
Message was edited by:
user646562well it does seem to give the right results ie. orderId is changed and itemId is rearranged! however the college has an online marker and when i try to submit the code, it says that the max(order_id) of the resulting table (ph2_item) is wrong, the sum(item_id) is wrong and the no of distinct orders is wrong.. this means i am either consolidating orders whne i shouldnt, and this in turns make my item_id wrong..
also there is one more criteria i should have mentioned but i forgot and that is even if the order_date and ship_date is the same as another order, we will only consolidate them if the customer in question has multiple sites.
here is the updated pl/sql block taking into account this criteria (using if/else statement)
DECLARE
cursor c1 is
SELECT
FROM
ph2_item
order by
order_date,
customer_id
for update;
new_order_id number(8,0) := 0;
new_item_id number(4,0) := 1;
temp_odate date := '11-JUN-08';
temp_sdate date:= '11-JUN-08';
temp_cId number(8,0) := 1;
totalSites number(2,0);
BEGIN
FOR rec in c1 LOOP
select site_count into totalsites from customer_sites where customer_id = rec.customer_id;
--dbms_output.put_line(rec.customer_id ||' ' || totalsites);
if totalsites > 1 THEN
IF rec.customer_id = temp_cId THEN
IF (rec.ship_date <> temp_sdate AND rec.order_date <> temp_odate) AND rec.ship_date is null THEN
new_item_id:= 1;
SELECT orderid.nextVal into new_order_id from dual;
temp_odate :=rec.order_date;
--temp_sdate :=rec.ship_date;
END IF;
ELSE
new_item_id:= 1;
SELECT orderid.nextVal into new_order_id from dual;
temp_cid := rec.customer_id;
temp_odate :=rec.order_date;
--temp_sdate :=rec.ship_date;
END IF;
ELSE
new_item_id:= 1;
SELECT orderid.nextVal into new_order_id from dual;
temp_cid := rec.customer_id;
temp_odate :=rec.order_date;
--temp_sdate :=rec.ship_date;
END IF;
update ph2_item
set order_id = new_order_id, item_id = new_item_id
where current of c1;
new_item_id := new_item_id + 1;
END LOOP;
END; -
PL/SQL block to populate a table
Hello Gurus,
Need help to write a pl/sql block as per below:
1. Write a PL/SQL block which will populate the RESULTS table as described below. Consider performance implications (specifically where would you commit the queries) as we are dealing with millions of records.
The PL/SQL will:
- insert into the RESULTS table each customer id, and the number of unique products purchased by that customer.
- update the recently_purchased column of the customer table to 'Y' (yes if they have purchased a product in the last 12 months) or 'N' (if they have not purchased a product in the last 12 months).
Listed below are the tables & definitions:
table: CUSTOMER
columns:
customer_id NUMBER,
customer_name VARCHAR2(100),
recently_purchased VARCHAR2(1) -- 'Y' or 'N'
table: CUST_PRODUCTS
columns:
product_id NUMBER,
customer_id NUMBER,
date_purchased DATE
table: RESULTS
columns: customer_id NUMBER, product_count NUMBER
Thanks a lot..Hi Guys,
I've tried this to my best but I feel like something's definately wrong with my update statement.
Please help..
--create customer table
create table customer (
customer_id number(6),
customer_name varchar2(100),
recently_purchased varchar2(1));
-- describe to see if it is created as required
desc customer
--populate customer table with random values
Begin
For i in 1..20
Loop
Insert into customer(customer_id,customer_name,recently_purchased)
values(i, dbms_random.string('U',5),'N');
If mod(i, 100000) = 0 then
Commit;
End if;
End loop;
End;
--create cust_products table
create table cust_products
(product_id number (6),
customer_id number(6),
date_purchased date);
--describe to see if table is created as required
desc cust_products
--populate cust_products with custome_id 1 to 10 and dates
Begin
For i in 1..20
Loop
Insert into cust_products
values(dbms_random.value(555,999),i,add_months('04-Nov-08',i));
If mod(i, 100000) = 0 then
Commit;
End if;
End loop;
End;
select * from cust_products
--update customer table as required
Begin
For i in 1..10
Loop
update customer set recently_purchased = 'Y';
commit;
update customer C set recently_purchased = 'N' where exists (select date_purchased from cust_products P where C.customer_id = P.customer_id );
commit;
End loop;
End;
--Insert into results table
select customer_id,count(product_id)
from cust_products
group by customer_id
Edited by: user497841 on Feb 4, 2010 2:12 PM -
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 -
Update Statement(with Case) in PL/SQL Block
Can we use Oracle case syntax (In a Update SQL)in a PL/SQL Block .
UPDATE table_name a
SET a.colum1 =
case when a.col2 IN (SELECT col1
FROM table_name1 b )
then 'Y'
else 'N'
end
It throws me an Error of code PLS-00103(This error message is from the parser. It found a token (language element) that is inappropriate in this context.)
Is there any alternative...
Thanx in Advance
nullAlas, PL/SQL has own SQL parser, and this parser dosn't know about CASE expressions (at least, it's true up to Oracle 8.1.7).
Try to use DECODE instead, something like
UPDATE table_name a
SET a.colum1 =
SELECT decode(count(*),0,'N','Y)
FROM table_name1 b
WHERE b.col1=a.colum1 -
Write an UPdate statement using the logic used in PL/SQL block (oracle 10g)
Hi All,
I have written the following PL/SQL block. I want to write an UPDATE statement using the logic used in the following PL/SQL block. can any one please help me out in this regards.
DECLARE
v_hoov_fag gor_gold_post.hoov_flg%TYPE;
v_b49n gor_gold_post.b49n%TYPE;
CURSOR c
IS
SELECT bs_id, loyalty_date, loyalty_period, contract_date
FROM gor_gold_post
WHERE tariff_code IN (169, 135, 136);
BEGIN
FOR rec IN c
LOOP
IF (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE) < 304
OR ( TRUNC ( ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE
) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
THEN
v_hoov_flg := 1;
ELSE
v_hoover_flag := 99;
END IF;
IF (TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE) < 121.6
OR ( TRUNC ( ADD_MONTHS (rec.loyalty_date, rec.loyalty_period)
- SYSDATE
) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2
THEN
v_b49n := 1;
ELSE
v_b49n := 99;
END IF;
UPDATE gor_gold_post
SET hoov_flg = v_hoov_flg,
b49n = v_b49n
WHERE bs_id = rec.bs_id AND tariff_code IN (169, 135, 136);
COMMIT;
END LOOP;
END;Thank you,Using case statement.
UPDATE gor_gold_post
SET hoov_flag = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 304
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END,
b49n = CASE WHEN TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) < 121.6
OR
(TRUNC (ADD_MONTHS (rec.loyalty_date, rec.loyalty_period) - SYSDATE) IS NULL
AND (SYSDATE - TO_DATE (rec.contract_date, 'YYYYMMDD')) > 91.2)
THEN 1
ELSE 99
END
WHERE tariff_code IN (169, 135, 136);Note: Code not tested. -
How to convert pl/sql block into single update statement
Dear all gurus,
I have pl/sql block mention below, Can I convert this pl/sql block to single update statement if possible?
If not how to optimize this block?
Pleaese suggest.
thanks in advance.
Vijay
DECLARE
CURSOR vt_mlr_cursor IS Select master_key, user4 from vt_mlr Where USER4 is not null;
USERFIELD VARCHAR2(100);
C1 VARCHAR2(3); /* this will return location of first space = 12 */
C2 VARCHAR2(3); /* this will return location of second space = 20 */
C3 VARCHAR2(3); /* this will return location of third space = 28 */
C4 VARCHAR2(3); /* this will return location of forth space = 35 */
Field1 VARCHAR2(40); /* this will return FTMYFLXA04W */
Field2 VARCHAR2(10); /* this will return VPI0043 */
Field3 VARCHAR2(10); /* this will return VCI0184 */
Field4 VARCHAR2(10); /* this will return 005 */
Field5 VARCHAR2(10); /* this will return 00001 */
Field_2_n_3 VARCHAR2(25);
key VARCHAR2(10);
BEGIN
FOR vt_mlr_record IN vt_mlr_cursor
LOOP
key := vt_mlr_record.master_key;
USERFIELD := vt_mlr_record.user4;
C1 := INSTR(vt_mlr_record.user4,' ',1,1); /* this will return location of first space = 12 */
C2 := INSTR(vt_mlr_record.user4,' ',1,2); /* this will return location of second space = 20 */
C3 := INSTR(vt_mlr_record.user4,' ',1,3); /* this will return location of third space = 28 */
C4 := INSTR(vt_mlr_record.user4,' ',1,4); /* this will return location of forth space = 35 */
Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1); /* this will return FTMYFLXA04W */
Field2 := SUBSTR(vt_mlr_record.user4,C1+4,C2-C1-4); /* this will return VPI0043 */
Field3 := SUBSTR(vt_mlr_record.user4,C2+4,C3-C2-4); /* this will return VCI0184 */
Field4 := SUBSTR(vt_mlr_record.user4,C3+4,C4-C3-4); /* this will return 005 */
Field5 := SUBSTR(vt_mlr_record.user4,C4+4,LENGTH(vt_mlr_record.user4)-C4-3); /* this will return 00001 */
Field_2_n_3 := Field2 || '/' || Field3;
/*DBMS_OUTPUT.PUT_LINE ('Current key is: ' || vt_mlr_record.master_key);*/
UPDATE vt_mlr
SET
aggregator_clli = Field1,
aggregator_vpi_vci = Field_2_n_3,
aggregator_slot = Field4,
aggregator_port = Field5
WHERE
master_key = vt_mlr_record.master_key;
END LOOP;
END;
/Hi Vijay,
Here's something to start with, you should be able to complete it.
First, combine your select and update statements:
update vt_mlr
set aggregator_clli = field1
,aggregator_vpi_vci = field_2_n_3
,aggregator_slot = field4
,aggregator_port = field5
where user4 is not null;Then put these two
C1 := INSTR(vt_mlr_record.user4,' ',1,1);
Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1);into
Field1 := SUBSTR(vt_mlr_record.user4,1,INSTR(vt_mlr_record.user4,' ',1,1) -1);And put it into the update statement, removing reference to record
(I have also removed default values for position and occurrence in instr function):
update vt_mlr
set aggregator_clli = substr(user4, 1, instr(user4,' ') - 1)
,aggregator_vpi_vci = field_2_n_3
,aggregator_slot = field4
,aggregator_port = field5
where user4 is not null; I think you can do the rest from here ;-)
Regards
Peter -
How to update PL/SQL block/Specs in Repository without cut/paste ?
(cross-posted in METALINK form also)
Hello,
Question: How to quickly update PL/SQL block/specs in a package
Repository Object Browser? (without cut/paste)
Tools: Designer 9i, ROB 9.0.2.6
Detailed description of a problem:
-- there is no good pl/sql IDE working with ROB
(JDeveloper can not work with NOT PRIVATE repository workspace)
-- I use Toad and develop/generate pl/sql object
directly in database.
-- I have to synchronize my work with repository as often
as possible the following way (we do not use read-server model
because afraid of getting 1000s of atomik func and proc):
---- navigate to the pl/sql package
---- select properties
---- click on pl/sql block - get old code in editor
---- copy all new code from Toad into editor
---- remove CREATE OR REPLACE and last line
---- save
---- do the same with specifications
I am looking for some way to do this with some script or
one-button click...
For example, for text files it is possible to use command line
Repository Tool. But I did not found the possibility to make
a script like this:
checkout
update workarea/container/plsql_definition/package_name/body....
.....with new_package_body.txt
checkin
Thanks in advance for any help/advice,
Alex V.Hi Alex,
I just had an "Ah! I see!" moment. I now understand why you're having trouble and I can explain things so you can move on... I hope!
First it's important to understand that Oracle SCM is designed to support versioning of both files and Oracle Designer objects. Designer objects are stored as rows in specially structured tables that support that specific product. When you look at PL/SQL definitions in the RON you're looking at Designer definitions - not files. As I mentioned before, these are not the definitions of 'real' PL/SQL objects in the data dictionary, but definitions used by Designer (from which the real things can be generated - but that's another story).
If you're using TOAD you should probably avoid accessing the Designer objects. You need to work with files.
Here's a suggestion for a sequence of operations:
- In the RON check out & download the file (e.g. mypkg.plb)
- In TOAD load the package (from DB, or downloaded file), edit, update package in DB
- In TOAD save as mypkg.plb (overwriting the downloaded copy)
- IN RON upload mypkg.plb and check in
If you've not stored the file in Oracle SCM yet, jsut omit the first step.
You could even automate this to an extent using SQL to query the data dictionary views (e.g. USER_SOURCE) after making changes to get the code and edit/overwrite the file contents that way.
Does this help at all?
Keith.
Maybe you are looking for
-
I updated to Yosemite while I was overseas and didn't have strong enough internet to do a Time Machine backup (it took hours to get Yosemite as it was and now I know that was dumb). Yosemite has made my older Mac almost un-usable. In LAYMAN'S terms,
-
I went to itunes for the 1st time in years and bought music. The updates removed all the songs on my ipod and did not downlaod my purchases. Instead I have a bunch of songs I never heard of. How do I reload my library on my ipod and get rid of the te
-
The Witcher 3 and Cities Skylines doesn't work with GTX 970M (GS 60)
Hello everyone. I don't know since when but everytime I try to play those games the screen is completely black but the sound works. If I try to use the integrated graphic card both of them work but if I use the dedicated card doesn't. I rollback the
-
Change where clause filter based on prompt?
Hi, I am trying to change my where clause filter based on a prompt selected. What I want to do logically looks like this - although it doesn't work as it is not valid case statement syntax: select * from table t where t.calc_result_info_key in (case
-
There is a standard functionality in crm 7.0 - export to Excel of search results. Export to Excel doesn't work on some client computers. Error of coding to excel document. Client computers: 1.WinXP SP3 2. MS Excel 2003 (11.8169.8172) SP3 3. IE 7.0.57