Access via ODBC - Oracle DEFAULT not working - oracle

We use MS Access as a front-end to Oracle tables, via ODBC, and it has been working well.
But we're trying to use the DEFAULT constraint in an Oracle table. When we open the linked table in Access, we see existing data just fine, but when we try to add a row, without keying any value into column(s) that have an Oracle DEFAULT (expecting the default to be used) we see #Deleted in each column and the row does not get added to the table. Any ideas? I can supply more details if it would help, just let me know.

If you're doing this with the grid view as data entry, I'd think that Access may be explicitly trying to insert an empty string as that value. Try writing the plain SQL statement for the insert and see what happens.
I'd expect underlying SQL like this (assuming default values set for name="John", balance="0.0")...
Via grid view:
insert into customers (cust_id, name, balance) values (1, "Bob", 50.25);
and if one were empty:
insert into customers (cust_id, name, balance) values (2, "", 0);
But, via SQL:
insert into customers (cust_id, name) values (3, "Pete");
insert into customers (cust_id) values (4);
I'd assume the SQL example to use the default values for the unset columns, but the grid view to supply blank values from the UI which would prevent the defaults from being used.

Dunno about Oracle, but to make this work with SQL Server you need a timestamp field in your table.

Related

how to Insert SQL query from previous database table value to pass to another database table with dynamic value in Katalon

