update using case statement
Hello my friendsI have a table "encompasses": continent, country, percentage
now the update should change the continent field, all the 'Europe' that 'Asia' and all 'Asia' to 'America' and 'America', 'Europe' using cases and an update statement.
So I wrote and I got this error
Error starting at line 2 in command:
UPDATE encompasses
SET continent=
CASE WHEN continent='Europe' THEN 'Asia'
WHEN continent='Asia' THEN 'America'
WHEN continent='America' THEN 'Europe'
END
Error report:
SQL Error: ORA-01407: cannot update ("intern"."ENCOMPASSES"."CONTINENT") to NULL
01407. 00000 - "cannot update (%s) to NULL"
*Cause:
*Action:
Please give me advice, thanks.-------------------------------------------------------
-- File created - Monday-May-13-2013
--------------------------------------------------------
--------------------------------------------------------
--------------------------------------------------------
CREATE TABLE "intern"."ENCOMPASSES" ("COUNTRY" CHAR(2), "CONTINENT" VARCHAR2(20), "PERCENTAGE" NUMBER)
COMMENT ON COLUMN "intern"."ENCOMPASSES"."COUNTRY" IS 'the country code'
COMMENT ON COLUMN "intern"."ENCOMPASSES"."CONTINENT" IS 'the continent name'
COMMENT ON COLUMN "intern"."ENCOMPASSES"."PERCENTAGE" IS 'percentage, how much of the area of a country belongs to the
continent'
COMMENT ON TABLE "intern"."ENCOMPASSES" IS 'information to which continents a country belongs'
REM INSERTING into intern.ENCOMPASSES
SET DEFINE OFF;
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('cx','Asia',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('eg','Asia',10);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ge','Asia',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('id','Asia',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ad','Europe',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('al','Europe',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('at','Europe',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('ba','Europe',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pa','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pe','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pm','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('pr','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('py','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('sr','America',100);
Insert into intern.ENCOMPASSES (COUNTRY,CONTINENT,PERCENTAGE) values ('sv','America',100);
Thank you, im using oracle 11g and ubuntu12best, david
Published by: 1003209 on May 13, 2013 10:12
If the continent does not fit the clauses WHEN CASE returns NULL. Add on the OTHER:
UPDATE encompasses
SET continent=
CASE WHEN continent='Europe' THEN 'Asia'
WHEN continent='Asia' THEN 'America'
WHEN continent='America' THEN 'Europe'
ELSE continent
END
SY.
Tags: Database
Similar Questions
-
I have problem with value NULL when the use CASE statement please help this question
I have problem with value NULL when the use CASE statement please help this question
Table: digital_val
SNO cl C2
1 San1 11
2 22 San2
Actual result: expected to A B
A B 11 22
11 NULL
22 NULL
query:
Select case when c1 = "san1" then c2,.
case If c1 = "san2" then c2 B
of digital_val
I'm more curious why, when you select 2 rows, you expect a result of row?
WITH digital_val
AS (SELECT 1 AS 'Sno', 'San1"C1, c2 FROM DUAL 11)
UNION ALL
2 SELECT AS 'Sno', 'San2"C1, c2 FROM DUAL 22)
SELECT CASE WHEN c1 is "San1" THEN END AS A c2.
CASE WHEN c1 = "San2" THEN END AS B c2
OF digital_val;
With no other input, if you select 2 rows, you get 2 rows. One of the other solutions use a max function, but is this really what you want, does not specify?
-
update TRG set C2=(using Case only Where ... 1).FOR C2 when TRG.K=SRC.K then SRC.B ELSE 0 a).TRG.K=SRC.K (Only one row for id = 300 then SRC.B) b).TRG.K=SRC.K & TRG.K!=SRC.K (two rows row for id = 100 then 0 for first row when TRG.K=SRC.K then 0 else SRC.B) Example: TRG K Id C2 201 100 3 202 100 4 201 300 5 Expected: TRG SRC.B K Id C2 30 201 100 0 30 202 100 30 42 201 300 42
It looks like, I was lucky to guess :), but this time I honestly don't know what you're after :(
If there is more than 2 ranks cnt > 1 and and rn = 1 will assign 0 to line 1 and b for the rest of the lines
Another assumption - you might be after
ranks cnt > 1 and and rn <> would assign 0 to all lines but the last (numbered cnt) and b on the last line has already been mentioned
There is another possible change: row_number() over (partition by order of identification by k desc) rn, i.e. reverse the order of numbering
Please provide the desired resultrn cnt c2 c2 c2 1 4 0 0 ? 2 4 b 0 ? 3 4 b 0 ? 4 4 b b ? | | | cnt > 1 and rn < cnt | cnt > 1 and rn = 1
Concerning
Etbin
-
Schema export multile using the case statement
Hello
I want several export schema using case statement.
provable I 4 schema test1, test2, test3 test4 for the scheme I created scripts for each of them either 4 scripts but I want only a scripts instead of 4 scripts. Please suggest how to write shell scripts using a case statement (via a parameter name or the schema).
example of diagram of TEST1.
expdp "" system/redhat as sysdba' "dumpfile directory = TEST1.dmp = DUMP_DIR = TEST1.log patterns = TEST1 logfile logfile = TEST1_Export.log
is it possible if you use under case statement (via the name of parameter/schema)
as case 1: TEST1
2: TEST2
3: TEST3
4: TEST4
If I pass the value as TEST1, and TEST1 schema export is made.No, it's easier.
In addition, you can only get the number and then use TEST$ {export_schema} instead.
But in any case you don't have no need 'breaks '. -
Hello
I am trying to use a global variable 'Global.test' in my ODI "pkg_test" package and step declaration type as a variable that is defined with the value 1 when my package evaluates the condition successfully run and with 0 if the fails.now condition I will carry out the same "pkg_test" package in my load "LP_TEST" and using the variable 'Global.test' Plan as a case statement in terms of load "LP_TEST".
It's workload Odi is unable to understand the value of the variable 'Global.test', which is defined in my pkg 'pkg_test' and my case statement is put down in my care Plan.
Thank you
Hi Santosh Pradhan,
What kind of story do you have in your variable?
If you have not selected any antecedent, the scope of the variable is limited to the session. As the execution of the package is a session in its own (independent of the workload performance), the value of the variable is not accessible after his execution.
You can also try assigning / updating of the value of the variable directly from your plan, instead of in the package:
It will be useful.
Best regards
JeromeFr
-
Use the control of timing DAQmx as input in case statement
Hello
I'm building a VI aquire sampled under tension of a sensor in continuous mode or finished. I was going to do this, use a box with a cable of the sample mode of the VI DAQmx calendar entry to the terminal State, the idea being that I couldn't aeither a while looping the case for continuous or simple acquisition according to the setting of this command.
However, instead of the sample mode provided for in the case of the case statement, I just get 1 and 0.
It's a good way to achieve this, and if so how can I get my case structure working properly?
Thank you
Dave
Hi Dave,.
Apologies - I consider that the error is from the data acquisition function? I forgot that she was using the sample entry mode.
Perhaps, then, it will be preferable to continue using the control of the ring - cases will be numbered and will correspond to the numeric value of the selection of the ring (i.e. finite samples = 0). I have attached a small example if we know not.
Moreover, the structure of the case cannot automatically fill for each case, in which case you can right click on the structure of the case-> add the case after.
Best regards
-
Can I use a hexadecimal string with a case statement?
Simple question:
Can I enter a hexadecimal string to a case statement and have the case statement see it as hex?
I understand that I could convert the hexadecimal string to a number and then enter the hexadecimal number to the case statement but I am curious to know if I could have the case see the string itself as hex without this added feature.
Would be nice to not have to convert all my numbers throughout my code strings
Thank you
-Eric
How long are the strings? Since you mention convert in numbers, they are probably short and all of same length.
Are there different possible channels how?
Case header includes \-codes in the case of a label deal selector As string, so that should be enough for your use. For example this code turns the LED (.. .so that a simple string of "\00\00" of wiring would not be!)
(See also the last sentence of the "enumerated values" section of the help).
-
using a Case statement to display the values of column even as table headers
I have a database that has been set up kind of tricky, in that some tables are made up of columns that are field names and one link to another table that contain the data for these field... also names there ID displays as many lines instead of as a row of data. I would like to write a query to extract that information and display it as one line for each ID.
example: table 1
ID, name, itemresponse and itemcode, Description
Dee Jones Childrens Hospital 123 SITE location
123 dee Jones, Date of appointment next NEXTAPPT 22/04/2014
123 dee Jones was on bedrest NOSHOW reason do not show
I would like to have the display of data as a record on this same patient, instead of as 3 separate registers (with the Description column in table 1
Table 2
ID, name, place, Date of the next meeting, show no reason
123 dee Jones Childrens Hospital 22/04/2014 was the bed rest
I have included the code I worked on below my question, for me to get the desired results should I use the Case statement and it's the right way to do it below?
(SELECT
PAT.ID "PATIENT ID."
PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
PAT. "PATIENT DOB," DATE_OF_BIRTH
DS. Date 'Date of inpatients ',.
Dai. ITEM_CODE "Item Code",
Dai. DESCRIPTION "Description."
Siad. ITEM_RESPONSE,Max (CASE WHEN dai. ITEM_CODE IS "SITE" THEN DAI. Decription
ANOTHER NULL
END) AS "name of the hospital."
Max (CASE WHEN DAI.) ITEM_CODE IS 'NEXTAPPT' THEN DAI. ITEM_Description
ANOTHER NULL
END) AS 'next Appt Date. "
Max (CASE WHEN DAI.) ITEM_CODE IS "LASTDATE" THEN DAI. Description
ANOTHER NULL
END) AS 'last visit Date.
Max (CASE WHEN DAI.) ITEM_CODE IS 'NOSHOW' THEN DAI. Description
ANOTHER NULL
END) THAT "the reason has not shown".
Of
(PAT.ID "IDENTIFYING PATIENT",
PAT. FIRST | » '|| PAT. "PATIENT FIRST NAME."
PAT. "PATIENT DOB," DATE_OF_BIRTH
DS. Date 'Date of inpatients ',.
Dai. ITEM_CODE "Item Code",
Dai. DESCRIPTION "Description."
Siad. ITEM_RESPONSEOf
dm_sessions Ds,
dm_session_assessments dsa,
DAS dm_admin_sections,
dm_session_assessment_items Siad,
Dai dm_admin_items,
Po Patient_Orders,
Inventory inv,
Patients_Table PAT
dm_admin_categories CAD
where dsa.session_Id = ds.session_Id
and PAT.ID = ds. Patient_ID
and dsa.excluded_assessment =' no
and dac.category_code = 'OPEN'and dsa.section_id = das.section_id
and das.category_id = dac.category_id
and das.section_code = 'northwest'
and dai.section_id = das.section_id
and dsai.item_id = dai.item_id
and dsai.session_assessment_Id = dsa.session_assessment_Id
and dsai.excluded =' no
- and Dai.ITEM_ID = Dsai.ITEM_ID
and Dai.ITEM_CODE IN ('SITE', 'NEXTAPPT', 'LASTDATE', 'NOSHOW')
and po.patient_ID = ds.patient_ID
and in. NDC_NO = inv. NDC_NO
and inv. TDRUG_ABBREV = in. DRUG_ABBREV
PAT.ID GROUP, PAT. FIRST | » '|| PAT. LAST, PAT. DATE_OF_BIRTH, ds. Date, dai. ITEM_CODE, dai. DESCRIPTION, Siad. ITEM_RESPONSE))Hello
DATE is not a very good name for a column. Use something like EVENT_DATE, that will not be confused with a keyword from Oracle, instead.
I don't see something like this column in the CREATE TABLE statement. He will always be the same value on all lines?
Here's a way to get the results you requested:
SELECT id
first name | ' ' || LastName AS name
Date of birth
MAX (CASE WHEN item_code = "NEXTAPPT", THEN item_response END) AS next_appointment,
MAX (CASE WHEN item_code = "LASTDATE" THEN item_response END) AS last_visit_date,
MAX (CASE WHEN item_code = "SITE" THEN item_response END) AS location
FROM mytable1
GROUP BY id, firstname, lastname, dob
;
Of course, I can't test it very well until you post INSERT statements for the sample data.
I guess that 2 or more lines of the entry have the same id, then they will necessarily be first name last name, the name and date of birth, too. No doubt they are standardized in your actual tables.
-
HelloHow can I convert a code for the below sql case statement:
If)
(length of (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < = 0 OR tmp_co_orig_val == 1 OR tmp_co_orig_val > = 9999999)
OR
((tmp_co_orig_val == 999999 AND (length of (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15)))
Start
tmp_collatvalue = «»
tmp_msg_cd = 115
end
Is the case statement below that I wrote is correct. I don't have an environment now to test. Please advice.
BOX WHEN (CHAR_LENGTH (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < 0 OR tmp_co_orig_val = 1 OR tmp_co_orig_val = > = 9999999)
OR (tmp_co_orig_val = 999999 AND (CHAR_LENGTH (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15))
THEN tmp_collatvalue IS NULL AND tmp_msg_cd = 115
END
Hello
937454 wrote:
Thanks Frank. Really helps. But I have to write a sql statement
But can you also specify, if I made a mistake in my code, or it's ok.
There are no CASES reported in Oracle SQL.
Oracle SQL has BOX expressions, but they only return a single value. You cannot set 2 columns in the same expression BOX.
Perhaps the best thing to do in pure SQL for you is to write a CASE expression, very similar to the CASE statement above, in a subquery and use the results of this in 2 separate expressions of BOX (very simple) in a Super application.
-
using case when statement or decode unfavorable in where clause
Hi the gems...
I have a problem in the following query...
I try to use when case statement in where clause of a select query.
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when ' > ' = ' > ' then ' cr.salary > 5000')
When ' > ' = ' < ' then ' cr.salary < 5000'
When ' > ' = '=' and then 'cr.salary = 5000'
Another null
(end);
the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
That is why, for the execution of the query, I put ' > ' in this place.
If the original query will look like this (for reference):
Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when variable = ' > ' then ' cr.salary > 5000')
When the variable = ' < ' then ' cr.salary < 5000'
When the variable = '=' and then 'cr.salary = 5000'
Another null
(end);
so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
If the user selects '=', then the filter will be 'where cr.salary = 5000 '.
but I get the error "ORA 00920:invalid relational operator.
Help, please... Thanks in advance...Hello
select cr.customer_name || ' - ' ||cr.customer_number as cust_name, cr.salary as salary from customer_details cr where ( v_variable = 'bigger' and cr.salary > 5000 ) or ( v_variable = 'less' and cr.salary < 5000 ) or ( v_variable = 'eq' and cr.salary = 5000 )
Published by: user6806750 on 22.12.2011 14:56
For some reason that I can't write in sql "<', '="">", "=".',>
-
Tuning - using the CASE statement in the WHERE clause of the query
Hi all
My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:
Query:
Description of the table:SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date, os.acctnum, os.avieworigin_refid, COUNT(1) cnt_articleview, SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm FROM TABLE1 os WHERE os.acctnum IS NOT NULL AND os.avieworigin_refid IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND CASE WHEN Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 END = 1 AND CASE WHEN Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' THEN 1 END = 1 GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
(Number of lines: approx. > amount 600 000 000)
Explain PlanName Null Type ------------------------------ -------- ------------ ARTICLEID NOT NULL NUMBER(20) USERKEY NUMBER(10) AVIEWORIGIN_REFID VARCHAR2(10) SUCCESS_IND VARCHAR2(2) ENTRY_CREATEDDATE DATE CREATED_BY VARCHAR2(10) FILENUMBER NUMBER(10) LINENUMBER NUMBER(10) ACCTNUM VARCHAR2(10) AUTOCOMPLETEDTERM NUMBER(2) REQUESTDATETIME VARCHAR2(19)
Published by: Chaitanya on June 9, 2011 02:44SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2224314832 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| |* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| ---------------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN 'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL' AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:47When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.
BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like? -
Use the CASE statement in a query of LOV
Hello
I wrote a select statement to be used in my list of values query, and it works fine when I run with SQL Developer. But when I put it in the LOV I get the LOV query is invalid error message. Here's the query I use:
If the CASE statement is the source of the problem?select case when nt.COMMON_NAME is not null then nt.COMMON_NAME || ' (' || nt.TAXON_NAME || ')' else nt.TAXON_NAME end display_species ,case when nt.COMMON_NAME is not null then nt.COMMON_NAME || ' (' || nt.TAXON_NAME || ')' else nt.TAXON_NAME end return_species FROM NBN_TAXON nt WHERE lower(nt.INPUT_CATEGORY) = decode(lower(:P312_TAXON_GROUP_ADD), 'fish', 'fishes', lower(:P312_TAXON_GROUP_ADD)) order by 1;
Hello
Try to remove the colon semi at the end.
See you soon
Ben
-
Help: How to use the Case statement in the ODI11g Interface?
Hello
My basic source I get 'Year' values and I want that these values result code in the interface and after translation want to push on the target system.
Example:
Database source, I get value for
Year
2010
2011
2012
When I get the year 2010 I want to change the value in "FY10".
When I get year 2011 I want to change the value in "FY11.
and even for the year 2012 to "FY12.
I've tried to make the Case statement, but had no success.
I don't want to create the lookup table in the source system.
Any help in this matter.
Thank you
Concerning
Sher
Published by: Sher Ullah Baig on August 26, 2012 17:52CASE
WHEN source_column = '2010' THEN 'FY10.
WHEN source_column = '2011' and THEN 'FY11.
WHEN source_column = '2012' and THEN 'FY12.
END -
Using nested switch/case statements
What is the best practice of two following switch/case statements?
Is there an easier way (less code) to do this?
Thank you.I think it's as clean as it gets:
-
Case statement in the process Page
Request Express 3.2.1.00.11
I put the following code in an anonymous block (will return no error) for a process Page;
BEGIN INSERT INTO DAD_ASSESSMENT_REQUEST ( tenure_id , client_id ) VALUES ( :P10101_TENURE_ID , :P10101_CLIENT_ID ); END;
But when I put a statement case it throws the following error;
1 error has occurred ORA-06550: line 7, column 3: PL/SQL: ORA-01747: invalid user.table.column, table.column, or column specification ORA-06550: line 3, column 1: PL/SQL: SQL Statement ignored
BEGIN INSERT INTO DAD_ASSESSMENT_REQUEST ( tenure_id , client_id , (CASE WHEN (:P10101_MEASURE_OPTION = 'AREA') THEN estimated_area_ha WHEN (:P10101_MEASURE_OPTION = 'LINE') THEN estimated_length_km END) ) VALUES ( :P10101_TENURE_ID , :P10101_CLIENT_ID , :P10101_X ); END;
Why is this code not work and it is possible to use a case statement in a Page Apex process
Concerning
Ben
Benton says:
Request Express 3.2.1.00.11
I put the following code in an anonymous block (will return no error) for a process Page;
- BEGIN
- INSERT
- IN DAD_ASSESSMENT_REQUEST
- (tenure_id
- client_id
- )
- VALUES
- (: P10101_TENURE_ID)
- ,: P10101_CLIENT_ID
- );
- END;
But when I put a statement case it throws the following error;
- 1 error has occurred
- ORA-06550: line 7, column 3: PL/SQL: ORA-01747: specification user.table.column, table.column or invalid column ORA-06550: line 3, column 1: PL/SQL: statement ignored
- BEGIN
- INSERT
- IN DAD_ASSESSMENT_REQUEST
- (tenure_id
- client_id
- (CASE
- WHEN (: P10101_MEASURE_OPTION = 'SPACE') THEN estimated_area_ha
- WHEN (: P10101_MEASURE_OPTION = 'LINE') THEN estimated_length_km
- END)
- )
- VALUES
- (: P10101_TENURE_ID)
- ,: P10101_CLIENT_ID
- ,: P10101_X
- );
- END;
Why is this code not work and it is possible to use a case statement in a Page Apex process
Of course, it is possible to use a CASE statement or expression (it is the latter) in a page APEX process. However, it is not possible to use an invalid syntax while doing so. Part of a clause INSERT INTO can contain only static column names.
In general the SQL expressions (and also the bind variable, another cause frequent errors of syntax) can be used only in
- the projections of the SELECT queries and subqueries
- the right side of the disposals in the SET update clause
- the lists of VALUES of INSERTs
- WHERE clause predicates
ReemaPuri wrote:
Try this
INSERT
IN DAD_ASSESSMENT_REQUEST
(tenure_id
client_id
estimated_area_ha
estimated_length_km
)
VALUES
(: P10101_TENURE_ID)
,: P10101_CLIENT_ID
, (SELECT CASE WHEN: P10101_MEASURE_OPTION = 'SPACE' AND THEN: P10101_X)
OTHERWISE, NULL END OF DOUBLE)
, (SELECT CASE WHEN: P10101_MEASURE_OPTION = 'LINE' THEN: P10101_X)
OTHERWISE, NULL END OF DOUBLE)
);
It's a good idea, but it can be simplified, eliminating unnecessary subqueries:
insert into dad_assessment_request ( tenure_id , client_id , estimated_area_ha , estimated_length_km) values ( :p10101_tenure_id , :p10101_client_id , case when :p10101_measure_option = 'AREA' then :p10101_x end , case when :p10101_measure_option = 'LINE' then :p10101_x end);
Maybe you are looking for
-
Equium A80: PS2/USB adapter does not work correctly
I have a satellite A80. I bought an adapter to allow me to use a graphics tablet on the usb ports. The adapter gives a ps2 keyboard and mouse ps2. The adptor is recognized by windows and displayed in the list of hardware. It also shows the mouse conn
-
Card mini PCI for Satellite P10 wireless
Hi all can someone help me find a mini PCI Wireless for my Satellite P10-304 to the United Kingdom?
-
My program involves several DAQ tasks that run in unison, as in the example of "Multi-multifunction-Synch I-AO. Works very good in general, but if anything it either never interrupts the flow of the program, I'm stuck permanently with the error 20027
-
How do you change the delay time on screen password so that I don't have to enter my username and password when I don't use the computer for several minutes?
-
XP home sp3 cannot update fixya for 0xC800042D and reported no problem and fixed... but it is not fixed, and I get the following Web site has encountered a problem and cannot display today is 21:48, 8 June 2012... but it has been throughout the after