Unique index on two columns based on the conditon
I have a table where I have two columns name and feed.create table test1 (name varchar(20), feed varchar(4));
insert into test1 values('abc','L3');
insert into test1 values( 'abc','Both');
insert into test1 values('abc','L2');
I want to create a unique index for the lines abc - L3 and cant abc - both together be inserted, rest the other flow values is not a problem, so the first two rows can not be there in the table.Please suggest
Thajs
create unique index test1_ind1 on test1 (name, case when feed = 'Both' then 'L3' else feed end );
Who did what you asked...
However, I highly doubt it does what you WANT.
Please provide information on the requirements, and we the flesh that out a little better.
Tags: Database
Similar Questions
-
Hi all
I want a unique index on two columns, but when I try this it will show me
I want to do not overlap with the combination of these two1 CREATE UNIQUE INDEX sale_order_no 2* ON sale_order (sale_order_no, season_year) SQL> / ON sale_order (sale_order_no, season_year) * ERROR at line 2: ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
Plaese Guide
Thanks and greetings
VikasYou would this behavior if SALE_ORDER_NO has NULL values. If it contains NULL values, a unique single-column index will succeed but an index unique multi-column will fail when it finds duplicates in SEASON_YEAR.
See:
SQL> create table dummy_objects (object_id number, object_owner varchar2(30), object_name varchar2(30)); Table created. SQL> insert into dummy_objects values (0,'HEMANT','TABLE_A'); 1 row created. SQL> insert into dummy_objects values (1,'HEMANT','TABLE_B'); 1 row created. SQL> insert into dummy_objects values (NULL,'HEMANT','NULL_1'); 1 row created. SQL> insert into dummy_objects values (NULL,'HEMANT','NULL_2'); 1 row created. SQL> create unique index dummy_objects_u1 on dummy_objects(object_id); Index created. SQL> drop index dummy_objects_u1; Index dropped. SQL> create unique index dummy_objects_u2 on dummy_objects(object_id, object_owner); create unique index dummy_objects_u2 on dummy_objects(object_id, object_owner) * ERROR at line 1: ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found SQL>
Hemant K Collette
http://hemantoracledba.blogspot.com -
Index on two columns becomes the index of function?
Hello, I create a unique index with two columns, a number (9) and a date.
It becomes an index of feature based with the number column and a column sys hidden (date).
When I do queries that use this index the autotrace tells me it does things like this:
sys_nc00001$ > SYS_OP_DESCEND (datevalue)
sys_nc00001$ IS NOT NULL
How is he did not have a normal index?Use of ESCR does this.
Of http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm
Oracle database processes Index descending as if they were focused on the index function.
-
retriving of unique records on two columns
Hello world
Using sql query, that he must retrieve unique records on two columns.
Example of table source: raster columns [uwi, well_no]
Examples of data below
UWI well_no
----- --------
1 988311
1 988311
1 1032662
1 1032662
2 103
2 103
2 103
3
3 104
3 104
3 104
4 106
4 107
4
4 108
For a given
UWI: 1 there are 4 well_no which is having two distinct values where these documents I need to go get
UWI: 2 there are 3 well_no, all 3 well_no contains the same value as (103) Consequently, these documents should not seek
UWI: 3 there are 4 well_no (1 null and 3 values are the same (104)] where these records should not seek.)
UWI: 4 there are 4 well_no which is to have three separate with a single value zero so these 4 files, I need to get.
output:
UWI well_no
----- --------
1 988311
1 988311
1 1032662
1 1032662
4 106
4 107
4
4 108
Thank you
Jery
Hi, Michel,.
Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data, so people who want to help you can recreate the problem and test their ideas.
Format your message so that it is easy to read and understand.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002
Maybe you want something like this, which shows information about the jobs that have deptnos 2 or more not NULL:
WITH got_cnt AS
(
SOME jobs, deptno
, ACCOUNT (SEPARATE deptno) RESUMED (work PARTITION) AS cnt
FROM scott.emp
)
SOME jobs, deptno
OF got_cnt
WHERE cnt > 1
;
-
My both hands, index fingers. which are based on the computer next to the trackpad or are used on the trackboard are painful, feel like they were burnt, and I can barely move them. I do not have this problem before, I bought my new Mac - specifications below: it hurts and I don't have a problem with my windows, iPad or Samsung Galaxy equipment operating systems computers.
It feels like radiation leaking through the computer case. Is the radiation involved in the chips?
MacBook Pro
Model identifier: MacBookPro11, 4
Processor name: Intel Core i7
Processor speed: 2.2 GHz
Number of processors: 1
Total number of Cores: 4
(By heart) L2 Cache: 256 KB
L3 Cache: 6 MB
Memory: 16 GB
Boot ROM version: MBP114.0172.B06
Version of the SCM (System): 2.29f24
Are you use while plugged in, I feel a buzzing in my 13-inch rMBP (12.1)
-
Compare multiple columns and update a column based on the comparison
Hi all
I have to update the column STATUS of the slot structure of the table.
Status should be 'P' if all the columns count are equal on the other should be "F".
The value of the column can be "NA'. If the value is NA, then avoid this comparison column; compare only other 3 columns.
My output should look like below.
State of cnt1, cnt2 cnt3 ID cnt4
1 4 4 4 4 P
2 4 5 4 4 F
3 4 4 NA 4 P
NA 4 4 3 4
I tried with the statemnt with BOX WHEN conditions and DECODE UPDATE, but could not succeed, can someone please help
To do this, if you use my statement in response #11 box (Re: Re: comparison of multi-column and update a column based on the comparison of)
-
Same page, two regions based on the same conflicts taskflow
I have a page and I understand two regions based on the same workflow, at the start of region renderes ok, but then they don't are never refreshed, it seems like a conflict.
I hope you can help me, thanks and sorry for my English...
Published by: Jocelyn on 2012-ene-18 09:13Hello
Well, I don't understand the question "no refresh" you mention. However, you did it that the workflow is isolated and does not share its DataControl? If you share the DataControl then region 1 and 2 show the same data and are just one and same.
Frank
-
In the form of table-update a column based on the other
Greetings,
I want to update a column based on the value of another column in a tabular presentation. What should I use? Calculation or validation process?
-VatsaYes, get rid of the update of "pims_component" - this is the cause of the error table mutation - and simply set
: new.state_ind: = Ls_state;
CITY
-
Update, one of the two columns based on a condition
I have this example table:
Lead_ID
Mailed_Date
Campaign of
Model
MPI
MP2
100
August 2, 12
Travel_Check
US_Air
null
null
200
August 2, 12
Travel_Check
US_Air
1099
null
MP1 and MP2 columns represent mailpiece_IDs (marketing mail that was sent). MP1 is the first piece in the mail and MP2 is the second room that receives mail. Here Lead_id 100 received no mail and Lead_id 200 received the first piece.
I want my update to allow me to update MP1 IF MP1 is null, but if MP1 is worth, I want MP2 to update. So if I update with a new post 2000 article ID the result should look like this after the update. Lead_ID 100 received a piece of mail, and 200 Lead_ID received two parts:
Lead_ID
Mailed_Date
Campaign of
Model
MPI
MP2
100
August 2, 12
Travel_Check
US_Air
2000
null
200
August 2, 12
Travel_Check
US_Air
1099
2000
I tried this case and I thought that maybe I could choose the field with COALESCE, but which doesn't seem to work. Can anyone help?
Hello
Here's another way to do it:
UPDATE yourtable
Mp1 SET = NVL (mp1, 2000)
mp2 = NVL2 (mp1, mp2 2000)
WHERE LESS (mp1, mp2) IS NULL
;
In any case, there are 2 columns that could be changed, so you should have 2 columns listed in the SET clause. It does not matter that one or these columns will be always equal to itself.
-
unique index for several columns
Hi all
We have a requirement for our application, to add a single search box, which searches more than 1 table of different columns. The way in which we have now implemented, is the following (simplified example):
Select *.
WCP
where instr(ename,:SEARCH) > 0
or instr(job,:SEARCH) > 0
or...
This approach is relatively slow, of course. I want to change it, using the text of the Oracle. Can you give me advice what kind of index, must be used? Our requirement:
-index must continue to be up-to-date (a few seconds)
-research must be
-case insensitive preference
-number of columns to be indexed: aprox. 20 in a table
I heard once you can make a function, with all the columns you want to index. This function generates an xml document, and you can use this function to create an Oracle text index. However, I can't seem to find how I can implement that. Or is there a better aproach?
Thanks again for your help!You can use a multi_column_datastore, that generates xml documents as you describe in the scenes. You can also use the transactional option or sync (on validation) with optimization. See the simplified example with only two columns below that matches what you provided. You can find further information and examples for the multi_column_datastore in the online documentation.
SCOTT@orcl_11gR2> begin 2 ctx_ddl.create_preference ('emp_ds', 'multi_column_datastore'); 3 ctx_ddl.set_attribute ('emp_ds', 'columns', 'ename, job'); 4 end; 5 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> alter table emp add (any_column varchar2(1)) 2 / Table altered. SCOTT@orcl_11gR2> create index emp_idx 2 on emp (any_column) 3 indextype is ctxsys.context 4 parameters 5 ('datastore emp_ds 6 transactional') 7 / Index created. SCOTT@orcl_11gR2> variable search varchar2(100) SCOTT@orcl_11gR2> exec :search := 'CLARK' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> select ename, job from emp 2 where contains (any_column, :search) > 0 3 / ENAME JOB ---------- --------- CLARK MANAGER 1 row selected. SCOTT@orcl_11gR2> exec :search := 'CLERK' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> select ename, job from emp 2 where contains (any_column, :search) > 0 3 / ENAME JOB ---------- --------- SMITH CLERK ADAMS CLERK JAMES CLERK MILLER CLERK 4 rows selected.
-
Report view columns based on the selection of the month
Hello
I have an interactive report.
In my report, I show the columns below. Let's say the show for months salary of the EMP for this month
EmpID, ename, jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
I have two selection lists (to filter the report) in my interface. P1_MONTH and P1_YEAR. These have static LOVs.
Jan (Display) - 01 (Return)
(Display) - 02 Feb (Return) and so on.
I am facing problem while hiding under certain conditions the columns.
For example, if the user selects the month "Mar." Then the report should display
EmpID, ename, jan, Feb, mar
Another example, if the month is "Jun" then
EmpID, ename, jan, Feb, mar, Apr, may, June
So he must hide under certain conditions the columns based on selection.
I put the conditional 'view' in the column of the report for "expression of the ar-ticle/column value 1 = expression 2'.
P1_MONTH (in the expression 1)
+ 06,07,08,09,10,11,12 (in the expression for the month of June selection 2) +.
But doesn't the show/hide.
Am I missing something? Please correct me if I'm wrong.
I use APEX 4.1 & g 10 DB
Thank you in advance,
DanielThis
value of item/column expression 1 = expression 2
is equivalent to a PL/SQL expression, such as
:P1_MONTH = '06,07,08,09,10,11,12'
So maybe, select a PL/SQL expression condition and write something like that for the month of March - if I interpret correctly the your needs.
TO_NUMBER(:P1_MONTH) <= 3
Scott
-
How ItemRenderer change for DataGrid column based on the value of this column?
Hello! I am trying to create a DataGrid that has a component Button to register when the value of this column is 'Open', then a label saying full when the value of this column is "Full". But Im having a hell of a time he find.
Here's my MXML with 2 different inline installation of components for different rendering engines point 2:
<? XML version = "1.0" encoding = "utf-8"? >
"" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' layout = "absolute" >
< mx:Component id = "RegFull" >
< mx:VBox horizontalAlign = "center" verticalAlign = "middle" >
< mx:Label id = 'Full text' text = "Full" / >
< / mx:VBox >
< / mx:Component >
< mx:Component id = "RegButton" >
< mx:VBox horizontalAlign = "center" verticalAlign = "middle" >
< mx:Button label = "Save" / >
< / mx:VBox >
< / mx:Component >
< mx:DataGrid id = "scGrid" width = "100%" height = "100%" number of lines = "4" >
< mx:dataProvider >
< mx:Object label = "Status" data = 'Open' / >
< mx:Object label = "Status" data = "Full" / >
< mx:Object label = "Status" data = 'Open' / >
< mx:Object label = "Status" data = "Full" / >
< mx:Object label = "Status" data = 'Open' / >
< mx:Object label = "Status" data = "Full" / >
< / mx:dataProvider >
< mx:columns >
< mx:DataGridColumn id = "RegCol" headerText = "Reg" dataField = "data" / >
< / mx:columns >
< / mx:DataGrid >
< / mx:Application >
How can I dynamically use the right of itemrenderer based on the value of the field? THANKS FOR ANY HELP PROVIDED!
The best
StephenYou can have more than 1 column renderer engine. There are two ways to do this. One way would be to use States. A State for each possible value in the data. Since you either want a button (data == 'open') or a label (data == 'Full') by using the States wouldn't be a bad choice.
Alternatively, you can use a canvas instead of a VBox. Make a label and a button with horizontalCenter = "0" "0" = red to make them each other. Make it visible according to the data value:
where dataField is the value of the property dataField on this converter DataGridColumn.
-
Compare two columns and get the percentage of cells that match
Hello
I'm looking to take two columns of data from different tables in the same document, which should have a high enough percentage of boxes and have another cell tabulate the corresponding percentage. I can the of seem to figure out how to do this, but it seems really possible.
Any help is greatly appreciated.
Thank you!
C1 = A1 = B1
It's shorthand dethrone select cell C1 and type (or copy and paste it here) the formula:
= A1 = B1
Select cell C1, copy
Select the column C, paste
Select cell E2, and then type 'TRUE '.
Select cell E3 and then type "FALSE".
F2 = COUNTIF ($C, E2)
F3 = COUNTIF ($C, E3)
G2 = F2÷SUM(F$2:F$3)
G3 = F3÷SUM(F$2:F$3)
-
Hide column based on the State in BI Publisher Excel Template
Hello
I have a requirement to hide a column based on certain conditions in the Excel of BI Publisher model. I am newbie for BI Publisher excel template. Anyone can provide some advice on this?
I need this emergency. Any kind of help would be very appreciated.
Thank you
Renu
Hi Renu,
Recently, I came across a similar requirement, and I went to without BEEP features to hide and show columns during execution, unlike the RTF.
But I did it in Excel model with the help of the Macro. It works fine for me.
Please see below
1. based on a cell value 'A', I have to hide the column
2 written a simple if statement in macro to get the value of 'A' and do the hide/show
3. you need to do this only in "ThisWorkbook" macro is executed when the excel output is open.
Thank you
Mani
-
Hi all
Suppose I have table, whose structure changes frequently on a daily basis.
For example. / / desc my_table gives you after the name of the column the day 1
SQL > my_table DESC;
Output
Name
Age
Phone
Day 2, two other columns are added, viz, address and salary.
SQL > my_table DESC;
Output
Name
Age
Phone
Address
Salary
Now, I want to create a Dynnamic RTF report which made extracting data from all columns from my_table daily. For this, I have defined a simultaneous program with XML output type and include in annex a data/definition of data model that takes XML as input and gives the final result of the conc program in EXCEL layout. I am able to do that for a constant number of columns, but don't know how to do it when the number of columns to display dynamically changes.
For 1 day my XML file should be like this.
<?xml version="1.0" encoding="UTF-8"?> <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0"> <dataQuery> <sqlStatement name="Q2"> <![CDATA[ SELECT Name ,Age ,Phone FROM my_table ]]> </sqlStatement> </dataQuery> <dataStructure> <group name="G_my_table" source="Q2"> <element name="Name" value="Name" /> <element name="Age" value="Age" /> <element name="Phone" value="Phone" /> </group> </dataStructure> </dataTemplate>
And my day 1, EXCEL output RTF model should be like this.
Name age phoneSwapnill 23 12345
For 2 days my XML file should be like this. With 2 new columns selected in the SELECT clause.
<?xml version="1.0" encoding="UTF-8"?> <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0"> <dataQuery> <sqlStatement name="Q2"> <![CDATA[ SELECT Name ,Age ,Phone ,Address ,Salary FROM my_table ]]> </sqlStatement> </dataQuery> <dataStructure> <group name="G_my_table" source="Q2"> <element name="Name" value="Name" /> <element name="Age" value="Age" /> <element name="Phone" value="Phone" /> <element name="Address" value="Address" /> <element name="Salary" value="Salary" /> </group> </dataStructure> </dataTemplate>
And my day 2, exit EXCEL model RTF should be like this.
Name address telephone pay23 12345 Madrid 100000 Swapnill
Now, I don't know below things.
- Make the dynamic XML as we did in the day 1 there are 3 columns in the SELECT statement and the day 2, 5 columns. I want to create a dynamic XML which must not be changed if the new columns are added into my_table. I don't know how to create this query and also create their corresponding items below.
- Make the RTF model dyanamic as day 1 there are 3 exit EXCEL columns and the day 2, 5 columns. I want to create a dynamic RTF model that would display all the columns selected in XML dynamic. I don't know how the RTF will create new XML tags and how it will know where to place them in the report. Means, I can create model RTF day 1, by loading the XML data for 3 columns and place 3 tags XML in the model. But how he will create and place the tags for the new columns the day 2?
Hope so, you got my requirement, it's difficult. Please let me know how I can implement the necessary solution using the RTF dynamically without any manual intervention.
Kind regards
Patricia K.
Post edited by: SwapnilK
Hi guys,.
I was able to solve above the requirement.
I created a procedure that would create & update (attached to the data definition) XML file dynamically for each race. This dynamic XML contains the SQL statement for the data query that is built dynamically. I am updating this XML file using XDOLoader utility to the definition of data. Then run my program customized to generate the excel output.
Exit excel retrieves correct number of columns dynamically (3 on Day1 and Day2 5), with corresponding data records.
Kind regards
Patricia K.
Maybe you are looking for
-
Motorola i1 - default theme change?
I HAVE A MOTOROLA I1 AND I WOULD LIKE TO ADD MORE SCREENS TO MY THEME OF THE DEFAULT VALUE IS 3 SCREENS, I WANT TO BE ABLE TO ADD, BUT KEEPING THE SAME THEME IS THERE A WAY TO MODEFY OR CHANGE MY DEFAULT THEME? I ALREADY TRIED ADVANCED LAUNCHER BUT I
-
installation of streets &; trips using vista
set up ends, then said, your registry settings for this application were not copied correctly, does run configure again and the same problem. had no problem installing on my other pc with XP
-
Why I can't resize my partition Windows 7
I have a 500 gb hard drive installed on my system. It is partitioned as follows: By car System reserved 100 MB C; Windows 7 100 GB primary Primary data P: 292 GB Q: sw 15 GB logical downloads R: Logical Archives 10 GB More a box that says "
-
When you wipe your Q5 using BlackBerry protect, u can again your backup to get your phone to were it was before? I guess you can, but on the BlackBerry protect the say ' wipe your device will permanently delete all data on your device and your card,
-
Hello I implement an application with function Push for OS 5 and above, and I have a problem: when the application does not, when a message arrives, I'm processing (for now I log in only a few details) in a different thread, but when I am clicking on