Implement Conditional Read-Only of Column Across Two Tables
Hello,
I would like to implement a "conditional read-only" mechanism on a column in a table with two tables in total being involved in this situation.
I have a demo/proof of concept of this and things are working as expected in the tests I have performed; however, I would like any input as to whether there is a better way, etc.
Here's a contrived demo but which illustrates the key ingredients nevertheless. Oracle version 10.2.0.4 64-bit on Windows Server 2008 Release 2 64-bit.
- Table DDL and small sample data
create table band(
band_id number primary key,
band_name varchar2(20),
status varchar2(20)
create table band_member(
band_id references band,
member_name varchar2(20)
insert into band values(3, 'The Rutles', 'prefab4');
insert into band values(4, 'The Beatles', 'established');
commit;
insert into band_member values(3, 'Ron Nasty');
insert into band_member values(3, 'Dirk McQuickly');
insert into band_member values(3, 'Stig O''Hara');
insert into band_member values(3, 'Barrington Womble');
commit;
insert into band_member values(4, 'John Lennon');
insert into band_member values(4, 'Paul McCartney');
insert into band_member values(4, 'George Harrison');
insert into band_member values(4, 'Ringo Starr');
commit;- The rules regarding the conditional read-only goal
1. Not permitted to update band.band_name when band.status='prefab4'
2. Not permitted to insert/update/delete any rows in band_member when the parent row has band.status='prefab4'
- Triggers used to implement the goal (current solution)
create or replace trigger t1
before update of band_name on band
for each row
when (old.status = 'prefab4' or new.status = 'prefab4')
begin
raise_application_error(-20010,
'can not update band_name when status=''prefab4''');
end;
create or replace trigger t2
before insert or update or delete on band_member
for each row
declare
l_status band.status%type;
l_band_id band_member.band_id%type;
cursor l_cursor (p_band_id number) is
select status from band
where band_id = p_band_id
for update;
begin
if updating or inserting then
l_band_id := :new.band_id;
else
l_band_id := :old.band_id;
end if;
open l_cursor(l_band_id);
fetch l_cursor into l_status;
close l_cursor;
if l_status = 'prefab4' then
raise_application_error(-20011,
'can not update child when parent status=''prefab4''');
end if;
end;
/- Quick sample test for each condition
update band
set band_name = 'THE RUTLES'
where band_id = 3;
update band
ERROR at line 1:
ORA-20010: can not update band_name when status='prefab4'
ORA-06512: at "DEMO.T1", line 2
ORA-04088: error during execution of trigger 'DEMO.T1'
update band_member
set member_name = 'RON NASTY'
where member_name = 'Ron Nasty';
update band_member
ERROR at line 1:
ORA-20011: can not update child when parent status='prefab4'
ORA-06512: at "DEMO.T2", line 18
ORA-04088: error during execution of trigger 'DEMO.T2'As I say, whilst my simple tests look to show the correct results, I'm left wondering if there might be a better way to implement said functionality.
I've attempted to provide the required information, but if I've managed to omit anything, please let me know.
Cheers,
Chalfont
Hi, Chalfont,
user13146957 wrote:
I went the cursor route to add the "for update" clause to force serialisation on the row - i.e. the idea was to avoid the case where another session might have wanted to update the status an instant after my fetch but before the remainder of the code completed. Does that make sense?No not really. The trigger on band prevents anyone from ever changing status from 'prefab4' to anything else (or vice-versa).
Even aside from that, you're putting in some effor to prevent something that will be allowed a split second later (or maybe the other way around). What's so significant about that split second?
I've been thinking of other ideas rather than the trigger approach, but have come up empty, as it were, thus far. I'm open to using other approaches and making some schema changes is not off the table either.FGA (Fine Grained Access), or its older sibling VPD (Virtual Private Database) can also do what you want, but, instead of raising an error, they just ignore the illegal action. This may be an advantage or a disadvantage, depending on your requirements.
Another approach is for the owner of the table not to grant INSERT, UPDATE or DELETE privileges to anyone: all DML must be done through a procedure (or procedures) owned by the table owner, who grants EXECUTE privileges instead of the other privileges.
Similar Messages
-
11GR2
=-----------------------------------
I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
begin
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', TRUE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES', FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',FALSE);
End;
select REGEXP_REPLACE(dbms_metadata_diff.compare_alter('TABLE','TABLE_NAME_A','TABLE_NAME_A','USER1','USER2'),('USER1...'),'', 1, 0, 'i') from dualI am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
If you want help you have to SHOW us what you are doing and how you are doing it; you can't just try to tell us in your own words.
We can't see your computer screen. -
How to read only particualr columns from excel sheet to internal table
Hi,
I have and excel sheet which has around 20 columns, in which i want to read only 6 columns. They are at different column positions, means the 1st column, 6thcolumn, 8th column so on..
Can we do this in sap? do we have any FM to do this?
Thanks.
Praveena.hi,
Use the below logic to fetch the data into internal table..You need to read the data cell by cell and update the internal table,
DATA l_count TYPE sy-tabix.
CONSTANTS: lc_begin_col TYPE i VALUE '1',
lc_begin_row TYPE i VALUE '2',
lc_end_col TYPE i VALUE '2',
lc_end_row TYPE i VALUE '3000'.
CLEAR p_i_excel_data. REFRESH p_i_excel_data.
* Function module to read excel file and convert it into internal table
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_p_file
i_begin_col = lc_begin_col
i_begin_row = lc_begin_row
i_end_col = lc_end_col
i_end_row = lc_end_row
TABLES
intern = i_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
* Error in file upload
IF sy-subrc NE 0 .
MESSAGE text-006 TYPE 'E'.
EXIT.
ENDIF.
IF i_data[] IS INITIAL .
MESSAGE text-007 TYPE 'E'.
EXIT.
ELSE.
SORT i_data BY row col .
* Loop to fill data in Internal Table
LOOP AT i_data .
MOVE i_data-col TO l_count .
ASSIGN COMPONENT l_count OF STRUCTURE p_i_excel_data TO <fs_source> .
MOVE i_data-value TO <fs_source> .
AT END OF row .
* Append data into internal table
APPEND p_i_excel_data.
CLEAR p_i_excel_data.
ENDAT .
ENDLOOP .
ENDIF . -
Modifying datatype of columns across multiple tables
Hi,
I have a requirement where-in I have to modify the datatypes of columns across multiple tables. Is there any direct way to do this? I mean does oracle has any function or in-built functionality to achieve this.
Example;
Table1 -> col1 datatype needs to be changed to varchar2(10)
Table2 -> col2 datatype needs to be changed to varchar2(30)
Table3 -> col3 datatype needs to be changed to number.
and so on....
Do we have such functionality?
Thanks,
IshanHi Aman,
Seeing the replies, I think I was unclear in the requirements. But I guess you understood it fully, but still I would like to restate my question once again, just to be 100% sure.
What I actually want is that in one shot, I would be able to modify columns of multible tables.
eg, table1-> col1 changed to varchar2(20);
table2->col2 changed to varchar2(10)
table3-> col3 changed to number;
I know how to do it individually, but just wanted to check, if only one command can modify the datatypes of multiple tables/.
If not, I have already written half the script, but just for knowledge sake wanted to check if some feature is available in oracle for that.
Regards,
Ishan -
Read-Only Access to Specific SAP tables
Is it possible to grant a user read-only access to a specific table or tables?
For example, say I wanted to give someone SE16N capability for just EKKO/EKPO/EKBE and NO OTHER tables. Is this possible? How?
Thanks.Hi,
as it was mentioned the transaction SE16N checks for authorization object S_TABU_DIS. The problem in your case is that the tables EKKO, EKPO and EKBE are already assigned to the authorization group MA - MM Appl. table. But there are many more tables assigned to this group. Changing assignment of standard tables is not a good idea.
Cheers -
Hi
how to create a external content type for Read and Update data from two tables in sqlserver using sharepoint designer 2010
i created a bcs service using centraladministration site
i have two tables in sqlserver
1)Employee
-empno
-firstname
-lastname
2)EmpDepartment
-empno
-deptno
-location
i want to just create a list to display employee details from two tables
empid firstname deptno location
and same time update in two tables
adilWhen I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list. When I attempt to edit it, I get an error:
External List fails when attached to a SQL view
Sorry, something went wrong
Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
I can edit the view in SQL Manager, so it seems strange that it fails.
Any advice would be greatly GREATLY appreciated.
Thanks,
Randy -
How to update two columns in two tables?
hi friends
I have two tables linked to each other through SaleNo and SaleDT. their structure as below
Sales Table============
SaleNo int PK auto increment
SaleDT Datetime PK
Qnty decimal
Units decimal
Invoices table
=================InvoiceNo int PK Auto incremented
InvoiceDT Datetime
SaleNo int FK
SaleDT Datetime FK
Note that SaleDT column is NOT assigned with getDate() expression.
1. what I need to do is update the SaleDT column of Sales table and Invoices table with the value '2013-01-31 10:31:55.813', how do I do this without manually breaking the link between the tables?
2. Assume SaleNos 15 to 27 needs update the SaleDT to '2013-06-12 10:31:55.813', how do I do this complex operation where I I have update SaleDt column of two table of SaleNo range from 15 to 27?
thanks
I use Visual studio 2012 Ultimate and SQL server 2008 developer edition!Why not below? May be you will not be able to change your design now, but just want to share.
Sales Table============
SALEID int PK autoincrement
SaleNo int
SaleDT Datetime
Qnty decimal
Units decimalUNIQUE (Saleno,SaleDT)
Invoices table
=================InvoiceNo int PK Auto incremented
InvoiceDT Datetime
SALEID int FK -
Selecting columns from two table is slow but same
I am selecting 27 columns from two tables
which running for more than 30 minutes. but
if I select count(*) with the same query
except the columns it is coming in seconds.
Where is the error?If you post
1) The table definitions for the underlying tables
2) The indexes that are on the tables
3) The two SQL statements you're running
4) The explain plan for both statements
we can probably be of some assistance.
My guess is that the count(*) is able to return much more quickly because the optimizer is able to use a significantly faster query plan that is based on an index which the longer-running query cannot utilize. Without the information I've requested, though, it's hard to do more than speculate.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to Find Two Matching Columns in Two Table(to create a JOIN)
Hi Guys!
I just wondering if it is possible to have a SQL query to find two matches columns in two table to create any type of joins?!
Let's say I have two tables CUSTOMER + INVOICE is it possible to run a SQL query to find two join able columns without scanning the tables visually?!
Best Regards,Well, there's the Data Dictionary you could query for foreign key columns/constraints.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:661009003696 -
Hi,
I have several simple look up tables with two columns, ID and DESCRIPTION.
ID is a numeric primary key.
They have been put into their own groups with the Layout Style set to "table".
The ID attribute's "Updateable?" has been set to "When New".
My problem is that when I go to the pages that edit these tables, some of the ID columns
are editable while some of the ID columns are read-only. I want all of the ID columns
to be read-only (except for the new row).
The ID attribures look identical in the ADF BC Properties Editor for all of the tables.
Where else should I look for differences?
Cheers,
Patrick CimoliniPatrick,
Actually, the line should not be present in the View Object file. Only if it is cleared, the value from the Entity Object should be picked up. I have experimented a bit and I could reproduce one weird case.
Start by going to the Entity attribute and set it to 'Always'. Then go to the View attribute and set it to 'Always' as well. Now check the ViewObject xml file. The 'isUpdateable' attribute should NOT be there now! If it is, something weird is going on and I would close JDev, remove the attribute in notepad and launch JDev again.
In the next bit, take care you follow the steps in this exact order. Go to the View Object attribute, and set it to 'While New'. Go to the Entity Attribute and set it to 'Never'. Go back to the View Object attribute. It will now be set to 'Never' and you won't have the option to put it back to 'While New' or 'Always' (greyed out). All very nice and logical, but if you look at the View Object XML file, it still says 'isUpdateable="while_insert"'. This is indeed an inconsistency between the JDev GUI and the actual XML file. As JHeadstart uses the XML file, it will use the 'while_insert' instead of the 'Never' that both the Entity and ViewObject GUI are showing you.
However, this is the only problem I have found. Could you please make sure that if you set everything back to 'Always', if necessary remove that 'isUpdateable' attribute from the ViewObject XML file as I mentioned above, then only set the 'While New' at the Entity level, and make sure that the 'isUpdateable' property is NOT present at the ViewObject XML file, if everything works as expected when running the generator?
Kind regards,
Peter Ebell
JHeadstart Team -
Conditional read only radiogroup item losing value when saving
Apex 3.2
I have a radiogroup item that is set to read only after it's populated and the user is not in the ADMIN Role. When non ADMIN users edit the page, it shows the value and they cannot change it, but if they save the page, it loses the value. Works fine if the user has ADMIN role.
This is the Pl/SQL function in the "Item is read only when" section
begin
if :p3_event_detail_id is not null and :p3_notification_period_id != -1 and not apex_util.public_check_authorization('ADMIN') then
return true;
else
return false;
end if;
end;
There is also a Not Null validation on this radiogroup item.
I changed the item type to select list and it works fine, but user like the radiogroup button.
Any ideas?It's using a shared component LOV cleverly called LOV_YN which consists of a static LOV with
1 Display=Yes, Return=Y
2 Display=No, Return=N
The settings in the LOV section on the item iteself:
Named LOV: LOV_YN
Display Extra values: No Dynamic translation: Not translated
Number of columns: 2 Display null: No
Null display value is blank as is null return value
Item was setup as a radio group and was only converted over to a select list to work around this issue. Let me know what else you need and thanks again.
Rgds/Mark M. -
BULK INSERT from a text (.csv) file - read only specific columns.
I am using Microsoft SQL 2005, I need to do a BULK INSERT from a .csv I just downloaded from paypal. I can't edit some of the columns that are given in the report. I am trying to load specific columns from the file.
bulk insert Orders
FROM 'C:\Users\*******\Desktop\DownloadURL123.csv'
WITH
FIELDTERMINATOR = ',',
FIRSTROW = 2,
ROWTERMINATOR = '\n'
So where would I state what column names (from row #1 on the .csv file) would be used into what specific column in the table.
I saw this on one of the sites which seemed to guide me towards the answer, but I failed.. here you go, it might help you:
FORMATFILE [ = 'format_file_path' ]
Specifies the full path of a format file. A format file describes the data file that contains stored responses created using the bcp utility on the same table or view. The format file should be used in cases in which:
The data file contains greater or fewer columns than the table or view.
The columns are in a different order.
The column delimiters vary.
There are other changes in the data format. Format files are usually created by using the bcp utility and modified with a text editor as needed. For more information, see bcp Utility.Date, Time, Time Zone, Name, Type, Status, Currency, Gross, Fee, Net, From Email Address, To Email Address, Transaction ID, Item Title, Item ID, Buyer ID, Item URL, Closing Date, Reference Txn ID, Receipt ID,
"04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392302", "jdal32", "http://ddd.com", "04/22/03", "", "",
"04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392932930302", "jejsl32", "http://ddd.com", "04/22/03", "", "",
Do you need more than 2 rows? I did not include all the columns from the actual csv file but most of it, I am planning on taking to the first table these specfic columns: date, to email address, transaction ID, item title, item ID, buyer ID, item URL.
The other table, I don't have any values from here because I did not list them, but if you do this for me I could probably figure the other table out.
Thank you very much. -
Render column read only after save in advanced table.
I have advanced table in my region. Right now, I have col1 & col2 both messageinputtext and adding new row works,
This is what I want to do :
When page loads, render col1 read only, (right now it pulls in data, with col1 as text field, I dont want the user to change data in col1, once he has saved it)
When user presses addRow button in table footer, it adds a row with col1 as input field, but when user is done inputting and clicks 'apply changes' button , col1 in all the rows become read only.
how can I do it programatically ?
thanksNow You have to capture the logic of AddRow button. Say you are handling its logic in AMImpl.
PFR of Controller:-->
processFormRequest
if ((table.Bean.getName().equals(source)) && (ADD_ROWS_EVENT.equals(event)))
// invoke method on view instance that will add 5 rows
In AMimpl:-
if (vo.getFetchedRowCount() == 0)
// We want to initialize the VO with the call to setMaxFetchSize()
// only before we add the first row. If we add subsequent rows,
// we don't want to call this again, which is way it's enclosed
// in the IF check.
vo.setMaxFetchSize(0);
// Perform insert
Row row = vo.createRow();
vo.insertRow(row);
// If this view object is transactional, you must also comply with
// Model Coding Standard M69 by setting the new row state to
// STATUS_INITIALIZED. Note that there is no harm in including
// this line of code in non-transactional view objects if you
// find it easier to follow a single coding pattern for all your
// view objects.
row.setNewRowState(Row.STATUS_INITIALIZED);
vo.reset();
vo.next();
Here try to do like this
OARow row = (OARow)vo.getCurrentRow;
OAViewObject pVO = (OAViewObject)findViewObject("macsfaqPVO1");
OARow poRow = (OARow)pVO.getCurrentRow();
poRow.setAttribute("QuestionColFlag", Boolean.FALSE);
Thanks
--Anil -
How to make a field conditional Read Only
Hi,
There is a "Close date" field. I need to check if the date today, and the "Close date" falls in the same quarter. If it does, then, a particular field has to be made editable otherwise not.
(Better, if it could be done by using business component user properties)Hi,
Surely i can give you details.
The LOV Type is - QTR_DET which has the following values -
1.Description - 04/03/2009 & Display Value - "Q2-2009"
2.Description - 07/05/2009 & Display Value - "Q3-2009"
3.Description - 10/02/2009 & Display Value - "Q4-2009"
These 4 quarter values are updated for every year
Hence, I need to compare values, on the basis of these values.
The Quarter for the Close Date has to be compared to Quarter which includes "Today"
As far as i know, JulianQuarter divides the year into exactly 4 parts, but as you can see, the values are not same as the quarter values, i need to use.
It would be surely great if you could help me solve this, as i am new to siebel.
I was trying to try with Lookup as well.
(The Following way, i was trying, but did not work
-Field1 is a calculated field - Lookup(QTR_DET,[Close Date])
-Field2 is a calculated field - Lookup(QTR_DET,Today())
-InPresentQuarter is a calculated field - IIF((Field1 = Field2), "N", "Y")
And this was further used for the Field Read Only Field: [Field Name] to make it read only)
Also please let me know, if this is the right way. -
Microsoft files Read-only when sharing between two Macs
I'm trying to share Excel files between my Macbook and my iMac. The files are located on my macbook and I've given read/write permission to the folder containing the files. When I try to open the files on my iMac they open as read only. This happens with Excel, Word and Power Point files.
How do I configure the file sharing so I can open Microsoft files without them being Read only.
I'm using Office:mac 2004 and both the Macbook and iMac are running OS X (10.5.6)There have been occassions where I have wanted to transfer something from the MBP to the Mini or vice-versa over wi-fi and have encountered problems. I suspect this is because I am using the same user account and they get confused.
Could you please explain, what kind of problems exactly you encountered? Error messages? Corrupted files? And why do you think the problem is caused by the same user profiles?
Like markwmsn I have no problem with sharing using the same account name on all my macs. Only since upgrading to Mt. Lion I usually use AirDrop to send single files. That saves the trouble to copy the files to a public folder.
Do both your macs support Air Drop?
OS X Lion: Share your files with others near you
and the requirements: HT5444
Regards
Léonie
Maybe you are looking for
-
Airprint with HP C4180 All-in-one Printer
I am currently thinking about upgrading my iPhone 3GS to the 4.2 software and undecided. If I do so, would I be able to print from iPhone to my HPC4180 All-in-one Printer? In order to use Airprint, do you have to have an Airport? Thanks in advance. M
-
i have 3 servers which are run on windows server 2003 and solaris 10...So, i need to setup vlan in each server. Our network will used ipv6 and ipv4 protocols.. The problem is i really dunno how to setup the network and interconnect between ipv4 and i
-
Hello, My computer is hooked up to my school ethernet system. I just bought a new computer with leopard and the built-in camera, which works fine. I've been trying to chat with my friend who has comcast high-speed internet service (with a netgear wir
-
Unable to invoke java proxy in PI 7.1
Hi , I am using NWDS 7.2 (Trial ver) and using it to deploy java proxy on PI 7.1. I also registered the interface using http://<pi>:<port>/ProxyServer url But when I invoke the proxy I get the error as "Cannot locate proxy bean" Please tell me what t
-
Dear all, We have created a PO Release Strategy 'R1' with Release Code '01'. Having two User IDs ' USER1' & 'USER2'. Provided PO Release authorization to both USER1 and USER2 with release code '01' Requirement: USER1 has to release PO and USER2 has