SQL Update statement
Hi allI have a table with 5 columns Col1, Col2, Col3, Col4, Col5. The requirement for the company is that all four columns Col1 by Col4 must be filled or any of the four columns must be filled.
Any line that does not conform the above rule must be marked as error.
I would like to know how I update the Col5 with 'Error' when 2 rules above does not comply with a statement direct update (sql).
For Ex:
Col1 Col2 Col3 Col4 Col5
Row1 has b c and d
Row2
Row3 a c error
Row4 a b c error
Thank you
More efficient UPDATE would be:
UPDATE your_table
SET col5 = 'Error'
WHERE NOT (
(col1 IS NOT NULL AND col2 IS NOT NULL AND col3 IS NOT NULL AND col4 IS NOT NULL)
OR
(col1 IS NULL AND col2 IS NULL AND col3 IS NULL AND col4 IS NULL)
)
/
Or you can create the check constraint:
ALTER TABLE your_table
ADD CONSTRAINT your_table_CHK1
CHECK(
(col1 IS NOT NULL AND col2 IS NOT NULL AND col3 IS NOT NULL AND col4 IS NOT NULL)
OR
(col1 IS NULL AND col2 IS NULL AND col3 IS NULL AND col4 IS NULL)
)
/
to avoid bad lines in the first place.
SY.
Tags: Database
Similar Questions
-
Updates using the single SQL Update statement.
Hi guys,.
I got an interview... and was not able to answer a question.
In view of the table emp... need to update the salary with the following requirement by using an SQL statement.
1 update salary + 1000 for employees who receive pay between 500 and 1000
2 update salary + 500 for employees who receive wages between 1001 and 1500
The two above the requirement should be made using only a SQL update statement... can someone tell me how to do?update emp set salary = case when salary between 500 and 1000 then salary + 1000 when salary between 1001 and 1500 then salary + 500 end;
Concerning
Arun -
How to convert the next update of FORALL to run the SQL UPDATE statement
I have a FORALL loop for updating a table. It takes too much time. I want to rewrite the code to a direct sql UPDATE. Also of other tips or tricks that can help to run the fastest proc?
Record count: -.CURSOR cur_bst_tm IS SELECT listagg(tm, ' ') WITHIN GROUP(ORDER BY con_addr_id) best_time, con_addr_id FROM (select Trim(Upper(con_addr_id)) con_addr_id, '&' ||decode(Initcap(start_day), 'Monday', 'm', 'Tuesday', 'tu', 'Wednesday', 'w', 'Thursday', 'th', 'Friday', 'f', Initcap(start_day)) ||'=' ||trunc(( ( TO_DATE(start_tm,'HH12:MI:SS PM') - trunc(TO_DATE(start_tm,'HH12:MI:SS PM')) ) * 24 * 60 )) ||',' ||trunc(( ( TO_DATE(end_tm,'HH12:MI:SS PM') - trunc(TO_DATE(end_tm,'HH12:MI:SS PM')) ) * 24 * 60 )) tm FROM (SELECT DISTINCT * FROM ODS_IDL_EDGE_OFFC_BST_TM) WHERE con_addr_id is not null) GROUP BY con_addr_id ORDER BY con_addr_id; TYPE ARRAY IS TABLE OF cur_bst_tm%ROWTYPE; l_data ARRAY; BEGIN OPEN cur_bst_tm; LOOP FETCH cur_bst_tm BULK COLLECT INTO l_data LIMIT 1000; FORALL i IN 1..l_data.COUNT UPDATE ODS_CONTACTS_ADDR tgt SET best_times = l_data(i).best_time, ODW_UPD_BY = 'IDL - MASS MARKET', ODW_UPD_DT = SYSDATE, ODW_UPD_BATCH_ID = '0' WHERE Upper(edge_id) = l_data(i).con_addr_id AND EXISTS (SELECT 1 FROM ods_idl_edge_cont_xref src WHERE tgt.contacts_odw_id = src.contacts_odw_id AND src.pc_flg='Y') ; EXIT WHEN cur_bst_tm%NOTFOUND; END LOOP; CLOSE cur_bst_tm;
Select count (*) from
ODS_IDL_EDGE_OFFC_BST_TM;
140 000
SELECT count (*)
Ods_idl_edge_cont_xref SRC
WHERE src.pc_flg = 'Y';
118 000
SELECT count (*)
OF ODS_CONTACTS_ADDR;
671 925
Version of database 11g.
Execution plan for update:
Operation object name lines cost/output PStart PStop object node bytes
Mode of UPDATE STATEMENT Optimizer = ALL_ROWS 6 K 8120
UPDATE ODW_OWN2. ODS_CONTACTS_ADDR
SEMI 6 K 256 K 8120 HASH JOIN
TABLE ACCESS FULL ODW_OWN2. ODS_CONTACTS_ADDR 6 K 203 K 7181
TABLE ACCESS FULL ODW_OWN2. ODS_IDL_EDGE_CONT_XREF K 118 922 K 938
Edited by: user10566312 May 14, 2012 01:07
-
SQL update statement executed or not?
I have a sql update stmt.
How can I know if the recording has updated or not, without cross-checking records?
Thank youUse cursor attribute % number of LINES:
SQL> begin 2 update emp set sal = sal + 1000; 3 dbms_output.put_line(sql%rowcount || ' rows were updated.'); 4 end; 5 / 14 rows were updated. PL/SQL procedure successfully completed. SQL>
SY.
-
PL/SQL: Update statement
SQL dear Experts,
I'm writing a procedure to execute a simple DML statement. For example below stmt update: I provide COL1 and COL2 as inputs based on the update should run. Can you suggest how this can be implemented?
UPDATE TABLE1 SET COL1=123 WHERE COL2=456;
create or replace procedure test1 (col1 varchar2,col2 varchar2) as v_str varchar2(90); begin v_str := 'update emp set '||col1 ||'= 55 where '||col2 ||'= 7369'; execute immediate v_str; end; DECLARE COL1 VARCHAR2(30); COL2 VARCHAR2(30); BEGIN COL1 := 'SAL'; COL2 := 'EMPNO'; TEST1( COL1 => COL1, COL2 => COL2 ); END;
Is that what you want?
-
I obviously have something messed up with the syntax of the following statement but I can't figure it out... anyone know what im doing wrong?
_db.execute('UPDATE sbItems SET sbs1 = ? WHERE thedate = ?', [td,db]);
sql = 'select * from sbItems where thedate = ?'; rs = _db.execute(sql,[thedate]); if (rs.isValidRow()) { sql = 'UPDATE sbItems SET sbs1 = ? WHERE thedate = ?'; _db.execute(sql, [sbs1,thedate]); } else { alert("Row not Found"); }
Turns out I had a problem with my formatting to survive that was causing the problem, the above code work if someone else happens to search for this... FYI "subsist" is in fact a string and not a date in my table...
-
I have a database in my application, and part of it (obviously) will require the user to update the database with the current information.
There are 24 columns of the table, and I have my update function works almost 100%, except that there are two drop downs, and when the user updates the record individual everything that is selected in the fall of two downs, is applied to all records.
My update statement is like this:
var statement:SQLStatement = new SQLStatement();statement.sqlConnection = connection;statement.text = "UPDATE TABLE SET " + "OneFish=?, " + "TwoFish=?, " + "RedFish=?, " + "BlueFish=?, " + // CONTINUES AS TEXT INPUTS DOWN TO "DropDown1=?, " + "DropDown2=?, " + // FEW MORE TEXT INPUTS THEN "WHERE RECORD_ID=?"; statement.parameters[0] = OneFish.text; statement.parameters[1] = TwoFish.text; statement.parameters[2] = RedFish.text; statement.parameters[3] = BlueFish.text; // CONTINUES AS TEXT INPUTS DOWN TO statement.parameters[17] = DropDown1.selectedItem; statement.parameters[18] = DropDown2.selectedItem; // FEW MORE TEXT INPUTS THEN statement.parameters[23] = FishOption.selectedItem.RECORD_ID; statement.addEventListener(SQLEvent.RESULT, updateWorked); statement.addEventListener(SQLErrorEvent.ERROR, updateFailed); statement.execute();
ALL updates day very well and shown to the a specific RECORD_ID. However, the decline in the bottom change overall.
This does not happen on my service of "addFish". Someone out there have any ideas why this is?
Update: It isn't my SQL. If I close the application and then go back, the changes show correctly. The drop down menus are simply not refreshing properly after the update of the database.
J.Rab!
I literally JUST thought out and sat next to the woman to rejoice with the laptop on my lap! Then the BlackBerry made his small notification and I said out loud, "oh look, it's probably somebody tell me what I did wrong before that I could update!
Had dinner and a record label with a look at it to understand.
To display the resulting data & update fields, I was setting the command prompt from the drop down menus! I went my output and changed function use the selectedItem and success!
I also forgot to include a refreshTheDatabase(); at the end of my updateFunction() function call;
I hit a brick wall with this for several hours this afternoon and I can't believe it was that simple! I should have got up and walked away earlier!
-
Commit to taking a lot of time for the update statement to bulk - 11 GR 2
Hi team,
We have a source table, which is the main table for our application.
When I commit a transaction after update block, it takes long about 2 to 4 minutes.
I don't understand why it takes too long...
Could you please help me on this fix, please...
It's the details on the table,
Total number of records: 35 M record
Validation interval: 500 records / commit
Total scores: 3
total number of columns: 95 - including primary, unique and foreign key columns (all columns will be updated for each update because update from the app online)
Total no of the foreign key columns: 12
Unique key column: 1
Total index: 27 ( including the key index foreign 12 + 1 + 1 index of primary key Unique key index )
example of update statement,
UPDATE DIRECTORY_LISTING_STG SET COLUMN_1 = :VAL_1 . . . COLUMN_94 = :VAL_94 WHERE RECORD_KEY = :P_KEY_VAL;
The table is.
Plan hash value: 2997337465 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | UPDATE STATEMENT | | 1 | 308 | 3 (0)| 00:00:01 | | 1 | UPDATE | DIRECTORY_LISTING_STG | | | | | |* 2 | INDEX UNIQUE SCAN| XPKDLS_STG_PARTPN | 1 | 308 | 2 (0)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("RECORD_KEY"=TO_NUMBER(:P_KEY))
Details of the database,
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production PL/SQL Release 11.1.0.7.0 - Production "CORE 11.1.0.7.0 Production" TNS for Linux: Version 11.1.0.7.0 - Production NLSRTL Version 11.1.0.7.0 - Production
Thank you
RAM
2793617 wrote:
Hello
I am updating table via an application using Hibernate jdbc connection online.
If the update statement will be sent to the database in a pack of 500 documents (batch update).
Thanks Ram
line-by-line UPDATE is slow by slow transformation
In Oracle no other session can 'see' upgrade from uncommitted changes.
The only way to significantly reduce the elapsed time is to have only 1 UPDATE & 1 COMMIT!
-
Update statement can be used depending on the result cache?
Hi all
I stumbled on an interesting question. UPDATE statement is used in the following function, even if the feature is created RESULT_CACHE. It seems illogical. I was wondering, is it possible?
If so, why RESULT_CACHE is used? Because it means "do not execute the function, look for the result of the hash table and return the results to the user ' if the UPDATE statement, so doesn't mean it should run for each call and use with RESULT_CACHE and UPDATE/DELETE/MERGE is illogical or wrong?
Thanks for your help.
FUNCTION to CREATE or REPLACE plch_get_data (FULL id_in)
RETURN VARCHAR2
RESULT_CACHE
IS
BEGIN
Dbms_output.put_line ('run');
UPDATE plch_data
SET nm = UPPER (nm)
WHERE id = id_in;
COMMIT;
RETURN "SUPERIOR."
END;
/
Yes, it's the challenge of PL/SQL quiz - and the point of the quiz is only automatic relies on parsing by Oracle only supports arrays of account that is QUESTIONED.
The tables that are affected by DML not a query as an update do not figure in automatic invalidation of a cache.
I was hoping that the explanations given in the questionnaire itself would not lead to a thread - rather it would provide a pleasant and clear answer. So feel free to let me know if you think otherwise.
As to why Oracle would let you include DML not a query inside a function of caching of result, well... I can easily accept that you shouldn't do this - in general. But I don't see that we should make it impossible. It would probably be a good candidate for an another PLW (PL/SQL warning), as in:
"Non-requetes DML in a result caching function will not affect caching and can result in unexpected results."
-
Helps when a special character and is included in the update statement
Hi gurus,
Please suggest me here. Your help is greatly appreciated.Am wririting an update statement on a column called Phone_num.description varchar2 (40).
Here is my update statement:
UPDATE Phone_num
DESCRIPTION SET = "Beta - EMV / not for the purpose of Production."
WHERE DIAL_NUMBER = 18662307528
AND DESCRIPTION =' to & VERIZON';
Here is the structure of the table:Phone_num. Description varchar2 (40)
Phone_num. DIAL_NUMBER Number (11)Sample data:
So when I run the sql script it pop-up is to highlight.Please suggest how I can handle this.
Hello
As John said, the easiest thing is just to disable the functionality of substitution of variables, saying:
SET DEFINE OFF
before the statement. If you need to re - enable this feature, then tell
ALL SET ON
just after the statement.
If you can't do that, then break the literal string in 2 parts immediately after the & character, like this:
UPDATE Phone_num
DESCRIPTION SET = "Beta - EMV / not for the purpose of Production."
WHERE DIAL_NUMBER = 18662307528
AND DESCRIPTION = ' to &'. | "VERIZON";
You can't have a substitution variable whose name starts by ', then SQL ("more does not interpret &" as meaning a substituton variable.)
-
Update statement is a coherent lof 'Get '.
Hello
When I run this update statement, it generates a lot of 'get in line ':
UPDATE PFA_FUSIONFACC WAS
SET (COD_FACTURA, TOT_CARGO_DB, TOT_CARGO_FB) =
(SELECT THE NPC. COD_FACTUcaRA AS COD_FACTURA, NPC. TOT_BASEIMPO_E AS TOT_BASEIMPO, NPC. TOT_IMPEMI AS TOT_IMPEMI
OF NPC, CTA AUX_CTAFACTU PFA_NPCOFACTMES
where LTC. CTA_FACTURAC = WAS. CTA_FACTURAC
AND NPC.cod_postal = CTA.cod_postal
AND NPC.cta_facturac = CTA.cta_facturac)
where FUS.rowid in
(SELECT WAS.) ROWID
NPC PFA_NPCOFACTMES, CTA AUX_CTAFACTU, WAS PFA_FUSIONFACC
where LTC. CTA_FACTURAC = WAS. CTA_FACTURAC
AND NPC.cod_postal = CTA.cod_postal
AND NPC.cta_facturac = CTA.cta_facturac
AND ROWNUM < 10000);
9999 filas actualizadas.
Passed: 01:38:15.47
Run plan
----------------------------------------------------------
Hash value of plan: 2048200947
----------------------------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time | Pstart. Pstop |
----------------------------------------------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT. | 1. 62. | 117 KB (4) | 00:23:27 | | |
| 1. UPDATE | PFA_FUSIONFACC | | | | | | | |
| 2. NESTED LOOPS | | 1. 62. | 117 KB (4) | 00:23:27 | | |
| 3. VIEW | VW_NSO_1 | 9999 | 117 KB | | 117 KB (4) | 00:23:27 | | |
| 4. UNIQUE FATE | | 1. 478K | | | | | |
|* 5 | COUNT STOPKEY | | | | | | | | |
|* 6 | HASH JOIN | | 774K | 36 M | 86 M | 117 KB (4) | 00:23:27 | | |
| 7. NESTED LOOPS | | 2258K | 60 M | | 101K (4) | 00:20:16 | | |
| 8. RANGE OF PARTITION ALL THE | | 2258K | 32 M | | 2554 (2) | 00:00:31 | 1. 338.
| 9. FULL RESTRICTED INDEX SCAN FAST | PFA_NPCOFACTMES_103 | 2258K | 32 M | | 2554 (2) | 00:00:31 | 1. 338.
| * 10 | INDEX UNIQUE SCAN | PK_AUX_CTAFACTU | 1. 13. | 2 (0) | 00:00:01 | | |
| 11. FULL RESTRICTED INDEX SCAN FAST | PFA_FUSIONFACC_I01 | 3923K | 78 M | | 5358 (2) | 00:01:05 | | |
| 12. TABLE ACCESS BY ROWID USER | PFA_FUSIONFACC | 1. 50. | 1 (0) | 00:00:01 | | |
| 13. TABLE ACCESS BY LOCAL INDEX ROWID | PFA_NPCOFACTMES | 1. 56. | 2 (0) | 00:00:01 | 1. 1.
| 14. NESTED LOOPS | | 1. 69. | 49 (0) | 00:00:01 | | |
| * 15 | INDEX SKIP SCAN | PK_AUX_CTAFACTU | 1. 13. | 47 (0) | 00:00:01 | | |
| 16. RANGE OF PARTITION ITERATOR. | 1. | | 1 (0) | 00:00:01 | KEY | KEY |
| * 17. INDEX RANGE SCAN | PFA_NPCOFACTMES_103 | 1. | | 1 (0) | 00:00:01 | KEY | KEY |
----------------------------------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
5 - filter(ROWNUM<10000)
6 - access("CTA".") CTA_FACTURAC "=" WAS ". ("' CTA_FACTURAC")
10 - access("NPC".") COD_POSTAL "=" CTA ". "" COD_POSTAL "AND"NPC ". "" CTA_FACTURAC "=" CTA ". ("' CTA_FACTURAC")
15 - access("CTA".") CTA_FACTURAC "(=:B1)"
filter ("CTA". "CTA_FACTURAC"(=:B1) "
17 - access("NPC".") COD_POSTAL "=" CTA ". "" COD_POSTAL "AND"NPC ". "CTA_FACTURAC"(=:B1) "
filter ("NPC". "" CTA_FACTURAC "=" CTA ". ("' CTA_FACTURAC")
And statistics
----------------------------------------------------------
1 recursive calls
13252 db block Gets
200711795 compatible Gets
407276 physical reads
Redo 3550216 size
837 bytes sent via SQL * Net to client
1320 bytes received via SQL * Net from client
3 SQL * Net back and forth to and from the client
2 sorts (memory)
0 sorts (disk)
9999 rows processed
Rollback Terminado.
But the query used by the update is much less "gets":
SQL > SELECT WAS. ROWID
NPC PFA_NPCOFACTMES, CTA AUX_CTAFACTU, WAS PFA_FUSIONFACC
2 where 3 DEC. CTA_FACTURAC = WAS. CTA_FACTURAC
AND NPC.cod_postal = CTA.cod_postal
4 5 AND NPC.cta_facturac = CTA.cta_facturac
AND ROWNUM < 10000 6;
9999 filas seleccionadas.
Passed: 00:00:20.57
Run plan
----------------------------------------------------------
Hash value of plan: 20234272
-----------------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time | Pstart. Pstop |
-----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9999 | 937K | | 29298 (2) | 00:05:52 | | |
|* 1 | COUNT STOPKEY | | | | | | | | |
|* 2 | HASH JOIN | | 774K | 70 M | 58 M | 29298 (2) | 00:05:52 | | |
| 3. RANGE OF PARTITION ALL THE | | 2258K | 32 M | | 2554 (2) | 00:00:31 | 1. 338.
| 4. FULL RESTRICTED INDEX SCAN FAST | PFA_NPCOFACTMES_103 | 2258K | 32 M | | 2554 (2) | 00:00:31 | 1. 338.
|* 5 | HASH JOIN | | 3906K | 175 M | 123 M | 12842 (2) | 00:02:35 | | |
| 6. FULL RESTRICTED INDEX SCAN FAST | PFA_FUSIONFACC_I01 | 3923K | 78 M | | 5358 (2) | 00:01:05 | | |
| 7. FULL RESTRICTED INDEX SCAN FAST | PK_AUX_CTAFACTU | 147K | 1869K | | 1120 (1) | 00:00:14 | | |
-----------------------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
1 - filter(ROWNUM<10000)
2 - access("NPC".") COD_POSTAL "=" CTA ". "" COD_POSTAL "AND"NPC ". "" CTA_FACTURAC "=" CTA ". ("' CTA_FACTURAC")
5 - access("CTA".") CTA_FACTURAC "=" WAS ". ("' CTA_FACTURAC")
And statistics
----------------------------------------------------------
1 recursive calls
0 db block Gets
54736 compatible Gets
53070 physical readings
0 redo size
304491 bytes sent via SQL * Net to client
7814 bytes received via SQL * Net from client
668 SQL * Net back and forth to and from the client
0 sorts (memory)
0 sorts (disk)
9999 rows processed
The "PFA_NPCOFACTMES_103" index is partitioned. I don't know if it's related to this issue:
SQL > select table_name, uniqueness, separated from all_indexes where index-name = "PFA_NPCOFACTMES_103";
TABLE_NAME UNIQUENES BY
------------------------------ --------- ---
PFA_NPCOFACTMES NON-UNIQUE YES
SQL > select TABLE_NAME, COLUMN_NAME, position_colonne from all_ind_columns where index-name = "PFA_NPCOFACTMES_103";
TABLE_NAME COLUMN_NAME POSITION_COLONNE
------------------------------ ------------------------------ ---------------
PFA_NPCOFACTMES CTA_FACTURAC 2
PFA_NPCOFACTMES COD_POSTAL 1
Why the update does not generate as much "becomes"?
Thanks in advance,
Jose Luis
I don't know the reason why at first sight, but it is obvious that the inner nested loop was doing a lot of work (full index scan).
My first thought was to rewrite the query in a merge statement.
Perhaps leads to a more effective plan and so no need to delve deeper into the issues you have raised ;-)
merge into FUS PFA_FUSIONFACC
a_l'_aide_de)
SELECT
NPC. COD_FACTUcaRA AS COD_FACTURA
NPC. TOT_BASEIMPO_E AS TOT_BASEIMPO
NPC. TOT_IMPEMI AS TOT_IMPEMI
OF NPC, CTA AUX_CTAFACTU PFA_NPCOFACTMES
where
NPC.cod_postal = CTA.cod_postal
AND NPC.cta_facturac = CTA.cta_facturac
) cta
(TBT. CTA_FACTURAC = WAS. CTA_FACTURAC)
When matched then update
Was SET. COD_FACTURA = cta. COD_FACTURA
was. TOT_CARGO_DB = cta. TOT_BASEIMPO
was. TOT_CARGO_FB) = cta. TOT_IMPEMI
where ROWNUM<>
-
problem by making an update statement
Hi all
I should write an update statement
These tables: country: name, code, population, nextyearr_population...
nextyear_population is empty, first, I should get population_growth of the picture of the population, then compute the year population next according to population and population_growth corrent
population: country (in fact no code name of the country), population_growth,...
So I wrote and I got this error
Error starting at line 1 in command: update country c set c.nextyear_population=(c.population+ ((c.population*(select pop.population_growth from population pop join country co on co.code=pop.code))/100) ) where country.code=population.country Error at Command Line:4 Column:20 Error report: SQL Error: ORA-00904: "POPULATION"."COUNTRY": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action:
Thanks in advance-------------------------------------------------------- -- File created - Wednesday-May-15-2013 -------------------------------------------------------- -------------------------------------------------------- -- DDL for Table COUNTRY -------------------------------------------------------- CREATE TABLE "intern"."COUNTRY" ("NAME" VARCHAR2(40), "CODE" CHAR(2), "CAPITAL" VARCHAR2(40), "PROVINCE" VARCHAR2(40), "POPULATION" NUMBER, "AREA" NUMBER, "NEXTYEAR_POPULATION" NUMBER) COMMENT ON COLUMN "intern"."COUNTRY"."NAME" IS 'the country name' COMMENT ON COLUMN "intern"."COUNTRY"."CODE" IS 'the internet country code (two letters)' COMMENT ON COLUMN "intern"."COUNTRY"."CAPITAL" IS 'the name of the capital' COMMENT ON COLUMN "intern"."COUNTRY"."PROVINCE" IS 'the province where the capital belongs to' COMMENT ON COLUMN "intern"."COUNTRY"."POPULATION" IS 'the population number' COMMENT ON COLUMN "intern"."COUNTRY"."AREA" IS 'the total area' COMMENT ON TABLE "intern"."COUNTRY" IS 'the countries of the world with some data' REM INSERTING into intern.COUNTRY SET DEFINE OFF; Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Andorra','ad','Andorra la Vella','Andorra la Vella',69865,468,null); Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('United Arab Emirates','ae','Abu Dhabi','Abu Dhabi',2523915,82880,null); Insert into intern.COUNTRY (NAME,CODE,CAPITAL,PROVINCE,POPULATION,AREA,NEXTYEAR_POPULATION) values ('Afghanistan','af','Kabul','Kabul',28513677,647500,null); -------------------------------------------------------- -- File created - Wednesday-May-15-2013 -------------------------------------------------------- -------------------------------------------------------- -- DDL for Table POPULATION -------------------------------------------------------- CREATE TABLE "intern"."POPULATION" ("COUNTRY" CHAR(2), "POPULATION_GROWTH" NUMBER, "INFANT_MORTALITY" NUMBER) COMMENT ON COLUMN "intern"."POPULATION"."COUNTRY" IS 'the country code' COMMENT ON COLUMN "intern"."POPULATION"."POPULATION_GROWTH" IS 'population growth rate (percentage, per annum)' COMMENT ON COLUMN "intern"."POPULATION"."INFANT_MORTALITY" IS 'infant mortality (per thousand)' COMMENT ON TABLE "intern"."POPULATION" IS 'information about the population of the countries' REM INSERTING into intern.POPULATION SET DEFINE OFF; Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ad',0.95,4.05); Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('ae',1.54,14.51); Insert into intern.POPULATION (COUNTRY,POPULATION_GROWTH,INFANT_MORTALITY) values ('af',4.77,163.07);
I'm using oracle11g and ubuntu 12
best, davidupdate country c set nextyear_population = population + population * (select pop.population_growth from population pop where c.code = pop.country) / 100 where code in ( select country from population ) /
SY.
-
Handful of division by zero error in the update statement
My dear welcom
How and I overcame this problem in my update statement
for exwmple, it comes to the table
CREATE TABLE TEST4
(
A1 NUMBER,
A2 NUMBER OF,
A3 NUMBER
)
Insert into TEST4 a1, a2, values (15.3);
Insert into TEST4 a1, a2, values (9.3);
Insert into TEST4 a1, a2, values (12.0);
commit;
now, I'm trying to update the column a3 in Division a1/12
Start
update set of test4
A3 = a1/a2;
exception
WHEN ZERO_DIVIDE THEN
update set of test4
A3 = 0;
end;
After you validate THE VALUE of A3 = 0;
Can any onle help me
I use oracle 10g R2
Thanks in advanceSQL> select * 2 from test4 3 / A1 A2 A3 ---------- ---------- ---------- 15 3 9 3 12 0 SQL> update test4 2 set a3 = case a2 when 0 then 0 else a1 / a2 end 3 / 3 rows updated. SQL> select * 2 from test4 3 / A1 A2 A3 ---------- ---------- ---------- 15 3 5 9 3 3 12 0 0 SQL>
SY.
-
Merger of statement: with several Update statement.
Hello
I'm trying under the merge statement. However to get the error "not correctly completed 0ra-00933 sql command.
In fact, my join conditions are the same, but I wanted to update the different columns based on the different places where clause in the update statement.
for example.
FUSION
IN abc3 tgt
With the HELP of abc CBC
WE (src.cust = tgt.cust)
WHEN MATCHED
THEN
UPDATE
SET tgt.sales = src.sales
where tgt.cust = 'Cust3'
UPDATE
SET tgt.sales1 = src.sales
where tgt.cust = 'Cust2';
Please let me know if there is no work around for this.Hi, pm
You can try this please.
MERGE INTO ABC3 TGT USING ABC SRC ON (src.cust = tgt.cust) WHEN MATCHED THEN UPDATE SET TGT.SALES = DECODE(TGT.CUST,'Cust3',SRC.SALES,TGT.SALES), TGT.SALES1 = DECODE(TGT.CUST,'Cust2',SRC.SALES,TGT.SALES1) WHERE TGT.CUST='Cust3' OR tgt.cust='Cust2';
-
How to use the user defined function in the Update statement
Hi all
I wrote under the update statement to update the column based on the return value of function. but it does not work. Could someone help me on this. This function returns a single value for each project.
Thanks in advance.
UPDATE dg2. OD_PROJ_LOOKUP_TEMP o
SET Months_In_Stage_Cnt = Months_In_Stage_Cnt_ret (o.project_id) select the double;
Thank you
DebPLS-00231: function 'MONTHS_IN_STAGE_CNT_RET' cannot be used in SQL
-What is the function that is declared private in a package? If Yes, then it must be public, otherwise the SQL engine cannot be used.
Published by: Dom Brooks on November 18, 2011 09:43
Maybe you are looking for
-
Hello For years, I am using NetInstall unroll my Mac to my 50ish users. As typical, I created a machine exactly as I want. When I buy a new machine (or decide to reimage an old), I start to restore image, change the name of the account, copy the fil
-
700 - 230qe Windows 10 of envy. No speakers or headphones are connected.
Wind 10 was already running through upgrade. Computer got slow slow opening files. Reinstalled windows and all that was giving problems very well works. Except that he said no speakers. There is no indicator in the device mgr. Driver is installed.
-
HP Deskjet 3050 J610 Series: Use of printer remove from 22/02/15.
There is a document which is held in my printer with the status "deletion" since 02/22/15. I'm not able to cancel printing and am not able to print anything else. Any help would be appreciated. The print job has been an interactive ticket secured
-
Hello I was just wondering if it would be worth for my thinkpad to buy a turbo memory stick. Data sheet: core 2 duo t8300, ram 4 GB, graphic chip nvidia and im working on the acquire an ssd, OS is Windows 7. Type of machine is 7663 - 11
-
How to connect to someones shared folders?
my friend has created network place a how to connect to its folders/disks shared in xp?