Solved

convert access boolean field value to oracle field value

Posted on 2009-07-01
11
534 Views
Last Modified: 2013-12-19
We have a dynamic series of insert queries that get run on an Access DB from dotnet program. We have duplicated the tables in Oracle (don't ask why) and these table need to get updated with the same queries. One problem I've seen so far is the boolean (Yes/No) Access fields we have converted to char(1) fields in Oracle so when it tries to insert using the query:
INSERT INTO ITEMMASTER
(StoreNum, BatchNumber, FileType, SKU, DESCRIPTION, ACTIVE, PRD_LVL_CHILD, PRD_LVL_PARENT)
VALUES (427, '2009051819010600', 'I', 29254, 'Kool Family B1G1F Sng Pk-Test-Inactive', -1, 27480, 205)

for example the -1 doesn't fit in the char(1) field. Can we do something like put a trigger on the ACTIVE field and convert the -1 value into '1' so it will fit?
0
Comment
Question by:bmutch
  • 5
  • 3
  • 3
11 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24758282
you could use NUMBER(1) instead of CHAR(1) ,  or use ABS(-1) to save 0 and 1 instead of 0 and -1,,,
0
 
LVL 4

Expert Comment

by:JonasMalmsten
ID: 24758648
When using oracle, a char(1) that equals 'Y' or 'N' is the most common way to represent a boolean value.

You can translate into this using Decode(value, '0', 'N', '-1', 'Y', null)

in your example that would be Decode(-1, '0', 'N', '-1', 'Y', null)
0
 

Author Comment

by:bmutch
ID: 24762453
This is going to be occurring in vb code and it will be a pain to have to parse the query string and replace the value, I will have to hunt and peck at the string to find the "boolean" field location for the given table in the string, I am reading these queries in from a text file, then I have to run each query in Oracle via ado.net. So is there any way to convert the value in a trigger?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24762500
>So is there any way to convert the value in a trigger?
no, as the trigger will happen AFTER the "-1" is rejected by the basic data type test against CHAR(1)

your only choice is to use VARCHAR2(2) instead, and then you could use the trigger to remove the "-" from "-1"
0
 
LVL 4

Expert Comment

by:JonasMalmsten
ID: 24762597
What she said, for example:

create table test (b varchar2(2));

create or replace trigger tr_iu_test
before insert or update on test
for each row
begin  
  select decode(:new.b, '-1', 'N', '0', 'Y', null) into :new.b from sys.dual;
end;
/
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Expert Comment

by:JonasMalmsten
ID: 24762615
or even better:

create or replace trigger tr_iu_test
before insert or update on test
for each row
begin  
  select decode(:new.b, '-1', 'N', 'N', 'N', '0', 'Y', 'Y', 'Y', null) into :new.b from sys.dual;
end;
/
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24762716
>What she said ...
correction needed:
>What he said ...
without offense, btw :)

0
 
LVL 4

Expert Comment

by:JonasMalmsten
ID: 24762728
ops, appologies :)
0
 

Author Comment

by:bmutch
ID: 24764189
thanks , can you possibly explain this in the trigger:
for each row ...

this doesn't mean it checks each row of the table every time there is an insert does it?
Concerned about performance.
0
 
LVL 4

Assisted Solution

by:JonasMalmsten
JonasMalmsten earned 250 total points
ID: 24764314
It means that the trigger will execute for each row that you insert or update, not for each row in the whole table.

If you ommit "for each row", the trigger will only fire once for each insert statement (that can possibly affect multiple rows). Consequently, if you ommit it you will not be able to access the :new.b variable.
0
 

Author Closing Comment

by:bmutch
ID: 31598967
ok, very helpful, thanks both.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now