Confirm delete before inserting then have a unique key.
Hello
I have a use case where a database field that is entered by the user must be unique.
In the database, there is already a record for example 'name1 '.
The user inserts a new record and puts his name 'name1' as well. Then, for some reason any decides to delete the first existing record and tries to save the new record 'name1 '.
The previous record validation "Name1" is not yet removed, but the new record with 'name1' seeks to insert.
Then I get the error message: attribute value 'name1' leads to duplicate keys for this type of entity. oracle.jbo.AttrValException...
Is it possible to run delete before insertion on commit or another work around?
JDev Version 11.1.2.3.0
Concerning
Here is the link which suites for your usecase
ADF binary Decompilation: customization of the display order of the changes made to the database
You need to wtite your own custom of the Transactionfactory class.
Let us know if it works for you
Thank you
KT
Tags: Java
Similar Questions
-
How to make Unique key Validation
ADF 11, ADF, BC.
I could be missing something, but how do you add a validator for a unique key?
I have a unique key defined on the DB, this unique key has nothing to do with the primary key.
(Its audit that a code is unique)
In the validators on the entity object, I can put a unique key validator, but it lists only the
primary key for the definition of not check unique key...
The unique key on the DB works as I get a nice constraint violation error, so how can I
Add a validator to a single key or at least catch the error to display a friendly message.
Concerning
PaulHello Paul,
My recommendation would be to leave the validation of the uniqueness constraint in the DB. Have a read of the article 37.8.3 (updated for 11g, 10 g, it is 33.8.3) guide the developer of Fusion, where you will find a way to provide your own rather than the ugly constraint violation a nice error messages.
Best,
John
-
TRIGGER BEFORE INSERT OR UPDATE OR DELETE
I want to create a single trigger before each insert or update or delete, a record gets copied into the AUDIT table. works very well on the insertion and to day but you have problem clear.
Can you please help me debug this error. The problem of mutation.
create or replace
BIU_FS_Test_T RELAXATION
BEFORE INSERT OR UPDATE OR DELETE
ON FS_Test
REFERRING AGAIN AS NINE OLD AND OLD
FOR EACH LINE
DECLARE
number of voffender_history_id;
Start
IF the INSERTION
SELECT FS_Test_history_seq. nextval in the double voffender_history_id;
INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,
OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.
SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,
HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.
PLACE_OF_BIRTH, TRANSACTION)
VALUES (voffender_history_id,
: new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,
: new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,
: new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,
:new. PLACE_OF_BIRTH,
"INSERT");
ELSIF UPDATE
et (
NVL (:OLD. First name, 'x') <> nvl():NEW. First name, 'x') or
NVL (:OLD. MIDDLE_NAME, 'x') <> nvl():NEW. MIDDLE_NAME, 'x') or
NVL (:OLD. Last_name, 'x') <> nvl():NEW. Last_name, 'x') or
NVL (:OLD. RACE 0) <> nvl():NEW. RACE 0) or
NVL (:OLD. SX 0) nvl(:NEW <>.) SX 0) or
NVL (:OLD. SKIN_TONE 0) <> nvl():NEW. SKIN_TONE 0) or
NVL (:OLD. HEIGHT 0) <> nvl():NEW. HEIGHT 0) or
NVL (:OLD. WEIGHT 0) <> nvl():NEW. WEIGHT 0) or
NVL (:OLD. EYE_COLOR 0) <> nvl():NEW. EYE_COLOR 0) or
NVL (:OLD. HAIR_COLOR 0) <> nvl():NEW. HAIR_COLOR 0) or
NVL (:OLD. BLOOD_TYPE 0) <> nvl():NEW. BLOOD_TYPE 0) or
NVL (:OLD. VARIOUS, ' x') <> nvl():NEW. VARIOUS, ' x') or
NVL (:OLD. DATE_OF_BIRTH, January 1, 1900 ") <> nvl():NEW. " DATE_OF_BIRTH, January 1, 1900 ") or"
NVL (:OLD. PLACE_OF_BIRTH 0) <> nvl():NEW. PLACE_OF_BIRTH 0)
)
THEN
SELECT FS_Test_history_seq. nextval in the double voffender_history_id;
INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,
OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.
SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,
HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.
PLACE_OF_BIRTH, TRANSACTION)
VALUES (voffender_history_id,
: new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,
: new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,
: new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,
:new. PLACE_OF_BIRTH, "UPDATE");
ELSIF DELETION THEN
SELECT FS_Test_history_seq. nextval in the double voffender_history_id;
SELECT FS_Test_history_seq. nextval in the double voffender_history_id;
INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,
OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.
SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,
HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.
PLACE_OF_BIRTH, TRANSACTION)
VALUES (voffender_history_id,
: new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,
: new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,
: new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,
:new. PLACE_OF_BIRTH, 'CLEAR');
END IF;
end;
Error I get
Error from the 1 in the command line:
Remove from the fs_test where PK = 41476
Error report:
SQL error: ORA-04091: table get OUT. SOR_O_HISTORY is changing, function of triggering/can not see
ORA-06512: at «GET. » BIU_FS_TEST_T', line 111
ORA-04088: error during execution of trigger ' EB. BIU_FS_TEST_T'
04091 00000 - «table %s. » "%s is changing, function of triggering/can not see.
* Cause: A trigger (or plsql user-defined function that is referenced in)
( this statement) attempted to watch (or modify) a table that has been
in the middle to be modified by the statement that shot.
* Action: Rewrite the trigger (or function) so it does not read this table.
PS 11g r2
Thank you.
n_shah18-
Is there a parent-child relationship between the tables involved in the triggering event? Is there a foreign key used above the child table that references the parent table?
If you have a parent-child relationship and a trigger on the parent table must be running some DML on the child table, and, if the child table as a foreign key (FK) back to the parent table, any DML on the child table will cause a recursive SQL statement to check the constraint. Indirectly, this will cause an exception table mutation.
So watch the dependencies on SOR_O_HISTORY / FS_TEST_HISTORY/all other related table. A FOREIGN KEY can make it to mutate (no pun intended).
Hope this will help you find the root cause.
-
PL/SQL TRIGGER BEFORE INSERT, DELETE OR UPDATE
Dear
I have 2 paintings; Catalog and Catalog_bak (read back as backup)
I need a trigger that after a DML (INSERT, UPDATE, DELET), copies all information from the table in the catalog to Catalog_bak table, adding 2 additional fields: change_type, change_date.
The change_type field should show a value meets the DML that fired the trigger. If the trigger is fired by a
INSERT == > 1
UPDATE == > 2
DELETE is > 3
So my question is: How can I determine if it was an INSERT, UPDATE, or DELETE command that triggered the trigger.
Yours Sincerely
ChristofWelcome to the forum.
You can consult the Oracle Online Documentation, learn more about triggers and the options you have:
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14251/adfns_triggers.htm#sthref1249Houses of doc. :
http://www.Oracle.com/pls/db102/homepage
http://www.Oracle.com/pls/db112/homepageSo, in your case it would be something like:
... begin if inserting then do the required stuff.. elsif updating then do the required stuff... elsif deleting then do the required stuff... end if; end;
Other examples:
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14251/adfns_triggers.htm#ABC1032282 -
How to display a confirmation message before deleting
Hello
I have a request and I want to display a confirmation message before people delete a record.
The button on page 42 is number 90 'delete this card '. This is a shipment as 'DELETE_ALL '. I saw that the buttons remove are redirects to the url javascript:confirmDelete(htmldb_delete_message,'DELETE'). but I can't use it because my button is not a redirect, but a shipment.
http://Apex.Oracle.com/pls/OTN/f?p=4550
Workaspace: ESPACE2008
User: guest
password: acdc2009
Name of the application's activities
Thank you for your kind replies.
ChristianHi Christian.
You can use the same logic for your own processing logic.
the syntax is...
javascript:confirmDelete(htmldb_delete_message,'YOUR_PROCESS_NAME');
Replace "YOUR_PROCESS_NAME" with the name of your page process that manages the deletion block. Don't for get the quotes either side of your process name.
I hope this helps.
Simon
-
Is a foreign key MUST have a UNIQUE or PK column as a reference?
First I tried, from what I saw Yes it must be Unique or PK. Secondly, I am pretty sure that I read somewhere where there are PK or unique. Thirdly, I checked oradocs and other pages, the thing ends, I owe an answer
Constraint foreign key (also called a constraint referential integrity) designates a column as a foreign key and establishes a relationship between this foreign key and a primary or unique key specified, called the referenced key.
This implies, but does not explicitly specify that it MUST be a PK or a SINGLE.
Basically I want a simple yes/no answer just to give me some peace of mind. I don't want to waste any time, but changes to the oracle from time to time, and I'd rather have a confirmation from someone with more knowledge/experience.
Thank you!
Yes.
This same document you are referencing tells you what are the rules for the creation of a foreign key.
Foreign key constraints
Whenever two tables have one or more common columns, Oracle database can apply the relationship between the two tables with a foreign key, also called a referential integrity constraint constraint. The constraint requires that for each value in the column on which the constraint is defined, the value in the other specified that another table and column must match. An example of a referential integrity rule is that an employee may work for only one Department.
Table 5-2 lists the terms associated with referential integrity constraints.
Table 5-2 referential integrity constraint conditions
Term Definition Foreign key
The column or set of columns included in the constraint definition that refers to a key that is referenced. For example, the
department_id
columnemployees
is a foreign key that refers to thedepartment_id
column ofdepartments
.Foreign keys can be described as several columns. However, a composite foreign key must refer to a primary or unique key with the same number of columns and the same types of data.
The value of the foreign keys can be either the primary or unique key value referenced or be null. If any column of a composite foreign key is null, then the portions not null the key do not match any corresponding part of a parent key.
Referenced key
The unique key or the primary key of the table referenced by a foreign key. For example, the
department_id
columndepartments
is the key referenced to thedepartment_id
column ofemployees
.Table dependent or child
The table containing the foreign key. This table is based on the values present in the primary or unique key referenced. For example, the
employees
table is a child ofdepartments
.Referenced or the parents table
The table that is referenced by the foreign key of the child table. It is the key to this table reference that determines whether specific inserts or updates are allowed in the child table. For example, the
departments
table is a parent ofemployees
.The first three terms defined in the table EXPLICITLY State references to the 'core' or 'unique' keys to the parent.
The doc also refers to the Application Developer Guide:
Maintaining the integrity of the data in Database Applications
Foreign key references a primary key by default
If the list of columns is not included in the
REFERENCES
option when you set aFOREIGN
KEY
constraint (simple or composite column), then Oracle database assumes that you want to reference the primary key of the specified table. You can also explicitly specify the columns to reference the table parent in parentheses. Oracle database checks automatically to check this list of column refers to a primary or unique to the parent table key. If it isn't, an informative error is returned.That the entire paragraph is as explicitly as it gets.
No list of columns? Oracle then checks for a primary key.
There is a list of columns? Then Oracle 'control to verify this list of column made reference to a primary or unique key'...
-
Hi, I need help to create a trigger before the insertion of the STA_STARTDATE column in the employees table
Note: If the declaration is < 01 - JAN-1980 quotesCREATE OR REPLACE TRIGGER trig_start_date BEFORE INSERT OF STAFF FOR EACH ROW BEGIN IF STA_STARTDATE < '01-JAN-1980' THEN RAISE_APPLICATION_ERROR(-20900, 'No earlier than 1/1/1980'); END IF; END;
When I run the script, it comes up with this error:
Error report:
ORA-04073: invalid column list for this type of trigger
04073 00000 - "list of invalid columns for this type of trigger.
* Cause: A list of columns has been specified for a non updated trigger type.
* Action: Delete the column list.
* fixed by replacing the OF keyword with, but still have a warning
Published by: 888948 on October 2, 2011 16:48Hello
to use a column in a trigger, the column must have: new for new values, or: old old values before the name of the column, so your if statement should begin with:
IF :NEW.STA_STARTDATE
Herald tiomela
http://htendam.WordPress.com -
I come to me on my computer and everything was gone. All my files, shortcuts and backround have simply disappeared. It's like I've never been on my computer before. I have nothing! How to get everything back?
You have been discharged into a temporary user account. It may be a glitch, or your user account may be damaged. First try a system restore when things worked. If it suits it, fine. If it is not then your account is damaged and the best thing to do is to create a new user account and copy your data from the old to the new. I would also like to do a Chkdsk and then some hardware diagnostics on the hard drive and RAM to make sure that the material is solid.
CHKDSK - click here to open the computer. Right click on the hard drive you want to check, and then click Properties. Click on the Tools tab and then, under error-checking, click check now. If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.
To automatically repair problems with files and folders that the scan detects, select automatically fix file system errors. Otherwise, the disk check will simply report a problem, but not to fix them.
To perform a full disk check, select search and attempt to recover bad sectors. This scan is trying to find and repair physical errors on the hard drive itself, and it may take much longer to complete.
To check for errors file and the physical errors, select both automatically fix errors in file system and search for and attempt recovery of bad sectors.
Click Start.
Depending on the size of your hard disk, this may take several minutes. For best results, do not use your computer for any other tasks while it checks errors.
Note: If you select automatically errors in file system of fix for a disc that is used (for example, the partition that contains Windows), you will be prompted, see the disk check for the next time you restart your computer.
Hardware tests - http://www.elephantboycomputers.com/page2.html#Hardware_Tshoot
Corrupt user account - if your single administrative user account is damaged (and therefore have what one user account is A Bad Thing), you must log on to the built-in Administrator (disabled by default in Vista) account. From there, you can create a new user account for yourself. In these cases, I prefer not to copy the whole profile to a new way to do not copy the bits corrupt. I prefer a new user account to copy the data (documents, photos, emails, etc.). Here are the instructions to do this. I assumed that you had only an administrative account, then you might want to take a look at the "general recommendations for setting Up user accounts in Vista" at the end of this post.
All this requires a certain level of computer skills. You know better and that take the machine to a competent local computer tech (not a type of BigComputerStore/GeekSquad place) is the best solution for you.
Activation of the built-in administrator.
Method 1. If you have an installation of Vista DVD (not a recovery DVDs), you can start the system with it. Select the default language, then select "repair your computer". Then select "Command Prompt". At the command prompt, type:
NET user administrator / Active: Yes [Enter]
If you do not have a Vista installation DVD, you can either make a bootable DVD of Vista repair in the file at this link:
http://NeoSmart.net/blog/2008/Windows-Vista-recovery-disc-download/
Note: All the Neosmart recovery disk downloads are torrent files. There is a good explanation of the torrent on the site Web of Neosmart files. You will need a torrent as muTorrent client to get the files. Torrent client will download the .iso file with which to create the bootable DVD.
After net user, remove the bootable CD and restart the computer. You will now see an icon for administrator on the Welcome screen. Connect to this account.
Method 2. Or you can use NTpassword to enable the built-in administrator. In both methods, you need third-party burning software such as Nero, Roxio or the free ImgBurn (http://www.imgburn.com ) to burn the .iso image image file, not in the form of data.
http://home.eunet.no/pnordahl/ntpasswd/
B. create a new user account for yourself and by copying data from your damaged to her user account
1. you are now connected to the built-in Administrator account. Go to control panel > user accounts and create a new Standard user for your daily work. Let's call it "Sheldon" for this example. Also create an administrator user, called 'CompAdmin' (or 'Tech' or similar).
4 Ouvrezunesession 'Sheldon' once for profile files are created. Now log off 'Sheldon' and 'CompAdmin '. In "CompAdmin", disable the built-in security administrator. Do this from a command prompt:
Start > Search > type: cmd
When cmd appears in the above results, right-click and choose "Run as Administrator". Provide the password/OK to the UAC prompt. Now, you will get the command prompt. Type:NET user administrator / active: No. [Enter] and exit the command prompt.
5. always in 'CompAdmin', you want to open two windows explore side by side. Open computer and navigate to C:\Users\old-corrupted-account. Now, do that again, but navigate to C:\Users\Sheldon. Copy the data from 'old-corrupted-account' on records in 'Sheldon '. Remember your Favorites, bookmarks (if you use Firefox) and by e-mail if you use an email like Windows Mail client.
6. When you are finished, log in to "Sheldon. All your stuff should be there. When you are sure to have what you need, you can remove the old man-corrupted-account control panel > user accounts.
General C. recommendations for creating users in Vista:
You absolutely don't want to have only one user account. As XP and all the other modern operating systems, Vista is an OS multi-user with system built-in accounts such as administrator, by default, all users and guest. These accounts should be left alone because they are part of the structure of the operating system.
In particular, you do not want one account user with administrative privileges on Vista because the administrator account integrated (normally only used in emergencies) is disabled by default. If you use as an administrator for your daily work, and this account is corrupt, things will be difficult. It is not impossible to activate the built-in administrator to rescue things, but it will take third-party tools and work outside the operating system.
The user account that is for your daily work must be a Standard user, with the extra administrative user (call it something like 'CompAdmin' or 'Tech' or similar) only it for elevation purposes. After you have created "CompAdmin", connect to it and change your normal user account Standard. Then log on to your regular account.
If you want to go directly to the desktop and ignore the Welcome screen with the icons of the user accounts, you can do this:
Start Orb > Search box > type: netplwiz [Enter]
Click continue (or provide an administrator password) when you are prompted by UACUncheck "users must enter a user name and password to use this computer". Select a user account to connect automatically by clicking on the account you want to highlight and press OK. Enter the password for this user account (when it exists) when you are prompted. Leave blank if there is no password (null). MS - MVP - Elephant Boy computers - don't panic!
-
Error message: Picture.library.ms no longer works. Tried to remove the library as suggested but does not ask for confirmation delete a few deletions without asking for confirmation. Also don't undersatnd how then restore you the other context using the trash of the library? Don't understand that your instructions please the ventilation in portions of beginner. Is - this recurring issue is sought in microsoft?
Hello
You solved the problem with the photo library?
You have been informed that the question about the image library is fixed in the next thread.
If you are now facing problems with videos from YouTube on Internet Explorer 11, try the steps in the above thread link and check.
Let us know if you need help with Windows related issues. We will be happy to help you.
-
Helps relaxation that fits into another table before insertion
I have two tables:
TABLE A as follows:
x, y, z
1, 1, 1
1, 1, 2
1, 1, 3
TABLE B as follows
c, d, e, f
1, 1, 1, 8
1, 1, 1, 2
1, 1, 1, 6
1, 1, 2, 5
1, 1, 2, 10
1, 1, 2, 3
1, 1, 3, 12
1, 1, 3, 11
1, 1, 3, 15
I want a trigger, BEFORE insertion in the TABLE B, I want to INSERT into TABLE A as follows:
c = > x
d = > y
e = > z
ONLY IF a (x, y, z) record does not already exist in the TABLE.
That is to say. If record (1, 1, 3) already exists in the TABLE, we do not try to put it back when you insert in the TABLE B with values containing (1, 1, 3).You will need
CREATE OR REPLACE trig_on_insert BEFORE INSERT ON B FOR EACH ROW IS lv_count NUMBER := 0; BEGIN SELECT COUNT(1) INTO lv_count FROM a WHERE x = :new.c AND y = :new.d AND z = :new.e ; IF ( lv_count = 0 ) THEN INSERT INTO A VALUES(:new.c,:new.d ,:new.e); END IF; END; /
Concerning
Arun -
Redirect data to another table using before insert trigger.
Dear all,
How can I redirect the data to another table in a before Insert trigger? My database is Oracle10g.
I have a table EMP (EMP_ID, LAST_NAME, SALARY).
I have another EMP_COPY table with the same structure. I also have a before Insert trigger on the EMP table.
Based on a condition that I have to redirect the data in table EMP_COPY. Let's say the condition is EMP_ID = 100.
I fire an insert on EMP table for example INSERT IN EMP(EMP_ID,LAST_NAME,SALARY) VALUES(100,'Dev',500).
On the inside of the front Insert trigger on the EMP table, I have the code
IF EMP_ID = 100 THEN
INSERT INTO EMP_COPY (EMP_ID, LAST_NAME, SALARY)
VALUES(:NEW.) EMP_ID,: NEW. LAST_NAME,: NEW. SALARY);
COMMIT;
ON THE OTHER
NULL;
END IF;
But the problem here is that data goes to EMP table of origin also although I don't want. He should do an Insert into EMP table only if EMP_ID! = 100.
One way has been to raise a user-defined exception inside the If statement and not handle it so that the original insert on table EMP fails but INSERT comes in the EMP_COPY table. But in this solution since the inside the trigger unhandled exception, it propagates to the calling environment. And I can't stand outside relaxation as the calling environment is a form of Oracle Apps standard that cannot be customized.
Any kind of help will be highly appreciated that I am fighting for more than two weeks.
Thanks in advance
DevRemove the autonomous transaction pragma... and then try again.
-
Insert, based on condition (constraint unique key)
Hello
Need help with checing the uniqeness of value before inserting
for example
have two table
Book book_owner years and need to inserting 100 rows in the table, but there are a few unique constraints challenged on the table where need to chek the value existing or not, if the value is exisitn jump insertion otherwise insert the value
Here is an example
Insert in the BOOK (BOOK_ID, CNT, ALT_CNT, ROW_INSERT_TMSTMP, ROW_LAST_UPDT_TMSTMP, BOOK_ID)
Values (SEQ_BOOK_ID.nextval, 50, 500, sysdate, sysdate, ' 123456');
commit;
/
Insert into BOOK_OWNER (BOOK_OWNER_ID, BOOK_ID, USER_ID) Values (SEQ_BOOK_OWNER_ID.nextval, SEQ_BOOK_ID.currval, "456");
commit;
/
Insert in the BOOK (BOOK_ID, CNT, ALT_CNT, ROW_INSERT_TMSTMP, ROW_LAST_UPDT_TMSTMP, BOOK_ID)
Values (SEQ_BOOK_ID.nextval, 50, 500, sysdate, sysdate, ' 678901');
commit;
/
Insert into BOOK_OWNER (BOOK_OWNER_ID, BOOK_ID, USER_ID) Values (SEQ_BOOK_OWNER_ID.nextval, SEQ_BOOK_ID.currval, ' 678');
commit;
/
Insert in the BOOK (BOOK_ID, CNT, ALT_CNT, ROW_INSERT_TMSTMP, ROW_LAST_UPDT_TMSTMP, BOOK_ID)
Values (SEQ_BOOK_ID.nextval, 50, 500, sysdate, sysdate, ' 5123987');
commit;
/
Insert into BOOK_OWNER (BOOK_OWNER_ID, BOOK_ID, USER_ID) Values (SEQ_BOOK_OWNER_ID.nextval, SEQ_BOOK_ID.currval, ' 896');
commit;
/
in the Book table BOOK_ID has the unique constraint and the data type is varchar type
BOOK_OWNER table USER_ID) has the unique constraint and as a varchar data type
I use oracle 10gDouble post!
-
Splitting words before inserting into the new table
I created another table:SQL> desc company Name Null? Type ----------------------------------------- -------- ---------------------------- CO_ID NOT NULL NUMBER(9) R_DATE TIMESTAMP(0) CONAME VARCHAR2(140) ESTYR NUMBER(5) COUNTRY VARCHAR2(32) PRODUCTS VARCHAR2(3900) SQL> select unique(products) from company where rownum<6; PRODUCTS -------------------------------------------------------------------------------- bars,tubes,pre-weld seams,isosceles and un-isosceles angles,special profiles,u-p rofiles,plates,t-profiles,flanges,tube fittings,round,hollow bars,double-t-profi les (ipe und ipb),pipe clamps,flat,special designs according to drawings for new products,profiles for floor covering,hexagon carbon steel bright bars,tool steel bright bars,alloy steel bright bars,stainles s steel bright bars cold rolled coil,e.g sheet,prepainted sheet,galvalume coil,copper scrap,stainles s steel sheet,shredded scrap,hms1 and 2,cobalt ore,rail scrap,hot rolled coil,ga lvanized sheet,iron ore PRODUCTS -------------------------------------------------------------------------------- ferro alloy producer switch technology,special tubes,rails,steel strip,special steel
I want to:crate table keywords( k_id number(14), keywords varchar2(500) unique ); create sequence keywords_pk_seq start with 3484 increment by 1; create or replace trigger keywords_pk_trig before insert on keywords referencing new as new for each row begin select keywords_pk_seq.nextval into :new.k_id from dual; end; /
one) to split columns of company.products where is comma (,) for example, bars, tubes, pre-soudures, tubes will became 4 different as words:
bars
tubes
welds
tubes
(b) then I want to insert these words in the table keywords.keywords with condition separated by ignoring the existing keywords.keywords (e.g. tubes came twice, let's get just a tubes) for example
k_id keywords
1 bars
2 tubes
3 before welding
Thank you and best regardsYou can use the merge statement:
for example
merge into keywords using ( with t as (select 'pipes,taps,spanner,spade,tubes' as txt from dual) -- end of sample data select distinct REGEXP_SUBSTR (txt, '[^,]+', 1, level) kw from t connect by level <= length(regexp_replace(txt,'[^,]*'))+1 ) x on (keywords.keyword = x.kw) when not matched then insert (id, keyword) values (key_seq.nextval, x.kw) /
But keep in mind that the sequence in this example will be updated for each line independently to know if she gets inserted or not.
If you set the ID using a sequence triggered when inserting then this will solve this problem. -
Before Insert TRIGGER to create partitions problem
Hello
I m having a problem with the following situation in Oracle 8i:
I have a table TEST_TABLE, which is divided by the beach with a DATE column. The idea is to have a partition for each month, so the HIGH_VALUE of partitions is always the first day of the month following that represents the partition.
I created a BEFORE TRIGGER INSERT on the table TEST_TABLE, which tests if the partition for the month of registration which is being inserted exists and, in case it doesn´t, a PROC AUTONOMOUS_TRANSACTION is called to create the TRIGGER.
Running the code below one can see that even if partitions are created as expected, when you try to insert a record with a date greater than the last partition for the first time, this error is returned:
ORA-14400: inserted partition key exceeds plu legal partition key.
Note that if you run the same statement again insert, it s inserted correctly on the partition that was created the first try.
I´ll appreciate any help on this matter.
code
----------------
CREATE TABLE TEST_TABLE)
IDENTIFICATION NUMBER,
DATE OF THE DT
)
TABLESPACE USERS
PARTITION BY RANGE (DT)
(
PART_B42009 PARTITION VALUES LESS THAN (TO_DATE ('2009-01-01 00:00:00 ',' YYYY-MM-DD HH24:MI:SS ',' NLS_CALENDAR = GREGORIAN '))
LOGGING
TABLESPACE USERS
);
/
CREATE OR REPLACE PROCEDURE SP_ADD_PARTITION (TEST_TABLE P_DATE. DT % TYPE)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
V_STR VARCHAR2 (500);
BEGIN
V_STR: = 'ALTER TABLE TEST_TABLE ADD.
|| 'PARTITION BIRD | TO_CHAR ("P_DATE, ' YYYYMM")
|| ' VALUES LESS (TO_DATE ("')).
|| TO_CHAR (ADD_MONTHS (P_DATE, 1), "YYYY-MM"). '-01 00:00:00 ','
|| ((' SYYYY-MM-DD HH24:MI:SS "," NLS_CALENDAR = GREGORIAN "))';
EXECUTE IMMEDIATE (V_STR);
END SP_ADD_PARTITION;
/
CREATE OR REPLACE TRIGGER TR_B_I_R_TEST_TABLE
BEFORE INSERTING
ON TEST_TABLE FOR EACH LINE
DECLARE
NUMBER OF V_PARTITION_EXISTS;
BEGIN
IF: NEW. DT > = TO_DATE ('2009-01-01 00:00:00 ',' ' YYYY-MM-DD HH24:MI:SS) THEN
IMMEDIATELY EXECUTE (' SELECT COUNT (1) ")
|| "Of all_tab_partitions atp'."
|| "WHERE atp.table_name ="table_test"'.
|| "AND the atp. Nom_partition =: v1 ')
IN V_PARTITION_EXISTS
WITH THE HELP OF "BIRD" | TO_CHAR(:NEW.) "DT,"YYYYMM";)
IF V_PARTITION_EXISTS = 0 THEN
DBMS_OUTPUT. Put_line ('Partition [' |]) 'BIRD ' | TO_CHAR(:NEW.) "DT,"YYYYMM"). does not exist!') ;
DBMS_OUTPUT. Put_line ('creation..');
SP_ADD_PARTITION (: NEW.) DT);
DBMS_OUTPUT. Put_line ('success.');
IMMEDIATELY EXECUTE (' SELECT COUNT (1) ")
|| "Of all_tab_partitions atp'."
|| "WHERE atp.table_name ="table_test"'.
|| "AND the atp. Nom_partition =: v1 ')
IN V_PARTITION_EXISTS
WITH THE HELP OF "BIRD" | TO_CHAR(:NEW.) "DT,"YYYYMM";)
IF V_PARTITION_EXISTS = 1 THEN
DBMS_OUTPUT. Put_line ("it s visible at this point..");
ON THE OTHER
DBMS_OUTPUT. Put_line ("it s not visible at this point..");
END IF;
ON THE OTHER
DBMS_OUTPUT. Put_line ('Partition [' |]) 'BIRD ' | TO_CHAR(:NEW.) DT, "YYYYMM")
|| already exists! ") ;
END IF;
END IF;
DBMS_OUTPUT. Put_line ('continues with insertion...");
END TR_B_I_R_TEST_TABLE;
/
-Go to the low score
INSERT INTO TABLE_TEST VALUES (1, TO_DATE ('2008-12-31 23:59:59 ',' YYYY-MM-DD HH24:MI:SS'));))
-Returns the error on the first try
INSERT INTO TABLE_TEST VALUES (2, TO_DATE ('2009-01-01 00:00:01 ',' YYYY-MM-DD HH24:MI:SS'));))
----------------It is the use of the pragma AUTONOMOUS TRANSACTION. Your current transaction cannot see the result of this DOF since it occurs outside of the current transaction. The clue is in the name.
Of course, you cannot run the DDL in a trigger without use of this pragma, so you're pretty much stuck. There is a solution in 11g, but that will not help you. Unfortunately, your only option is to pre-create the partitions required in front of the need. For example, you might have a DBMS JOB to create a partition for the next month, which takes place the last day of each month (or logical date of company).
Cheers, APC
blog: http://radiofreetooting.blogspot.com
-
Restore the option "confirm deletion".
Hello
I have a LENOVO Thinkpad 03193TG. Someone tweaked the settings on it and removed the need to confirm the deletion by pressing ENTER when you press the DELETE key. I would be very grateful if you could advise me on how to restore this option.
Trash > properties > confirm delete
Maybe you are looking for
-
No updated driver in dxdiag (Satellite M60) to display ATI
I bought a Satellite M60-139 last week and I have huge problems with various games, gel, so I started to update my drivers. However after downloading and installing the ATI display driver, restart the pc and check dxdiag and the hardware Manager, the
-
Photosmart 7510: activate scan-to-printer
All of a sudden my scan of the printer does not work, and I enter the usual loop. I downloaded the diagnosis of HP software, which enabled an analysis of test to work. But no more. I deleted the printer and then re-added, with Windows does not recomm
-
Re: Qosmio F50-10 b Blutooth does not
I have just Purcheesed Toshiba Qosmio F50-10 portable computer b, all thing okey except bluetooth could not be started, I've tried everything I know, but seems still that no bluetooth device has been installed... Please help me because it is very imp
-
I got a .zip file attachment on Outlook.
Computer says generator of preview not available for this file. If you click on "open with...". "and tried a few programs without result. Now a .zip file previous that I have somehow managed to open does not open again. If I choose Notepad, all previ
-
After running Diagnostics for error 0142 problem
Help, please. I ran a diagnostic test and an error code 0142 came. So, I read a few o forums and found if I get my original os drive and put it in when I start the computer it would give me a prompt asking you to fix. I never had that. So I just down