Use Oracle Apex to read csv line by line and validate data - sql

Now, I installed Oracle database and Apex into my local server.
I also create a table
CREATE TABLE FAC_CODE_CPQLDN(
ID NUMBER(10),
CODE NVARCHAR2(100) NOT NULL,
NAME NVARCHAR2(1000),
DESCRIPTION BLOB,
PARENT_ID NUMBER(10),
CONSTRAINT FAC_CODE_CPQLDN_PK PRIMARY KEY (ID)
);
How can I use Oracle Apex to read csv file line by line, store into "list_value" to validate before inserting into database?

If your csv less than 50 columns ( I think it is your case)
Excel2Collection [Plug-in]
Else
Implement your own PL/SQL PROCEDURE PARSE_CSV

Related

Auto UUID Creation on PostgreSQL COPY Command

I'm copying some data into a postgres database, and the CSV files do not have UUIDs. Currently the schema for the DB looks like this:
CREATE TABLE customers(
id UUID NOT NULL DEFAULT gen_random_uuid(),
customer_name VARCHAR(255) NOT NULL,
customer_age INT,
PRIMARY KEY(id)
);
The COPY statement is as follows:
COPY customers FROM '/usr/app/data/customers.csv' HEADER csv;
And the CSV file is shaped like this:
customer_name,customer_age
"Peter",12
"Sam",13
How can I automatically create the UUID for the customers data on the COPY command if it doesn't already exist in the CSV file? Currently this COPY command fails because it expects the customer_name row to be the UUID.
Sorry! This one is straightforward, you must specify the columns you're copying over:
COPY items (customer_name, customer_age) FROM '/usr/app/data/customers.csv' HEADER csv;

How do I create a postrgresql database using SQL's DDL on pgadmin4?