Hi any one can help me on this issue which i have problem insert a dynamic value which is from previous database table value to pass to another table in Katalon.
Please find my information below:-
This screenshot is ab.dbo.DOCUMENT table which DOCUMENT_ID is auto populate with value
which mean it will appear random number by itself.
Another screenshot is bc.dbo.DOCUMENT_IC table which i need to manually key in DOCUMENT_ID in
the value base on on what it is given from ab.dbo.DOCUMENT table DOCUMENT_ID.
Attached of a screenshot for bc.dbo.DOCUMENT_IC
In Katalon i am using a keyword to connect my database, insert query and close
connection. I am aware of this step and able to connect to database with katalon. But i
am not very sure how to pass a dynamic value from ab.dbo.DOCUMENT table DOCUMENT_ID which
it can randomly appear a number value to bc.dbo.DOCUMENT_IC table DOCUMENT_ID which i need to
manually key in a value base on the value given.
Below is my Katalon script:-
Hopefully someone can help me on this
Thank you.
If I have a table with an auto incrementing ID in one table and I need that value elsewhere I would typically write sql like this :
insert into firsttable (Document_Type) values ('PDF');
insert into secondtable (Document_ID, App_ref_Num) values (##Identity, 'somenumber')
In the databases I have worked with ##Identity will give you the integer or id of the last inserted row. If you can't run multiple statements most connection libraries will have something like a $conn->insert_id that will do the same thing as running select ##identity.

How do I insert a row with an identity column with Datagrip?

In trying to use Datagrip, I have come across a major blocker.
I have a Sql Azure table with a primary key "Id" field that is sent as an Identity(1,1). In Datagrip it shows the column as Id INT (auto increment).
I clicked on the table and opened the table editor. I then added a new record but left the Id column blank. However, when I go to commit my changes it says that it cannot insert explicit values for identity column.
Is it not possible to add new records in Datagrip with an identity column?
It looks like that issue was fixed a couple years ago.
If you want to add a record with an identity column, you would need to turn on IDENTITY_INSERT for the particular table.
https://msdn.microsoft.com/en-AU/library/ms188059.aspx
SET IDENTITY_INSERT tblYourTable ON
INSERT INTO tblYourTable (ID, Name...) VALUES (1, 'Foo', ...)
SET IDENTITY_INSERT tblYourTable OFF
It is worth noting that this is not something you should leave on, as the expectation is you want to only do this for a few records. For example, to import previous data.

ORACLE 12 C, cannot drop NOT NULL constraint on a DEFAULT ON NULL column

create table autos (
id integer generated by default on null as IDENTITY unique,
owner_name nvarchar2(50)
);
Then I insert in table several rows
insert into autos
(owner_name)
VALUES
('Nick');
insert into autos
(owner_name)
VALUES
('Tommy');
2 rows inserted, then for increase rows count, I run this query
insert into autos
(owner_name)
select owner_name
from autos;
Several query was run successfully, but after this, oracle returns error: ORA-30667: cannot drop NOT NULL constraint on a DEFAULT ON NULL column
Tell please, what is wrong here?
P.S. I use SQL Developer.
UPDATE
If I am trying all above codes in sys database connection, all works fine, but I am create new user (here is code how I create new user)
CREATE USER C##OTO_USER
IDENTIFIED BY oto_user_pass;
GRANT ALL PRIVILEGES TO C##OTO_USER;
Then I create new connection with C##OTO_USER and only in this connection happens above error.
Also, that error happens sometimes, sometimes INSERT query works fine.
And not only INSERT... SELECT, but usually INSERT statement also causes that error.
So, I think this is new user/connection problem, may be above user creating code, not creates complete user?
If trying inserting with SQL*PLUS, also same error happens.
Your problem is that when you use IDENTITY in the column definition, you should take into account its restrictions.
If you want to insert rows as subquery so you encounter with following restriction: CREATE TABLE AS SELECT will not inherit the identity property on a column (source). Same situation happens with your insert, IDENTITY unique doesnt work properly.
insert into autos
(owner_name)
select owner_name
from autos;

ODBC with Oracle Trigger Key Column

I'm trying to update some existing code that is supposed to write data to a variety of Databases (SQL, Access, Oracle) via ODBC, but I'm having a few problems with Oracle and am looking for any suggestions.
I've set my Oracle database up using a Trigger (basic tutorial online, which I'd like to support).
CREATE TABLE TABLE1 (
RECORDID NUMBER NOT NULL PRIMARY KEY,
ID VARCHAR(40) NULL,
COUNT NUMBER NULL
);
GO
CREATE SEQUENCE TABLE1_SEQ
GO
CREATE or REPLACE TRIGGER TABLE1_TRG
BEFORE INSERT ON TABLE1
FOR EACH ROW
WHEN (new.RECORDID IS NULL)
BEGIN
SELECT TABLE1_SEQ.nextval
INTO :new.RECORDID
FROM dual;
end;
GO
I then populate a DataTable using a SELECT * FROM TABLE1. The first problem is that this DataTable doesn't know that the RecordId column is auto-generated. If I have data in my table then I can't alter it because I get a error
Cannot change AutoIncrement of a DataColumn with type 'Double' once it
has data.
If I continue, ignoring this, then I quickly get stuck. If I create a new DataRow and try to insert it, I can't set RecordID to DBNull.Value because it complains that the column has to be non-null (NoNullAllowedException). I can't however generate a value myself, because I don't know what value I should be using really, and don't want to screw up the trigger by using the next available value.
Any suggestions on how I should insert data without ODBC complaining?
It does not appear that your first problem is with an Oracle database. There is no such thing as an "Autoincrement" column in Oracle. Are you sure that message is coming from an Oracle database?
With Oracle, you should be able to provide any dummy value on insert for the primary key, and the trigger will overwrite it.
There is also nothing in your provided description that would prevent you from updating this value in Oracle (since your trigger is on insert only) unless you have foreign key references to the key.

Oracle 10g - An invisible column?

Is it possible to 'hide' a column in an Oracle 10g database, or prevent data from being inserted altogether? We'd prefer to have existing INSERT statements still function, but have the information NOT insert for a particular column. Also, column masking or any type of encryption is not preferred.
Not sure if it's possible, but thanks in advance.
If all you need to do is stop data from being inserted, you could create a BEFORE INSERT FOR EACH ROW trigger that wipes out any value inserted into the column before the row is saved.
There are various other things you can do with security (also views) to prevent inserts/selects from particular users in particular circumstances, but these will probably not let existing inserts continue to work.
With Oracle feature virtual private database (VPD) you can define which users can change and which users can select a column. Virtual private database is also called fine-grained access control (FGAC).
I know how to hide the column.
You use the
SET UNUSED
option to mark one or more columns as unused.
You use the DROP
UNUSED COLUMNS
option to remove the columns that are marked as unused.
ALTER TABLE emp
SET UNUSED (last_name);
and
ALTER TABLE emp
DROP UNUSED COLUMNS;
Rename original table, create view with original table name but only selecting the columns you want to show.
Recompile code referring to existing table.
what about just setting your grants to each item you allow to update or insert
grant select on emp to scott;
grant update (column1, column2), insert (column1) on emp to scott

Resources