Solved

convert access boolean field value to oracle field value

Posted on 2009-07-01
11
530 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Comment Utility
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]
Comment Utility
>What she said ...
correction needed:
>What he said ...
without offense, btw :)

0
 
LVL 4

Expert Comment

by:JonasMalmsten
Comment Utility
ops, appologies :)
0
 

Author Comment

by:bmutch
Comment Utility
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
Comment Utility
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
Comment Utility
ok, very helpful, thanks both.
0

Featured Post

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.

Join & Write a Comment

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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

743 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

12 Experts available now in Live!

Get 1:1 Help Now