I'm learning DDL to create and define an SQL database with Postgresql 10.
I have the something like the following SQL code in an .sql file, and I want to input it in psql or PgAdmin 4, just to test the syntax and see the database structure:
CREATE DATABASE database;
CREATE TYPE t_name AS
( first VARCHAR(30),
last VARCHAR(60)
);
CREATE TABLE telephone_m
( tnumber VARCHAR(15) NOT NULL UNIQUE
);
CREATE TABLE people
( curp CHAR(18) NOT NULL PRIMARY KEY,
pname t_name NOT NULL,
birth_date DATE NOT NULL,
telephone_m VARCHAR(15) REFERENCES telephone_m
);
CREATE TABLE clients
( curp CHAR(18) NOT NULL PRIMARY KEY,
cid SERIAL NOT NULL REFERENCES cards,
clocation VARCHAR(29)
) INHERITS (people);
CREATE TABLE cards
( cid BIGSERIAL NOT NULL PRIMARY KEY,
curp CHAR(18) NOT NULL REFERENCES clients,
trips SMALLINT,
distance NUMERIC,
points NUMERIC
);
CREATE TABLE drivers
( curp CHAR(18) NOT NULL PRIMARY KEY,
rfc CHAR(22) NOT NULL UNIQUE,
adress t_adress NOT NULL
) INHERITS (people);
I've tried in PgAdmin 4 making right-click on a new database -> CREATE Script, it opens Query Editor, I copy paste my code and execute it, but it returns:
ERROR: CREATE DATABASE cannot be executed from a function or multi-command string
SQL state: 25001
I've also tried using Query Tool directly from the PgAdmin tools menu with the same results.
The database is created just fine. But if you want to create object in the new DB, you have to connect to it. In any client, including pgAdmin4.
And you cannot run CREATE DATABASE inside of a transaction. Must be committed on it's own. Executing multiple commands at once is automatically wrapped into a single transaction in pgAdmin.
You have to execute CREATE DATABASE mydb; on its own (for instance by selecting only that line and pressing F5 while being connected to any DB, even the maintenance db "postgres". Then click on "Databases" in the object browser in the pgadmin4 main window / tab, hit F5 to refresh the view, click on the new DB, open up a new query tool with the flash icon (in a new window / tab) and execute the rest of your script there.
psql scripts manage by using the meta-command \c to connect to the new db after creating it, within the same session.
Asides:
"database" is no good name for a database.
CREATE TYPE AS (...), but just CREATE TABLE (...). No AS.
And you typically don't want to use the data type CHAR(18). See:
Any downsides of using data type "text" for storing strings?
Get sum of integers for UNIQUE ids
What is the overhead for varchar(n)?
Should I add an arbitrary length limit to VARCHAR columns?
There is the ; missing after the CREATE DATABASE database (and perhaps give the db a better name).

Liquibase ignorable comments

Is there a way we can add comments in liquibase file which are not parsed by the program?
We are using the text format for the changes.sql and this is how it looks
--changeset Sapan.Parikh:MyUniqueAlphaNumericId5
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test11 (
id int primary key,
name varchar(255)
);
create table liqui_test9 (
id int primary key,
name varchar(255)
);
create table liqui_test10 (
id int primary key,
name varchar(255)
);
Our organization has been using similar change log for years and while migrating to Liquibase we want to be able to do two things.
Add dashes or hashes after each changeset.
And after every production build we add a comment at the end of the changes file.
For instance
--changeset Sapan.Parikh:MyUniqueAlphaNumericId5
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test11 (
id int primary key,
name varchar(255)
);
-----------------------------------------------------------------
--changeset Sapan.Parikh:MyUniqueAlphaNumericId4
--comment: Table created for liquibase testing purpose with non numeric id
--6:10 PM 11/10/2015
create table liqui_test12 (
id int primary key,
name varchar(255)
);
###------------------Build 10.0.1 Made-------------------
Now if we add just dashes- or # the luqibase task is breaking and DB upgrade does not happen. Is there a way to accommodate comments which are not parsed by liquibase engine?
You can just persist your comments and strip them right before executing liquibase
- can be done easily using sed

Newly added table not working

I am working on DB2 9.7 database. I was using SquirrelSQL for GUI purpose. However ever since I applied an alter command to one of my tables , I started facing problems with the table, and any further select queries asked for "reorg" of the table. to overcome this, I renamed the old table and created new table. However the create query didn't execute properly in Squirrel ,and so downloaded DBViewer for my STS(Spring Source Tool Suite.)I executed the create table query from DBViewer, but the issue now is neither am I able to access the newly created table from my JAVA code , nor from Squirrel.
I am completely clueless as to what could be the problem. Has anyone got any idea?
Following is the Structure of my table:
CREATE TABLE DB2ADMIN.CERT
(
CERT_ID CHAR(36) NOT NULL,
CERT_CD CHAR(1) NOT NULL,
CERT_NBR CHAR(10) NOT NULL,
CERT_REQ_USR_CD_1 CHAR(10),
CERT_REQ_USR_CD_2 CHAR(10),
CERT_REQ_USR_CD_3 CHAR(10),
CERT_REQ_USR_CD_4 CHAR(10),
CERT_REQ_USR_TXT_1 VARCHAR(255),
CERT_REQ_USR_TXT_2 VARCHAR(255),
CERT_REQ_USR_TXT_3 VARCHAR(255),
CERT_REQ_USR_TXT_4 VARCHAR(255),
CERT_REQ_USR_TXT_5 VARCHAR(255),
CERT_REQ_USR_TXT_6 VARCHAR(255),
CERT_REQ_USR_TXT_7 VARCHAR(255),
CERT_REQ_USR_TXT_8 VARCHAR(255),
CERT_REQ_USR_TXT_9 VARCHAR(255),
CERT_REQ_USR_DT DATE,
LAST_MDF_USER_ID CHAR(25) NOT NULL,
LAST_MDF_ACY_TS TIMESTAMP(26,6) NOT NULL,
CONSTRAINT SQL111017085116710 PRIMARY KEY (CERT_ID)
);
In my alter query I changed the datatype of CERT_NBR form INTEGER to CHAR
using the command;
ALTER TABLE CERT ALTER COLUMN CERT_NBR SET DATA TYPE INTEGER
any further select queries asked for "reorg" of the table.
This is a common occurrence after altering tables in DB2. It should be trivially solved by calling:
reorg table table-name;
This is a command-line command, rather than an sql statement, but you can call it via SQL with the admin_cmd procedure:
call sysproc.admin_cmd('reorg table table-name');
I'm not sure why you are unable to access the new table. The error message should help you resolve this. Some possibilities:
You created it with a different username than the one you are trying to access it with.
You never committed after the create table statement.
Something went wrong and the table ended up in an inoperable state.

"There is already an object named XXXX in the database" after creating New database

I have an SQL file which I am executing on an SQL Server instance which contains the schema for a database. The file creates a brand new database (as in, a database with this name does not exist on this server):
CREATE DATABASE PROJECT;
and begins to create a relation:
CREATE TABLE Courses (
CourseID INT NOT NULL PRIMARY KEY,
Name VARCHAR(64) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
);
...
and here is what SQL Server tells me right off the bat:
Msg 2714, Level 16, State 6, Line 3
There is already an object named 'Courses' in the database.
Any idea why SQL Server tells me that there already exists a relation by the name of Courses when clearly there isn't?
Thank you for your time.
Check the database if you are using PROJECT
CREATE DATABASE PROJECT
GO
USE PROJECT
GO
CREATE TABLE Courses
(
CourseID INT NOT NULL PRIMARY KEY,
Name VARCHAR(64) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
)
GO
You are likely missing USE PROJECT statement and therefore trying to create Courses table in the master database, not in the PROJECT database.
Long shot but try using:
Use project;
CREATE TABLE Courses....