Constraint based on existing values for a column in the table
I have a table as follows
create table MS_FAV_ACCT
NICKNAME VARCHAR2(50) not null,
ACCOUNT VARCHAR2(6) not null,
SUB_ACCOUNT VARCHAR2(3) not null,
DETAIL VARCHAR2(4) not null,
ICID VARCHAR2(3) not null,
SEGMENT VARCHAR2(2) not null,
PRIMARY_ACCT VARCHAR2(1) not null
I want to have a constraint such that there can be only one row with PRIMARY_ACCT ='Y' there could be multiple rows with value 'N'.
I have put a CHECK constraint on this column to check for values Y or N but I want to be able to check this condition too that only one row can have PRIMARY_ACCT as Y .
I saw a thread on this forum regarding using UNIQUE INDEX with case when but didnt understand how I could use it in my case.
Could anyone please help?
You only want to have 1 row in the table with an identifier of 'Y'?
That is what i understood, in which case you can use something like this.
ME_XE?create table MS_FAV_ACCT
2 (
3 NICKNAME VARCHAR2(50) not null,
4 ACCOUNT VARCHAR2(6) not null,
5 SUB_ACCOUNT VARCHAR2(3) not null,
6 DETAIL VARCHAR2(4) not null,
7 ICID VARCHAR2(3) not null,
8 SEGMENT VARCHAR2(2) not null,
9 PRIMARY_ACCT VARCHAR2(1) not null
10 );
Table created.
Elapsed: 00:00:00.03
ME_XE?CREATE UNIQUE INDEX MS_FAV_ACCT_U01 ON MS_FAV_ACCT (CASE WHEN PRIMARY_ACCT = 'Y' THEN 1 ELSE NULL END);
Index created.
Elapsed: 00:00:00.01
ME_XE?
ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','N');
1 row created.
Elapsed: 00:00:00.00
ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y');
1 row created.
Elapsed: 00:00:00.00
ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','N');
1 row created.
Elapsed: 00:00:00.01
ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y');
INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y')
ERROR at line 1:
ORA-00001: unique constraint (TFORSYTH.MS_FAV_ACCT_U01) violated
Similar Messages
-
Add user-entered "Fill-In" values for "Choice" column to the list of available choices?
I have a "Choice" column in SharePoint where users need to select a name for a specific engagement when uploading a document. Since new engagements come up all the time, they need to be able to enter a new value and have that value available
to select as a Choice from the list the next time they upload a document. Is this possible in SharePoint?
Our organization does not allow custom code using Visual Studio, but I do have access to SharePoint Designer.Hello!
All available choices are specified in the list's schema. I.e. the "Choice" column is designed to operate with predefined values that are set in the schema. Of course, you can every time add a new choice to the list's schema programmatically, but that's a worst
practice.
In your case I suggest to add a list (kind of dictionary) containing all values available to pick out. Then, instead of "Choice" column, use "Lookup" column which points to the dicitionary-list. Once a new value is entered, add a new list item to the dictionary.
Next time this value will be available to pick out.
.Net Follower (http://dotnetfollower.com) -
Pro*C & SQLDA with NULL value for predicate column
Hi: I am using a C program to update a table via a dynamic sql (method 4) and SQLDA. In the update statement predicate, I have place holders (as in TBLCOL=:C000). One of the columns in the predicate contains null values, so I set L[n] = 0, V[n] = pData (which pData[0] = '\0'), *(I[n]) = -1, and T[n] = 5 (for text). I cannot find the row that I know is there.
I cannot change my statement to contain TBLCOL IS NULL, since I don't know ahead of time if I'm looking for rows with null values for this column. The Pro*C manual says that by setting the appropriate *(I[n]) = -1, it indicates to Oracle to simulate the "IS NULL" clause, and update the appropriate rows. In my case, I receive 1403 as SQLCODE when I use TBLCOL=:C000 vs TBLCOL IS NULL. What am I doing wrong? Thank you for your help.You should include these columns as well;
ChangeType (see mxi_changetype)
ValOwner (repository)
UserID ("jobid=<>", usermskey, GUI (mmc), DG (dyngrp), reconcile)
IdAudit (This is the event task (add and del member for assignments)
ParentAuditId (AuditID of parent which last updated the attribute, not consistent)
ChangedBy (Holds the MSKEY of the user which last changed the attribute)
ExpiryTime
to make sure you get a fuller picture of the audit record.
Your selection does not cover all events and descriptions
br,
Chris -
How to set default values for boolean columns
I'm trying to deploy some content types and columns into a site with a feature. All it's ok, except that I'm trying to set a default value for boolean columns with no success.
I've tried to set default value at column level:
<Field ID="{EFE23A1D-494E-45cf-832E-45E41B17F0CF}" Name="ScopeSpanish" DisplayName="Se publican noticias en español"
Type="Boolean" Hidden="FALSE" Group="Columnas ShaCon" >
<Default>TRUE</Default>
</Field>
and at content type level:
<FieldRef ID="{EFE23A1D-494E-45cf-832E-45E41B17F0CF}" Name="ScopeSpanish" DefaultValue="TRUE" Required="TRUE" />
But in any case, when i create a new item with this content type, default value is applied.
Can anyone tell how to set default values for boolean columns?
Thanks in advance,
Regards,
SergioIn the field definition you can set
<Default>1</Default>
or
<Default>0</Default>
How to set the default value Null? -
Hide row values for certain column in GRR2
Hi Experts,
Looking for some help in report painter. I need to hide row values for certain columns in report painter. The requirement is I have 5 columns in the report, the 5 th column is the sum of col 1 to 4 and in my row i have a formula setup to sum of values for each column, what i would like to do is for column 1 thru 4 i didnt want to display the total values in row total but i wanted to dispaly value for column 5 in row total. I have been trying my best with putting formula, but couldnt succeed.
Could somebody let me know is there an way to get this addressed.
Thanks in advance
Best Regards,
gjHow was it achieved ? Did you use sections for the columns for which rows needed to be hidden?
I have a smiliar issue of hiding certain rows for few columns. -
Calling a user defined function as default value for a column
Hi All
Can we call a user defined function as default value for a column ??
for example:
create or replace function test1 return number is
begin
return 10;
end;
create table testt
(id as test1,
name varchar2(20));
getting error:
Error at line 1
ORA-02000: missing ( keywordThanks
Ashwani
Edited by: Ashwani on Jan 16, 2012 1:19 AMHi;
For your issue i suggest close your thread here as changing thread status to answered and move it to Forum Home » Database » SQL and PL/SQL which you can get more quick response
Regard
Helios -
Using default values for a column
Hi,
I am using PL/SQL Developer, where for some columns in a table I've defined 0 as default value.
After running some queries on the table (insert,update) I realized that all the columns that are supposed to have 0 value (default), actually have NULL value.
Please advice about possible reason.
ThanksHi,
You might have explicitly inserted a NULL value in those columns. Have a look at the below test case:
SQL> create table test(a number, b number default 0, c number default 1);
Table created.
SQL> insert into test (a) values (10);
1 row created.
SQL> select * from test;
A B C
10 0 1
SQL> insert into test (a, b) values (10, null);
1 row created.
SQL> select * from test;
A B C
10 0 1
10 1
SQL> insert into test (a, b, c) values (10, null, null);
1 row created.
SQL> select * from test;
A B C
10 0 1
10 1
10
SQL> insert into test (a) values (20);
1 row created.
SQL> select * from test;
A B C
10 0 1
10 1
10
20 0 1Regards -
Change Account Workflow in CUP - Doesn't pick up existing values for an Acc
Hi,
When using the change account option available in the CUP(5.3 SP 7), I expected the system to populate the user details as they exist in the provisioning system once I enter the account details that need a change. We have the 'Search' and 'User Details' Data source configured to the same SAP R/3 system.
For eg, when requesting for a new account, I've chosen an Employee Type attribute as 'Non-Employee' (SAP delivered request attribute) and entered some values for my custom attributes .
And when I chose to change the same user account, I notice that the system doesn't pick up the existing values for any of the attributes and render them. For the Employee Type attribute, it shows the default value and for the custom fields, they are shown blank!!!!
It does seem like the user attribute values from R/3 are being picked up and displayed correctly, but the ones from GRC Database are left out.
I believe this to be a bug and does anyone experienced this issue and found a fix????
Thanks,
AnilHi Alpesh,
Thanks for your response.
This brings up a basic question on the repository for saving user attribs...ie. does all these need to be saved on R/3? Assuming yes depending on our current configuration(We have the 'Search' and 'User Details' Data source configured to the same SAP R/3 system), do we have a standard field for saving the 'Employee Type' attrib in SAP?. I did perform a field mapping of a custom attirb to one of the SAP fields in the user master, and get it saved during user provisioning. But it doesn't pick it up from there when I perform a change account. Seems it's missing that reverse mapping. And I've chosen the 'Field Type' of the custom filed to Text as to enable free text during new account request.
Hope you may find something more.
Regards,
Anil -
Default value for a column in Table Control
Hi friends, can i set dinamcally a default value for a column in table control?, this column is check type. This default value must appear in empty rows,
thanksADD A MODULE AS Module yyyy In ur PAI.
as
In PAI.
LOOP at itab.
Module YYYY
ENDLOOP.
Module YYYY.
LOOP AT SCREEN.
IF SCREEN-NAME = 'ITAB-VAL.
ITAB-VAL = 'XXXXXXXX' "(DEFAULT VALUE)
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
End module.
*note
make this event work only if the previous column is filled okay.
the display will be in display mode on the screen as screen-input = 0.
see that in the table control u can get the table field for all the rows even though you are processing on some fields .
so what u do is make that particular filed masked(no i/p field and populate the field that will be better instead of populating all the columns okay.
hope this helps you out ,
regards,
vijay. -
Default Value for a column in matrix
Hi,
How to set default value for a column in matrix which is of type combo(Yes/No).
The cell has combo in it
ManojHi Manoj,
The column is set as combo. Now you need to tell SBO what constituates a Y or N. In my example my Column "Col6" must display Yes if the RENTED column = 1 and No if the RENTED column = 0. (I'm obviously using a datasource to tie the data to the matrix)
oMatrix = frm.Items.Item("YourMatrixID").Specific
oColumns = oMatrix.Columns
oColumn = oColumns.Item("Col6")
oColumn.DataBind.SetBound(True, "@VIDEO", "U_RENTED")
oColumn.ValOn = "1"
oColumn.ValOff = "0" -
Setting default values for a column
Hi,
I have a table having some default values for the columns. I am using a PreparedStatment to insert into this table. For null values I am using setNull(..) method but the default values given for the columns are not inserted for null values.
eg: INSERT INTO TEST VALUES(?,?);
where TEST table contains two columns col1 and col2 with default values 'AA' and 'BB' respectively. My requirement is to make sure that when null values are specified for the columns then the database default should be picked up. using setNull(..) method doesn't help.
Thanks in advance.
GyanDefault value for a column can be picked up from DatabaseMetaData class.
The below snippet shows that: -
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getColumns(null, null, "TEST", "COL%");
while ( resultSet.next() )
String defaultValue = resultSet.getString("COLUMN_DEF");
String datatype = resultSet.getString("DATA_TYPE");
System.out.println("defaultValue = " + defaultValue);
System.out.println("datatype = " + datatype);
} -
Need to compare values in two columns of one table against values in two columns in another table
Hi, as the title reads, I'm looking for an approach that will allow me to compare values in two columns of one table against values in two columns in another table.
Say, for instance, here are my tables:
Table1:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SEAN
FEDCBA,SHAWN
Table2:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SHAWN
In comparing the two tables, I'd like my query to report the rows in table1 NOT found in table2. In this case, it'll be the 3rd row of table one:
Server,Login
FEDCBA,SEAN
Thanks.create table Table1([Server] varchar(50), Login varchar(50))
Insert into Table1 values ('ABCDEF','JOHN'),('ABCDEF','JANE'),('FEDCBA','SEAN'),('FEDCBA','SHAWN')
create table Table2([Server] varchar(50), Login varchar(50))
Insert into Table2 values ('ABCDEF','JOHN'),('ABCDEF','JANE'), ('FEDCBA','SHAWN')
select [Server] ,Login from Table1
Except
select [Server] ,Login from Table2
select [Server] ,Login from Table1 t1
where not exists(Select 1 from Table2 where t1.[Server] = t1.[Server] AND Login=t1.Login)
drop table Table1,Table2 -
Associative array type for each blob column in the table
i am using the code in given link
http://www.oracle.com/technology/oramag/oracle/07-jan/o17odp.html
i chnages that code like this
CREATE TABLE JOBS
JOB_ID VARCHAR2(10 BYTE),
JOB_TITLE VARCHAR2(35 BYTE),
MIN_SALARY NUMBER(6),
MAX_SALARY NUMBER(6),
JOBPIC BLOB
CREATE OR REPLACE PACKAGE associative_array
AS
-- define an associative array type for each column in the jobs table
TYPE t_job_id IS TABLE OF jobs.job_id%TYPE
INDEX BY PLS_INTEGER;
TYPE t_job_title IS TABLE OF jobs.job_title%TYPE
INDEX BY PLS_INTEGER;
TYPE t_min_salary IS TABLE OF jobs.min_salary%TYPE
INDEX BY PLS_INTEGER;
TYPE t_max_salary IS TABLE OF jobs.max_salary%TYPE
INDEX BY PLS_INTEGER;
TYPE t_jobpic IS TABLE OF jobs.jobpic%TYPE
INDEX BY PLS_INTEGER;
-- define the procedure that will perform the array insert
PROCEDURE array_insert (
p_job_id IN t_job_id,
p_job_title IN t_job_title,
p_min_salary IN t_min_salary,
p_max_salary IN t_max_salary,
p_jobpic IN t_jobpic
END associative_array;
CREATE OR REPLACE package body SHC_OLD.associative_array as
-- implement the procedure that will perform the array insert
procedure array_insert (p_job_id in t_job_id,
p_job_title in t_job_title,
p_min_salary in t_min_salary,
p_max_salary in t_max_salary,
P_JOBPIC IN T_JOBPIC
) is
begin
forall i in p_job_id.first..p_job_id.last
insert into jobs (job_id,
job_title,
min_salary,
max_salary,
JOBPIC
values (p_job_id(i),
p_job_title(i),
p_min_salary(i),
p_max_salary(i),
P_JOBPIC(i)
end array_insert;
end associative_array;
this procedure is called from .net. from .net sending blob is posiible or not.if yes howOk, that won't work...you need to generate an image tag and provide the contents of the blob column as the src for the image tag.
If you look at my blog entry -
http://jes.blogs.shellprompt.net/2007/05/18/apex-delivering-pages-in-3-seconds-or-less/
and download that Whitepaper that I talk about you will find an example of how to do what you want to do. Note the majority of that whitepaper is discussing other (quite advanced) topics, but there is a small part of it that shows how to display an image stored as a blob in a table. -
To set a dropdown list for one column in the excel file before downloading
Hi all,
I am downloading an excel file which has the format of an internal table with a number of fields. I want to set a dropdown list for one column in the excel file. How can i do this?
ThanksHI ,
U can use function module " QINT_GET_EXCEL_DATA " ....
and modify the excel sheet based on ur requirement ......
Try this ...
Hope it works
Thanks
Shambhu -
The column in the table do not match an existing primary key
I've got two tables tbl_Workshop and tbl_Material
tbl_Workshop has columns workshopID, workshopTitle, materialID
tbl_Material has materialID, name, workshopTitle
when I'm trying to create a relationship between the workshopTitle of tbl1 and tbl2, it gives me an error that says the column in the table do not match an existing primary key.
What could be the reason for this error and how to overcome it.
ps. The datatypes and names of both the table's column match.Have you created primary key on workshopTitle column in tbl_Workshop
You can add foreign key relationship from tbl_Material.workshopTitle
to tbl_Workshop.workshopTitle
only if latter is a primary key of the table.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Maybe you are looking for
-
How do I change the phone number in the setup of my keychain?
I put the wrong phone number in my keychain at setup and need to change it. I am fairly new to MAC and need help with this issue,PLEASE!
-
Please answer a programming question for an admin
I'm not a programmer (although my interest is growing), so I can't answer this question in a discussion regarding how Win32API w/OLE and COM is SO much better than programming for Unix/OS X applications. The original discussion was in regards to OS X
-
Is there a similar function in Edge Animate that is similar to the draw path function in After Effects?
-
What's a SHAREDCONTENT.RPLN ?
Hi, I am currently working with indesign 5.04. I have recently received a file from a client that is asking for the "SHAREDCONTENT.RPLN" when I attempt to open the file. Any ideas what this may be? Or how to solve this? I also have a contact that has
-
SAP Workflow integrated with Microsoft Outlook
Hello All, I have the following question. When an work item comes in the SBWP inbox, as soon as the work item is executed by the user the workitem disappears from the SBWP. Now my question is if SAP Workflow is integrated with Microsoft Outlook (so t