multiple BLOB file insertion in oracle using SQLdeveloper - sql

I want to insert Multiple BLOB file at once ​​in "USER_PROFILE" table using loop by procedure/function.
Working on Oracle DB using SQLdeveloper
BLOB Files:
user.resetpassword.email.body.html
password.expiry.notification.email.html
password.expiry.notification.subject.txt
user.resetpassword.email.subject.txt
BLOB FILE DIRECTORY : U_PROFILE
BLOB column name : PROP_VALUE
Unique key : PROP_KEY (This column naming conventions will be same with BLOB file names)
CREATE TABLE "USER_PROFILE" (
"USER_PROFILE_PID" VARCHAR2(40 BYTE)
, "PROP_KEY" VARCHAR2(100 BYTE)
, "PROP_VALUE" BLOB
, "MODIFIED_DTS" DATE
, "BUILD_VERSION" VARCHAR2(100 BYTE)
, "DESCRIPTION" VARCHAR2(4000 BYTE)
)
​;
INSERT INTO user_profile (
user_profile_pid
, prop_key
, modified_dts
, build_version
, description
) VALUES (
'CTP-1000'
, 'password.expiry.notification.email'
, NULL
, '1.2'
, 'User Account Expiry notification'
);
INSERT INTO user_profile (
user_profile_pid
, prop_key
, modified_dts
, build_version
, description
) VALUES (
'CTP-1001'
, 'password.expiry.notification.subject'
, NULL
, '1.2'
, 'User Account Expiry notification subject'
);

Related

Select and insert on the same table

