Data insertion issue using cakephp 3.2 to oracle 11g tables - oracle

I am just trying to build a simple crud application using cakephp and oracle. But when i am trying to add a new data from my add.ctp its return with this error. can anyone help. Errors are below.
ORA-01400: cannot insert NULL into ("HR"."EMP"."EMP_ID")
CakeDC\OracleDriver\Database\OCI8\OCI8Exception
BTW here 'EMP_ID' is primary key of 'EMP' table and i have also created sequence.

You should try to create all tables strctures using cakephp migrations.
The reason of that - datasource when create table dditionally create not only sequence, but also a triger, to fill id field. Also driver written in way to follow cakephp table field naming conventions. So you can just take EMP schema and get everything work.
Options are: create all tables using migrations from cakephp side, or write trigger that will fill id fields manual on oracle side.

Related

when using dbms_metadata.get_ddl to generate the ddl for a table can I exclude creating of constraints

I am trying to develop some scripts so I can recreate the oracle schema for a development user when I need to refresh the data from a MySQL production database.
I am using the dbms_metadata.get_ddl function to generate the ddl, but it also creates all the constraints for the tables and I need to wait on creating at least the foreign constraints since I want to load the actual data first.
Is there a way to tell dbms_metadata.get_ddl to not create the indexes and constraints?

Laravel Migration create table from existing table

I am working on such application where table audit should perform to make revision of updated records. Let's say for example I have to log each field update in Users update.
I wants to create clone of existing user table by
CREATE TABLE users_audit LIKE users;
My main question is,
Is there any alternative way or provision in Laravel migration to create table from existing table ?
I know we can run raw sql query in migration up/down method using \DB::raw();
But it would be helpful if any helper function available to create table from existing table like, create or table
Yes, you can, see the below link
Click this link
This statement is used to execute raw queries
DB::statement('CREATE TABLE tablename LIKE existingtablename');

Re insert records in Oracle table with Auto generated identifiers using Hibernate

I have few tables in my database where the primary keys are auto generated using Hibernate seqhilo generator configuration. We need to archive these records and at a later point, should be able to restore them in case of a business scenario. My question is if I restore these tables with simple insert statements will that suffice or should I worry about the sequence generator? I would like to have the same ID and not a new generated one. To be clear these re-inserts will happen via direct SQL and not via Hibernate.

Can EF6 use oracle database links?

We have a legacy app that I am rewriting in .net. All of our databases are oracle and make use of database links. Is there any way for Entity Framework 6 to generate models based on tables located on a different database?
Currently the legacy app gets data from table like this
SELECT * FROM emp#foo2;
where its db connection is to database foo that has a database link to the database foo2.
I would like to reproduce this using EF6. So far all I have found regarding this is this question.
You can do two things that EF 4 or higher will work with:
CREATE VIEW EMP as SELECT * FROM emp#foo2;
CREATE MATERIALIZED VIEW EMP as SELECT * FROM emp#foo2;
LOBS are not accessible across a database link without some contorted PL/SQL processing to read the LOB piece by piece.
I believe fast refresh does not work across database links so you must consider the size of the table on the linked database. If you are refreshing a million rows you may find the time to do this is an issue. Most large tables are full of tombstone data that never changes so a timestamp column with the last modified date could help you create a package that only picks out the changed data.
If you are doing complicated joins for either ensure that Oracle considers the column that would be the primary key as not null.
You can add a primary key on views and materialized view but it must be disabled. See here for details.

How to create a table identical to other table in structure and constraints in Oracle?

I want to create a table (lets say table_copy) which has same columns as other table (lets call it table_original) in Oracle database, so the query will be like this :
create table table_copy as (select * from table_original where 1=0);
This will create a table, but the constraints of table_original are not copied to table_copy, so what should be done in this case?
Only NOT NULL constraints are copied using Create Table As Syntax (CTAS). Others should be created manually.
You might however query data dictionary view to see the definitions of constraints and implement them on your new table using PL/SQL.
The other tool that might be helpful is Oracle Data Pump. You could import the table using REMAP_TABLE option specifying the name for the new table.
Use a database tool to extract the DDL needed for the constraints (SQL Developer does the job). Edit the resulting script to match the name of the new class.
Execute the script.
If you need to do this programmatically you can use a statement like this:
DBMS_METADATA.GET_DDL('TABLE','PERSON') from DUAL;

Resources