Insert and update by the select statement
Hi allHow can I insert and update in an oracle 10g database table
by a select statement. do not merge.
Florian wrote:
Hi all
How can I insert and update in an oracle 10g database table
by a select statement. do not merge.
>
How can I insert and update in a table of database oracle 10g via a select statement. do not merge.
Do you mean by using subqueries?
Something like
insert into whatever
...select statement
update whatever
set (column, column) = (select column, column ...)
There is a lot of information on this topic in the online documentation
Tags: Database
Similar Questions
-
Mr President
Jdev worm is 12.2.1
How to modify and update a line later was inserted and updated in the doDML() method?
I added two rows in my table a method of action-listener in bean managed and secondly with operation doDML() as below.
Method 1-first row in managed bean
public void addNewPurchaseVoucher(ActionEvent actionEvent) { // Add event code here... BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("VoucherView1Iterator"); RowSetIterator rsi = dciter.getRowSetIterator(); Row lastRow = rsi.last(); int lastRowIndex = rsi.getRangeIndexOf(lastRow); Row newRow = rsi.createRow(); newRow.setNewRowState(Row.STATUS_NEW); rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow); rsi.setCurrentRow(newRow); BindingContainer bindings1 = BindingContext.getCurrent().getCurrentBindingsEntry(); DCIteratorBinding dciter1 = (DCIteratorBinding) bindings1.get("VdetView1Iterator"); RowSetIterator rsi1 = dciter1.getRowSetIterator(); Row lastRow1 = rsi1.last(); int lastRowIndex1 = rsi1.getRangeIndexOf(lastRow1); Row newRow1 = rsi1.createRow(); newRow1.setNewRowState(Row.STATUS_NEW); rsi1.insertRowAtRangeIndex(lastRowIndex1 +1, newRow1); rsi1.setCurrentRow(newRow1); }
Method of doDML() of line 2 seconds in the entityImpl class
protected void doDML(int operation, TransactionEvent e) { setAmount(getPurqty().multiply(getUnitpurprice())); if (operation == DML_INSERT) { insertSecondRowInDatabase(getVid(),getLineitem(),getDebitst(), (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100)); } if(operation == DML_UPDATE) { updateSecondRowInDatabase(getVid(),getLineitem(),getDebitst(), (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100)); } super.doDML(operation, e); } private void insertSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4) { PreparedStatement stat = null; try { String sql = "Insert into vdet (VID,LINEITEM,DEBITST,AMOUNT) values ('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "')"; System.out.println("sql= " + sql); stat = getDBTransaction().createPreparedStatement(sql, 1); stat.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { stat.close(); } catch (Exception e) { e.printStackTrace(); } } } private void updateSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4) { PreparedStatement stat = null; try { String sql = "update vdet set vid='"+ value1+"',lineitem='"+ value2+"',DEBITST='" + value3 + "', AMOUNT='" + value4 + "' where VID='" + VID + "'"; System.out.println("sql= " + sql); stat = getDBTransaction().createPreparedStatement(sql, 1); stat.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { stat.close(); } catch (Exception e) { e.printStackTrace(); } } }
Now the problem is that when later I change the quantity and price of the first line isn't updated but second row, because I used the command
<af:button actionListener="#{bindings.Commit.execute}" text="Commit"
This button update the first line added by bean managed, but the second row remains unchanged.
Please help how to update the two lines with the same button or something else.
Concerning
DML_UPDATE will call only if there is some change data attributes.
I guess that the update statement is false because vid looks like a primary key for the table, then, how update you the primary key of the update statement and how the update condition statement where the vid = '0'
I assume the update statement should look like:
private void updateSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4) { PreparedStatement stat = null; try { String sql = "update vdet set lineitem='" + value2 + "',DEBITST='" + value3 + "', AMOUNT='" + value4 + "' where VID='" + value1 + "'"; System.out.println("sql= " + sql); stat = getDBTransaction().createPreparedStatement(sql, 1); stat.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { stat.close(); } catch (Exception e) { e.printStackTrace(); } } }
-
command evaluated Pivot and UnPivot in the select statement
My research assessing the order of the select statement is below.
My question is Where clause Pivot and UnPivot clause ?1 from 2 where (Join condition) 3 start with 4 connect by 5 where (filter of rows) 6 group by 7 having 8 model 9 select 10 order by
http://download.Oracle.com/docs/CD/E16338_01/server.112/e10592/statements_10002.htmWell the pivot is applied to a single table or an inline or a view - so it's going to be like any other table or view in the list - it will be first
select b.BUSINESS_OBJECT_CATEGORY_DESCR, a.c, a.d from (select PAY_METHOD_TYPE_CODE, BUSINESS_OBJECT_CATEGORY_CODE from target_odi.business_object_pay_methods) pivot (count(PAY_METHOD_TYPE_CODE) for PAY_METHOD_TYPE_CODE in ('D' as d, 'C' as c)) a , target_odi.business_object_categories b where a.BUSINESS_OBJECT_CATEGORY_CODE = b.BUSINESS_OBJECT_CATEGORY_CODE
So for the SQL above the pivot is first assessed before the join between A and B.
-
I feel as if I'm fighting my way around a paper bag trying to insert a record. I have recently converted from MySQL for PDP, which cannot be applied. I'm not trying to write routines to update data and started with insert. I tried the example in your PHP Solutions edition two, pp. 361-363, but I can't get a written account.
It is a database, which I supported since the host server using phpMyAdmin. I'm very well display the data on the site, so I guess that my login script is ok. However, nothing I've tried has got a registered insert. I tried to get back to the basics, and it still does not work. This is my current code. Something is wrong with my statement = $sql and I can't identify the problem. Help, please!
If (isset($_POST['insert'])) {}
try {}
create the SQL
$sql = "INSERT INTO Homepage_text (enriched, h_date, h_seq, h_col, p_heading, p_text, h_hide) VALUES ($_POST ['enriched'], $_POST ['h_date'], $_POST ['h_seq'], $_POST ['h_col'], $_POST ['p_heading'], $_POST ['p_text'], $_POST ['h_hide']);"
$sainttim-> execute ($sql);
echo "new record successfully created ';
}
catch (PDOException ($e) exception
{
echo $sql. "< br / > '. $e-> getMessage();
}
}
There are several things wrong with your code:
- You use elements of an associative array within a double quoted string. Which will cause a parse error.
- The values you are trying to insert in the database are for most (if not all) of the text fields. If you use a literal SQL query, text fields must be wrapped in quotes.
- You try to use the method execute() with a literal SQL query. In AOP, execute() only works with a prepared statement. To run a literal SQL query, you must use the exec() method.
- Passing the values in the array $_POST directly in the database without any sort of validation and without escaping quotes or other characters just asking for trouble.
Follow the examples in the book, and use a prepared statement. To address all these issues quickly and easily.
-
Update using the Select statement
I have a requirement of the main table was updated. Here is an example
Example (a) works in PL SQL but does not work in Forms6i.
Example (b) works in PLSQL so in Forms 6i.
I need work example (a) in forms 6i. What is the solution
one)
UPDATE fman_validation_master SET TOT_HRS = TOT_HRS +.
(SELECT SUM (FAV. H TOT_HRS)
OF FMAN_ACTQTY_VALIDATION FAV
WHERE fman_validation_master. = PROJECT: CONTROL. PROJECT AND
fman_validation_master. PROJECT = fav. PROJECT AND
fman_validation_master. ACTIVITY_CODE = FAV. ACTIVITY_CODE
FAV GROUP. PROJECT, FAV. ACTIVITY_CODE
) where of the = project: CONTROL. PROJECT;
(b)
UPDATE fman_validation_master SET TOT_HRS =
(SELECT SUM (FAV. H TOT_HRS)
OF FMAN_ACTQTY_VALIDATION FAV
WHERE fman_validation_master. = PROJECT: CONTROL. PROJECT AND
fman_validation_master. PROJECT = fav. PROJECT AND
fman_validation_master. ACTIVITY_CODE = FAV. ACTIVITY_CODE
FAV GROUP. PROJECT, FAV. ACTIVITY_CODE
) where of the = project: CONTROL. PROJECT;Hello
According to Oracle 8.1, you can say:
UPDATE table_x SET column_a = exp;
where exp is any expression, or
UPDATE table_x SET column_a = (ssq);
where ssq is now called a scalar subquery. Oracle 8.1 sometimes allowed scalar subqueries in places where the documentation did not say that they were allowed. The first statement is an example, when you use
tot_hrs + (ssq)
as an expression. It works in SQL * Plus and also in PL/SQL, but (apparently) not in the forms.
Re-write your UPDATE statement so that the scalar subquery appears in itself to the right of the sign =, like this:
UPDATE fman_validation_master SET tot_hrs = ( SELECT fman_validation_master.tot_hrs + SUM (fav.tot_hrs) FROM fman_actqty_validation fav WHERE fman_validation_master.project = fav.project AND fman_validation_master.activity_code = fav.activity_code ) WHERE project = :control.project;
In other words, just move the original fman_validation_master.tot_hrs (to which you add the SUM) of the main request in the subquery.
-
Insert and update in a single statement
I want to update a table with data from another table. the key field is empid.
for example
I want to update the table empmst with data in increments
If the matching empid exist in the empmst table, I want to update the values.
If this isn't the case, I want to insert the line with the data in the table by increments
I use oracle 10g
Cases in the sample
================
create the table empmst as
(
Select 1 empid, salary 0, 300 incrementamnt of all the double union
Select 3, 0, 300 Union double all the
Select 5, 0, 300, double
);
create table like slices
(
Select 1 empid, salary 10000, incrementamnt null in all the double union
Select double union 2, 10000, 400
Select 3, 43000, union null double all the
Select 4, 34000, union null double all the
Select 5, 50000, 500 double
);
Help, please...
Hello
Krishna Devi wrote:
I want to update a table with data from another table. the key field is empid.
for example
I want to update the table empmst with data in increments
If the matching empid exist in the empmst table, I want to update the values.
If this isn't the case, I want to insert the line with the data in the table by increments
That's exactly what FUSION.
Here's one way:
MERGE IN e empmst
USING increment i
WE (e.empid = i.empid)
WHEN NOT MATCHED THEN INSERT
(e.empid, e.salary, e.incrementamnt)
VALUES (i.empid, i.salary, i.incrementamnt)
WHEN MATCHED THEN UPDATE
SET i.salary = e.salary
e.incrementamnt = i.incrementamnt,
;
Thanks for posting your sample data.
Don't forget to post the desired results of these data, in other words, the content of empmst once this task is completed. For example:
EMPID SALARY INCREMENTAMNT
---------- ---------- -------------
1 10000
2 10000 400
3 43000
4 34000
5 50000 500
-
FORALL using insert and update
Hello
I want to use FORALL for insert and update at the same time in a single FORALL...
It's like...
FORALL INDX IN 1... record. Count
insert into Table values (record (i)); - Table is updated with some values in the column
Update Table
Set table.col10 = (select val table11 where table11.column = record.count (i))
-update the Table by taking the value of some other column table... passing the parameter each time...
Help, please...Refer to this
http://docs.Oracle.com/CD/B19306_01/AppDev.102/b14261/forall_statement.htm
But why PL SQL?
You can do this with the Merge statement
http://docs.Oracle.com/CD/B19306_01/server.102/b14200/statements_9016.htm
Mezaber
-
Add error causing senior in 4.2.1 when inserting and updating same time
Hi all
I have problems with the top to add a line in a table.
There is already a thread here on how to add the line above in table form in version 4.0.
We have recently upgraded to version 4.2.1 Apex.
Since then we have question while inserting a new line and update an existing line at the same time, and then click Save button causing the error below:
Current version of the data in the database has changed since the user initiated the update process. version of current line identifier = "xxxxxx" line application version identifier = "xxxxxx".
But insert a new record and update an existing record works well separately with an error.
Here's the code to add the line at the top of page header HTML<script language="javascript" type="text/javascript"> function addRowTop() { apex.widget.tabular.addRow(); apex.jQuery(apex.widget.tabular.gTabForm).find(".highlight-row").last() .insertBefore(apex.jQuery(apex.widget.tabular.gTabForm). find(".highlight-row").first()); } </script>
If I use by default addRow so absolutely no problem to insert and update at the same time.
Here is the example of work in the workspace apex.
Looks like a bug to me.
Can any of the Oracle team please see this and let us know if it needs a patch.
Thank you
REDA
Not sure that I consider this a bug since you are somehow hacking the default functionality of the APEX. Maybe you could add a feature request 'Add Top line' to https://apex.oracle.com/vote
It seems that you hit some enhancments to safety that have been made to the tabular forms. You should be able to work around it by putting the new lines to the bottom of the form before submitting the page.
Create a dynamic action based on the click of the submit button.
Event: click on
Selection type: button
Button: SUBMIT (Submit)
Condition: - no requirement.
Add real action to run the JavaScript Code:
Action: run the JavaScript Code
Fire when the result of the event is: true
Fire on Page load: [disabled]
Code:
apex.jQuery(apex.widget.tabular.gTabForm).find("input[value=''][name='frowid']").closest(".highlight-row") .insertAfter(apex.jQuery(apex.widget.tabular.gTabForm).find(".highlight-row").last());
Add a real action to send the page:
Action: send the Page
E: Nam request/buttonSUBMIT
-Jeff
-
INSERT and UPDATE audit generating more lines expected in $ AUD
Environment:
Oracle 11.2.0.3 EE on Solaris
I had a request for verification of the INSERT and UPDATE on the activities of all the tables in a particular schema. It was in anticipation of a request that will live and the owner wanted to see a 'typical' of some test users activity.
Here are the steps I took:
I also "audit_sys_operations = TRUE' so I know I'll take some SYS audit data in $ AUD as well, but I can ask around those."alter system set audit_trail=DB_EXTENDED scope=spfile; Bounce the instance audit INSERT table, UPDATE table by USERX;
My question is that I see several connections from the application server with "LOGIN" and "LOGOUT" actions and I don't know why they are appearing in the table of AUD $.
Is it because I have auditing enabled for inserts and updates on all THE tables for USERX and opening operations and logoff do I/O in tables that are not owned by USERX under logon logoff procedure?
I'm a newbie audit and the docs I read not answered this question.
I just found an article on the value of 'SESSION_REC' of ACTION_NAME and I need to change my check to "by access. I'll change that and see what happens, but it shouldn't change my question.
Thanks much for any help!
-garyHello
I have the SYS activities audited but I never said anything about the session auditing for this particular user.
"audit session;" check all successful and failed connections to and disconnections of the database, regardless of the user, by session
Is there a way to confirm what has been turned on for auditing?
You can check with the following query
Select * from dba_stmt_audit_opts;
Select * from dba_priv_audit_opts;You can also check out the link below for more deatails
http://psoug.org/reference/auditing.html -
Create triggers in the table, sequence, insert and update with "model"?
It must be of rtfm, trial and error thing but you wanted to ask, is it possible to have models or similar automation for the following scenario:
1.), I add the table to the logic model
2.) Using glossary I transform a relational model that was recovered / synchronized with the data dictionary
3.) then I have the new table to add
-but
I would then have auto-DDL of to be synchronized to database:
-create sequence for the id column
-create table
-create indexes for the id column pk
-Create triggers for insert and update
-l' idea is to have db_created_dt and db_modified_dt defined in the table, so that each table has them to the fields of record etc.
-activate the triggers
Each of them following the same naming convention.
Similarity with approx. generator Apex workshop utils sql create table of the copy paste "excel" that creates 'id' - column + sequence and insert the trigger.
rgrds Paavo
Hi Paavo,
most of the steps can be made in one or other way
-create sequence for the id column
-create table
-create indexes for the id column pk
If you want to start in the logic model and you don't want to have the ID column in the logic model and select 'Create the surrogate key' checkbox in the dialog entity - you will get an identity column in the relational model and the version of database and settings in ' preferences > Data Modeler > model > physics > Oracle "you can set the sequence generation and the trigger for taking in load.
fields of record defined in the table, so that each table has them
You can add the same set of columns in all tables with the transformation script 'model of Table... ».
You can also look here Oracle SQL Developer Data Modeler 4.1 user - defined DDL generation using transformation scripts
to see how to grant your DDL generation using the transformation script. DM comes with example to generate separate tables of logging and triggers. You can create your build script of triggers that support logging in these common columns.
Philippe
-
validation for each 1,000 records to be inserted in the select statement
Hi, I have the following INSERTION in the SELECT statement.
The SELECT statement (who joined) data fo about 6 crores. I need to insert this data into another table.
Please suggest me the best way to do it.
I use the INSERT in the SELECT statement, but I want to use the statement commit for each 1,000 records.
How can I do this...
Thank youinsert into emp_dept_master select e.ename ,d.dname ,e.empno ,e.empno ,e.sal from emp e , dept d where e.deptno = d.deptno ------ how to use commit for every 1000 records .
Method 4 is the best
You could combine method 3 and 1 (without dynamic SQL)
Method 2 is the less optimal solution from the list.
-
Insert and update server behaviors in the same form
I have a php form that is inserted into a table and then update another table. I have the form of inserting the record first and then I want to update the other table. I'm starting to learn and understand PHP, but I don't know how to have the update function to run after that it inserts the records. I guess that's something like if you insert this disc, then update this record and then go to the redirect page. I know this goes to redirect page after it inserts the record, but I don't know how to tell him not to go to the $insertGoTo. I want him to run the following update function and then go to the $insertGoTo and not the $updateGoTo. Thanks in advance for any help.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO employee (CompId, empfirstname, empmiddleint, emplastname, EmpType, EmpStatus) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['CompId'], "int"), GetSQLValueString($_POST['empfirstname'], "text"), GetSQLValueString($_POST['empmiddleint'], "text"), GetSQLValueString($_POST['emplastname'], "text"), GetSQLValueString($_POST['EmpType'], "text"), GetSQLValueString($_POST['EmpStatus'], "text")); mysql_select_db($database_dotweb, $dotweb); $Result1 = mysql_query($insertSQL, $dotweb) or die(mysql_error()); $insertGoTo = "Roster.php?CompId=" . $_POST['CompId'] . ""; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE company SET CompanyType=%s WHERE CompId=%s", GetSQLValueString($_POST['CompanyType'], "text"), GetSQLValueString($_POST['CompId'], "int")); mysql_select_db($database_dotweb, $dotweb); $Result1 = mysql_query($updateSQL, $dotweb) or die(mysql_error()); $updateGoTo = "purchases.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); }
PHP code is executed from top down and is controlled by the conditional statements ('if' blocks). To achieve what you want, you need to combine the conditional statements that control the insert and update server behaviors and to move the redirect to the end of the code. Amend as follows:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO employee (CompId, empfirstname, empmiddleint, emplastname, EmpType, EmpStatus) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['CompId'], "int"), GetSQLValueString($_POST['empfirstname'], "text"), GetSQLValueString($_POST['empmiddleint'], "text"), GetSQLValueString($_POST['emplastname'], "text"), GetSQLValueString($_POST['EmpType'], "text"), GetSQLValueString($_POST['EmpStatus'], "text")); mysql_select_db($database_dotweb, $dotweb); $Result1 = mysql_query($insertSQL, $dotweb) or die(mysql_error()); $updateSQL = sprintf("UPDATE company SET CompanyType=%s WHERE CompId=%s", GetSQLValueString($_POST['CompanyType'], "text"), GetSQLValueString($_POST['CompId'], "int")); mysql_select_db($database_dotweb, $dotweb); $Result1 = mysql_query($updateSQL, $dotweb) or die(mysql_error()); $insertGoTo = "Roster.php?CompId=" . $_POST['CompId'] . ""; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); }
-
Update using a function in the select statement
Hello
Is it possible to do the follwing.
I tabele and a custom function, the custome service will update the column (amount) of the table based on the value of going through the function of the select statement.
SELECT id, stock, where an id = get_update (id);
Now
Get_update function will return the same id I'm passing and update the column amount to a value in the
table a.
When I run the satament selection I have the updated data in the column amount in my first executtion, but if execute the same statement, again, I see the changes reflected. is it possible to get data updates to the first performance himself.
the function is of type PRAGMA AUTONOMOUS_TRANSACTION
ConcerningIndeed a strange requirement and probably not the way to go in a production environment. But anyway is a way to achieve your goal
SQL> create table a as select 12 id, 500 amount from dual union all select 13 id, 600 amount from dual / Table created. SQL> create or replace type a_typ as object (id number, amount number) / Type created. SQL> create or replace function get_id (pid number) return a_typ is pragma autonomous_transaction; l_a_typ a_typ := a_typ (null, null); begin update a set amount = 800 where id = pid returning id, amount into l_a_typ.id, l_a_typ.amount; commit; return l_a_typ; end get_id; / Function created. SQL> select id, d.a_typ.amount amount from a, (select get_id (13) a_typ from dual) d where id = d.a_typ.id / ID AMOUNT ---------- ---------- 13 800 1 row selected.
-
Im trying to buy photoshop but it keeps saying that its not available in my area. I am in the United States and in my area gets bad! I even updated to the United States, but it is not record the change!
Hi Mariam,
It seems that your ID Adobe was initially registered in Pakistan due to which it is not allowing you to make purchases in the United States.
You can create a new Adobe ID, register in the United States and then it should allow you to make a purchase.
Let us know if it works or not.
Thank you
Yann Arora
-
Problem with instructions to update within the if statement
Hello
I have the following PL/SQL script. It was written in a way so it can be run several times, without worrying about if she has previously run means that it should only perform the update and edit, if it has not already been done.
DECLARE
CNT NUMBER;
BEGIN
-Rename column
COUNT (*) of SELECT INTO cnt FROM user_tab_columns WHERE TABLE_NAME = 'WELL_TEST_DATA_QUERIES' AND COLUMN_NAME = 'PRIMARY ';
IF (cnt = 1)
THEN
UPDATE WELL_TEST_DATA_QUERIES
THE PRIMARY VALUE = 0
WHERE PRIMARY = 1;
RUN IMMEDIATELY 'ALTER TABLE WELL_TEST_DATA_QUERIES RENAME COLUMN PRIMARY TO WELL_TEST_TYPE;
END IF;
END;
However, when it is executed several times, it seems to execute the body of the if statement each time, despite the fact that the select statement must return a count of 0 (and I checked that this is the case).
If I change the script and put the UPDATE statement in an EXECUTE IMMEDIATE, it works fine:
DECLARE
CNT NUMBER;
BEGIN
-Rename column
COUNT (*) of SELECT INTO cnt FROM user_tab_columns WHERE TABLE_NAME = 'WELL_TEST_DATA_QUERIES' AND COLUMN_NAME = 'PRIMARY ';
IF (cnt = 1)
THEN
IMMEDIATE EXECUTION
' UPDATE WELL_TEST_DATA_QUERIES
THE PRIMARY VALUE = 0
WHERE PRIMARY = 1';
RUN IMMEDIATELY 'ALTER TABLE WELL_TEST_DATA_QUERIES RENAME COLUMN PRIMARY TO WELL_TEST_TYPE;
END IF;
END;
Can someone give me an indication of what is happening here?
Thank you
Kathrynuser10855910 wrote:
HelloI have the following PL/SQL script. It was written in a way so it can be run several times, without worrying about if she has previously run means that it should only perform the update and edit, if it has not already been done.
Are you referring to getting this:
SQL> create table well_test_data_queries (primary number); Table created. SQL> insert into well_test_data_queries values (1); 1 row created. SQL> commit; Commit complete. SQL> ed Wrote file afiedt.buf 1 DECLARE 2 cnt NUMBER; 3 BEGIN 4 -- Rename column 5 SELECT COUNT(*) INTO cnt FROM user_tab_columns WHERE TABLE_NAME = 'WELL_TEST_DATA_QUERIES' AND COLUMN_NAME = 'PRIMARY'; 6 IF cnt = 1 THEN 7 UPDATE WELL_TEST_DATA_QUERIES 8 SET PRIMARY = 0 9 WHERE PRIMARY = 1; 10 EXECUTE IMMEDIATE 'ALTER TABLE WELL_TEST_DATA_QUERIES RENAME COLUMN PRIMARY TO WELL_TEST_TYPE'; 11 END IF; 12* END; SQL> / PL/SQL procedure successfully completed. SQL> select * from well_test_data_queries; WELL_TEST_TYPE -------------- 0 SQL> DECLARE 2 cnt NUMBER; 3 BEGIN 4 -- Rename column 5 SELECT COUNT(*) INTO cnt FROM user_tab_columns WHERE TABLE_NAME = 'WELL_TEST_DATA_QUERIES' AND COLUMN_NAME = 'PRIMARY'; 6 IF cnt = 1 THEN 7 UPDATE WELL_TEST_DATA_QUERIES 8 SET PRIMARY = 0 9 WHERE PRIMARY = 1; 10 EXECUTE IMMEDIATE 'ALTER TABLE WELL_TEST_DATA_QUERIES RENAME COLUMN PRIMARY TO WELL_TEST_TYPE'; 11 END IF; 12 END; 13 / WHERE PRIMARY = 1; * ERROR at line 9: ORA-06550: line 9, column 11: PL/SQL: ORA-00904: "PRIMARY": invalid identifier ORA-06550: line 7, column 5: PL/SQL: SQL Statement ignored SQL>
The problem is not because the IF statement entered the swiped m the cnt = 1, but because, when the code is compiled the PRIMARY column does not exist. The code should compile properly against the database, and all verified database object references, until the code is actually running.
As you have discovered, when you do the dynamic update to help to run immediately, you will not get this problem, because execute immediate statements are strings that can not be validated at compile time and so the code will compile ok and then run.
Maybe you are looking for
-
session of system update files can be deleted?
It seems to me that ThinkVantage System Update must keep everything that it downloads. I now have on my T60 about 7000 files (2.5 GB) of files under C:\Program Update\sessions of Lenovo. Who doesn't clean up after itself? Can one of these files delet
-
Hi team, I have a question where adding a network printer is successful. I can see the printer in the Device Manager and I can print as well. However, it does not immediately appear under devices and printers and takes a long time to appear. Can some
-
WAG160N exasperating dropouts/reliability
I myself bought a gateway WAG160N after I set up an ADSL service at my home last weekend. I have install the modem to the letter by the installation fast and installed guide the LELA utility to observe the State of the network. The modem has power, w
-
HP Pavilion 20 - preparation auto repair
My HP PAvilion 20 froze on me. I went to restart it and now it shows the HP symbol and it says "preparing auto repair." Then the screen becomes a blank black screen. Is there something I can do?
-
I get the BSOD and have no idea how fix and or repair. I ran a memory test using cd ISO and memory checks very well. Errors seem to be due to Mini090610 - 05.dmp 06/09/2010 19:23:24 IRQL_NOT_LESS_OR_EQUAL 0x0000000A 0 x 00000078 0x0000001b 0x00000001