Can you tell me what is wrong with this query:
INSERT INTO properties 
(
f_gen_id(NULL)
, 'ASHAgroup18E'
, entity
, effective_dt
, property_key
, property_value
, created_by
, create_ts
, updated_by
, update_ts
) 
SELECT f_gen_id(NULL)
, 'ASHAgroup18E'
, entity
, effective_dt
, property_key
, property_value
, description
, created_by
, create_ts
, updated_by
, update_ts
-- 'UIL-Migration', CURRENT_TIMESTAMP, 'UIL-Migration', CURRENT_TIMESTAMP 
FROM properties
WHERE group_key = 'ASHAgroup18B';
In the INSERT part you should have column names, not a function
INSERT INTO properties (f_gen_id(NULL),...
replace this with the name of the primary key/id column
INSERT INTO properties (id,...
Update
I guess also the second column in the INSERT is incorrect since it contains a string. Again, replace it with a column name

Counting of Tries for a log

I have 3 tables. INV_HDR, PAYM_LOG, PAY_CA. The schema are as follow
CREATE TABLE INV_HDR
(
INV_HDR_ID NUMBER(19, 0) DEFAULT "SEQ_INV_HDR_ID"."NEXTVAL" NOT NULL
, INV_NO VARCHAR2(30 BYTE) NOT NULL
, INV_TYPE_CD VARCHAR2(10 BYTE)
, INV_PARTY_UEN VARCHAR2(17 BYTE)
, INV_DT DATE
, GIRO_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
, INV_STS_CD VARCHAR2(11 BYTE) DEFAULT '1' NOT NULL
, PAYMENT_STS_CD VARCHAR2(11 BYTE) DEFAULT '1' NOT NULL
, RFD_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
, WAIVE_WRITE_DRAW_STS_CD VARCHAR2(11 BYTE) DEFAULT '0' NOT NULL
) ;
CREATE TABLE PAYM_LOG
(
PAYMENT_LOG_ID NUMBER(19, 0) DEFAULT "SEQ_PAYMENT_LOG_ID"."NEXTVAL" NOT NULL
, INV_HDR_ID NUMBER(19, 0) NOT NULL
, INV_PARTY_UEN VARCHAR2(17 BYTE)
, INV_NO VARCHAR2(30 BYTE) NOT NULL
, TRANS_DT DATE
, AMT NUMBER(15, 2) DEFAULT 0 NOT NULL
, VOUCHER_NO VARCHAR2(30 BYTE)
, REASON VARCHAR2(60 BYTE)
, CREATED_BY VARCHAR2(35 BYTE) NOT NULL
, CREATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, LAST_UPDATED_BY VARCHAR2(35 BYTE) NOT NULL
, LAST_UPDATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, PAYMENT_STS VARCHAR2(11 BYTE)
) ;
CREATE TABLE PAY_CA
(
PAY_CA_ID NUMBER(19, 0) DEFAULT "SEQ_PAY_CA_ID"."NEXTVAL" NOT NULL
, CA_ID VARCHAR2(2 BYTE)
, TRANS_DT DATE
, JOURNAL_HDR_ID NUMBER(19, 0)
, CREATED_BY VARCHAR2(35 BYTE) NOT NULL
, CREATED_DT TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL
, LAST_UPDATED_BY VARCHAR2(35 BYTE) NOT NULL
)
INV_HDR
1. Invoice is created for every Invoice generated. PK = INV_HDR_ID
2. GIRO_STS_CD will be updated from 2(Success) to 3(Fail) when payment has been made successfully
PAYM_LOG
1. Every attempted payment is recorded.
2. PAYMENT_STS = 12 (Fail), 13 (Pass)
PAY_CA
1. Only successful payment that has been made will have records created.
Thing is I would like to generate a report where there are 4 statuses.
1. GIRO Successful -- 1st time successful payment
2. GIRO Failed
3. GIRO Failed - 1st Retry
4. GIRO Failed - 2nd Retry
My report columns will be
S/N | INV_HDR.UNV_PARTY_UEN | CA_ID | Payment Status | Amount | Retry
With a summary to count the 4 different statuses.
Summary Count Amount
GIRO Successful x 100
GIRO Failed y 200
GIRO Failed - 1st Retry z 50
GIRO Failed - 2nd Retry w 10
Is it possible to do it in a single SQL? I have something like this so far..
SELECT PAY_CA.CA_ID, INV_HDR.INV_PARTY_UEN ,
INV_HDR.GIRO_STS_CD AS PAYMENT_STATUS,
PAY_CA.AMT,
SUM (
CASE
WHEN PAYM_LOG.PAYMENT_STS = '12'
THEN 1
ELSE 0
END ) AS RETRY
FROM INV_HDR,
PAYM_LOG,
PAY_CA
WHERE INV_HDR.INV_HDR_ID = CA_PAY.INV_HDR_ID
AND INV_HDR.INV_NO = PAYM_LOG.INV_NO
AND INV_HDR.GIRO_STS_CD IN ('2' ,'3')
GROUP BY PAY_CA.CA_ID ,
INV_HDR.INV_PARTY_UEN ,
INV_HDR.GIRO_STS_CD ,
PAY_CA.AMT
Thing is I need to retrieve both Failed and successful payment. Joining with PAY_CA will only allow me to get successful payments. How do i also get non-successful payments into counting of the retries?

Error during copy command in Postgres

I'm trying to insert data into my table in Postgres with the COPY command and I had the following error:
ERROR: extra data after last expected column
There is my COPY command :
copy basic_data_cs from '/data/tmp/basic_data.csv' delimiter ';' header csv;
There is my table structure :
CREATE FOREIGN TABLE basic_data_cs
( oid4 BIGINT , oid3 BIGINT , date_creation date , date_modif date , id_princ text , nb_ref INTEGER , coobox INTEGER , otype_bin INTEGER , ra REAL , ra_prec SMALLINT , dec REAL , dec_prec SMALLINT , coo_err_maja FLOAT , coo_err_maja_prec SMALLINT , coo_err_mina FLOAT , coo_err_mina_prec SMALLINT , coo_err_angle SMALLINT , coo_qual TEXT , coo_wavelength TEXT , coo_bibcode TEXT , pmra REAL , pmra_prec SMALLINT , pmdec REAL , pmdec_prec SMALLINT , pm_err_maja FLOAT , pm_err_maja_prec SMALLINT , pm_err_mina FLOAT , pm_err_mina_prec SMALLINT , pm_err_angle SMALLINT , pm_qual text , pm_bibcode text , plx_value REAL , plx_prec SMALLINT , plx_error FLOAT , plx_error_prec SMALLINT , plx_qual TEXT , plx_bibcode TEXT , rvz_type TEXT , rvz_radvel REAL , rvz_radvel_prec SMALLINT , rvz_redshift REAL , rvz_redshift_prec SMALLINT , rvz_error FLOAT , rvz_error_prec SMALLINT , rvz_qual TEXT , rvz_nature TEXT , rvz_wavelength TEXT , rvz_bibcode TEXT , sp_type TEXT , sp_type_bin BIGINT , sp_qual text , sp_nature text , sp_bibcode text , morph_type text , morph_type_bin INTEGER , morph_qual text , morph_bibcode text , galdim_majaxis FLOAT , galdim_majaxis_prec SMALLINT , galdim_minaxis FLOAT , galdim_minaxis_prec SMALLINT , galdim_angle SMALLINT , galdim_incl SMALLINT , galdim_qual text , galdim_wavelength text , galdim_bibcode text , nb_parents INTEGER , nb_children INTEGER , nb_siblings INTEGER , id_princ_select text , hpx BIGINT , otype text , vlsr REAL , vlsr_prec SMALLINT , vlsr_error REAL , vlsr_error_prec SMALLINT , vlsr_wavelength text , vlsr_bibcode text) server cstore_server;
And there is a line from my csv file :
10396425;;2016-08-02;2016-08-02;SDSS J001954.03+025717.0;1;11278;-14680064;4.975139;7;2.954735;7;;-1;;-1;32767;C;O;2014A&A...563A..54P;;;;;;;;;;;;;;;;;;z;263064.159868091;0;2.9147;4;0.0003;4;C;s;O;2014A&A...563A..54P;;;;;;;;;;;;;;;;;;;;;;;(0.0868325562943782 , 0.0515698542739147);4635816;QSO;;;;;;;;;;
This command worked for an another 'classic' table with the same CSV file and the same command.
This would be because , your table contains 78 columns and your csv delimited file has 82 entries.
Either you get a new csv with same columns as table or you can try
check the top answer from there

Extract data from flat file to a table

I'm using Oracle database 9i.
I want to extract data from flat file(.txt) then insert them into a table (on the client) using other than sql_loader, utl_file, external table, sqldeveloper, toad.
Example of flat file source :
Allain Analyst 13456...
King manager 98768 ...
This extracts data from file_name.csv file and inserts it into EX_TABLE
create table EX_TABLE(
COL1 varchar2(13 BYTE)
,COL2 varchar2(250 CHAR)
,COL3 varchar2(210 CHAR)
,COL4 varchar2(70 CHAR)
)
organization external
(type oracle_loader
default directory EXT_DIR
access parameters
(
records delimited by newline
fields terminated by ','
missing field values are null
reject rows with all null
fields(COL1 CHAR(13)
,COL2 char(250)
,COL3 char(210)
,COL4 char(70)
)
)
location ('file_name.csv')
)
reject limit unlimited
;
CREATE TABLE EX_TABLE
( COL1 varchar2(3 BYTE)
,COL2 varchar2(3 CHAR)
,COL3 varchar2(1 CHAR)
,COL4 varchar2(10 CHAR)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY DAT_DIR
ACCESS PARAMETERS
( RECORDS DELIMITED BY \n
CHARACTERSET JA16SJISTILDE BADFILE BAD_DIR : 'test_%p_%a.bad' LOGFILE LOG_DIR : 'test_%p_%a.log' READSIZE 10485760 FIELDS LRTRIM MISSING FIELD VALUES ARE NULL REJECT ROWS
WITH ALL NULL FIELDS ( COL1 ( 1: 3) CHAR(3) ,COL2 ( 4: 6) CHAR(3) ,COL3 ( 7: 7) CHAR(1) COL4 ( 8: 17) CHAR(10) ))
LOCATION
( 'STS.txt'
)
)
REJECT LIMIT UNLIMITED;
Loading data to external table based on position in the file

Oracle XPath: Parent Node Attribute?

I'm an XPath newbie; I've found a way to do what I want, but wonder if there's another way that can save me some repetition in my code.
I have this table:
CREATE TABLE t (
quark_p1 VARCHAR2(4)
, quark_p2 VARCHAR2(7)
, quark_p3 VARCHAR2(6)
, one VARCHAR2(1)
, two VARCHAR2(1)
, three VARCHAR2(1)
, four VARCHAR2(1)
, five VARCHAR2(1)
, six VARCHAR2(1)
, seven VARCHAR2(1)
, eight VARCHAR2(1)
, nine VARCHAR2(1)
)
;
The following PL/SQL anonymous block does what I want, extracting into this table the structure from my given XML:
BEGIN
INSERT INTO t (
quark_p1
, quark_p2
, quark_p3
, one
, two
, three
, four
, five
, six
, seven
, eight
, nine
)
SELECT x.quark_p1
, x.quark_p2
, x.quark_p3
, x.one
, x.two
, x.three
, x.four
, x.five
, x.six
, x.seven
, x.eight
, x.nine
FROM XMLTABLE('/BASIS/QUARK'
PASSING XMLTYPE (
'<BASIS>
<QUARK P1="up" P2="charm" P3="bottom">
<NEST>
<ONE>A</ONE>
<TWO>B</TWO>
<THREE>C</THREE>
<FOUR>D</FOUR>
<FIVE>E</FIVE>
<SIX>F</SIX>
<SEVEN>G</SEVEN>
<EIGHT>H</EIGHT>
<NINE>I</NINE>
</NEST>
</QUARK>
<QUARK P1="up" P2="strange" P3="top">
<NEST>
<ONE>J</ONE>
<TWO>K</TWO>
<THREE>L</THREE>
<FOUR>M</FOUR>
<FIVE>N</FIVE>
<SIX>O</SIX>
<SEVEN>P</SEVEN>
<EIGHT>Q</EIGHT>
<NINE>R</NINE>
</NEST>
</QUARK>
</BASIS>')
COLUMNS quark_p1 VARCHAR2(4) PATH '#P1'
, quark_p2 VARCHAR2(7) PATH '#P2'
, quark_p3 VARCHAR2(6) PATH '#P3'
, one VARCHAR2(1) PATH 'NEST/ONE'
, two VARCHAR2(1) PATH 'NEST/TWO'
, three VARCHAR2(1) PATH 'NEST/THREE'
, four VARCHAR2(1) PATH 'NEST/FOUR'
, five VARCHAR2(1) PATH 'NEST/FIVE'
, six VARCHAR2(1) PATH 'NEST/SIX'
, seven VARCHAR2(1) PATH 'NEST/SEVEN'
, eight VARCHAR2(1) PATH 'NEST/EIGHT'
, nine VARCHAR2(1) PATH 'NEST/NINE'
) x;
END;
/
This results in the following, which is what I'm after:
SQL> SELECT * FROM t
2 ;
QUARK_P1 QUARK_P2 QUARK_P3 O T T F F S S E N
-------- -------- -------- - - - - - - - - -
up charm bottom A B C D E F G H I
up strange top J K L M N O P Q R
SQL>
Since the "NEST" level is repeated so often, I'd like to pull it up into the starting node, and still get the same results. I'm looking to do something like the following:
BEGIN
INSERT INTO t (
quark_p1
, quark_p2
, quark_p3
, one
, two
, three
, four
, five
, six
, seven
, eight
, nine
)
SELECT x.quark_p1
, x.quark_p2
, x.quark_p3
, x.one
, x.two
, x.three
, x.four
, x.five
, x.six
, x.seven
, x.eight
, x.nine
-- Notice, I changed the starting node from /BASIS/QUARK to /BASIS/QUARK/NEST....
FROM XMLTABLE('/BASIS/QUARK/NEST'
PASSING XMLTYPE (
'<BASIS>
<QUARK P1="up" P2="charm" P3="bottom">
<NEST>
<ONE>A</ONE>
<TWO>B</TWO>
<THREE>C</THREE>
<FOUR>D</FOUR>
<FIVE>E</FIVE>
<SIX>F</SIX>
<SEVEN>G</SEVEN>
<EIGHT>H</EIGHT>
<NINE>I</NINE>
</NEST>
</QUARK>
<QUARK P1="up" P2="strange" P3="top">
<NEST>
<ONE>J</ONE>
<TWO>K</TWO>
<THREE>L</THREE>
<FOUR>M</FOUR>
<FIVE>N</FIVE>
<SIX>O</SIX>
<SEVEN>P</SEVEN>
<EIGHT>Q</EIGHT>
<NINE>R</NINE>
</NEST>
</QUARK>
</BASIS>')
-- ...and I changed all the paths here
COLUMNS quark_p1 VARCHAR2(4) PATH '../#P1'
, quark_p2 VARCHAR2(7) PATH '../#P2'
, quark_p3 VARCHAR2(6) PATH '../#P3'
, one VARCHAR2(1) PATH 'ONE'
, two VARCHAR2(1) PATH 'TWO'
, three VARCHAR2(1) PATH 'THREE'
, four VARCHAR2(1) PATH 'FOUR'
, five VARCHAR2(1) PATH 'FIVE'
, six VARCHAR2(1) PATH 'SIX'
, seven VARCHAR2(1) PATH 'SEVEN'
, eight VARCHAR2(1) PATH 'EIGHT'
, nine VARCHAR2(1) PATH 'NINE'
) x;
END;
/
This seems to me like it should work, but I get this error:
FROM XMLTABLE('/BASIS/QUARK/NEST'
*
ERROR at line 28:
ORA-06550: line 28, column 10:
PL/SQL: ORA-19110: unsupported XQuery expression
ORA-06550: line 2, column 5:
PL/SQL: SQL Statement ignored
SQL>
Am I missing something simple, or can I not get there from here?
Thanks.
I was surprised to find from
How to get the name of the parent element in an Oracle XPath expression?
that it works if you just put "./" in front of the "../"