ORA-01722: invalid number with to_char timestamp - oracle

First, the table I'm trying to insert into is this table:
CREATE TABLE Message
(
MessageID varchar2(80) NOT NULL,
Message varchar2(500),
SendDate date NOT NULL,
SendID varchar2(50) NOT NULL,
Request_ID varchar2(50) NOT NULL,
PRIMARY KEY (MessageID)
);
and my insert query is this(Spring, mybatis):
INSERT INTO message (
messageid
, message
, senddate
, sendId
, request_Id
)VALUES(
#{sendidjbuser} + TO_CHAR(systimestamp, 'yyyymmddhh24missff3')
, #{message}
, sysdate
, #{sendidjbuser}
, #{requestIdjbuser}
)
I tried this on cmd and this part of the above query was the problem:
INSERT INTO message (messageId) VALUES('sendId' + TO_CHAR(systimestamp, 'yyyymmddmissff3'))
I'm on Oracle 11. I just tried inserting only TO_CHAR(systimestamp, 'yyyymmddmissff3') without adding that to a string and it worked. But I do need that part to work. Is there a right way to do that?

In Oracle, please use || or CONCAT() function to concatenate strings. You are using '+', hence getting the error.

Related

sql script not running

Here is a code snippet of a sql script which is giving me error,I have to generate a sequence on the primary_key of the table without using triggers in oracle:
CREATE SEQUENCE t1_seq START WITH 1 INCREMENT BY 1;
DROP TABLE CPR_SOURCE_SYSTEM_METADATA;
CREATE TABLE CPR_SOURCE_SYSTEM_METADATA
(
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
SYSTEM_NAME VARCHAR2(200),
DATE_FORMAT VARCHAR2(200),
CREATED_BY VARCHAR2(200),
MODIFIED_BY VARCHAR2(200),
CREATED_ON NUMBER(20),
MODIFIED_ON NUMBER(20),
IS_DELETED VARCHAR2(1),
CONSTRAINT "CPR_SOURCE_SYSTEM_PK" PRIMARY KEY ("SYSTEM_ID")
);
It is giving me the below error :
DROP TABLE CPR_SOURCE_SYSTEM_METADATA
* ERROR at line 1: ORA-00942: table or view does not exist
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
* ERROR at line 3: ORA-00907: missing right parenthesis
Not able to figure out the error,can anyone help??
SYSTEM_ID NUMBER(4) NOT NULL t1_seq.nextval,
The t1_seq.nextval segment is not valid - you cannot specify an auto-incrementing column like that.
The SQL parser is expecting to see:
SYSTEM_ID NUMBER(4) NOT NULL,
and throws the exception as the comma is not where it expects.
In Oracle 12c you can use an identity column but in earlier versions you will either need to:
Use the sequence in the SQL insert statement;
Use a trigger to insert the correct sequence value; or
Create a stored procedure to handle inserts and manage the sequence through that (disallowing direct inserts that could bypass this).

cx_Oracle.DatabaseError: ORA-00947: not enough values

I have a table:
create table employee (
employee_id NUMBER NOT NULL,
name VARCHAR2(255) NOT NULL,
notes VARCHAR2(4000),
created_by varchar2(255) not null,
created_at date default sysdate not null,
updated_by varchar2(255) not null,
updated_at date default sysdate not null,
PRIMARY KEY(vendor_id)
);
so when I insert from SQL developer:
insert into employee(employee_id, name,notes) values(1,'xyz','test');
it auto populates create_by, created_at, updated_at and updated_by.
row gets inserted successfully.
Whereas if I try to insert using cx_Oracle module in python,
cursor.execute("INSERT INTO employee VALUES (:employee_id,:name,:notes)",
{
'employee_id' : max_value,
'name' : each_vendor,
'notes' : 'test'
}
)
it throws error saying not enough values.
Why do I get this error? How can I solve it?
The answer is very simple, and has nothing to do with python. Your 2 insert statements are very different.
In the 1st, you explicitly name the columns you intend to provide values for: (employee_id, name,notes). However, in the insert statement used from Python, you don't specify the 3 columns by name. As a result, your insert statement expects you to provide the values for all columns in the table.
The fix: explicitly name the 3 columns:
cursor.execute("INSERT INTO employee (employee_id, name, notes) VALUES (:employee_id,:name,:notes)",
{
'employee_id' : max_value,
'name' : each_vendor,
'notes' : 'test'
}
)

ORA-00932: inconsistent datatypes

I'm trying to CAST MULTISET an object via PL/SQL and I'm getting the error mentioned in the subject.
I've checked the datatypes defined in the object itself and the columns in the tables and they appear to match. Same goes for the order I get the values and the order in the object.
But I keep getting the error, here is the full code:
CREATE OR REPLACE TYPE TASK_DESTINATION_LIST_OBJTYP AS OBJECT
(
ENTITY_ID NUMBER(9)
,ENTITY_CODE NUMBER(3)
,ENTITY_NAME VARCHAR2(255)
,ENTITY_FAVOTIRE NUMBER(1)
,ENTITY_PATH VARCHAR2(1535)
,STATE_CODE NUMBER(3)
,STATE_NAME VARCHAR2(50)
,RES_MSG VARCHAR2(2000)
)
/
CREATE TYPE TASK_DESTINATION_LIST_COLTYP AS TABLE OF TASK_DESTINATION_LIST_OBJTYP
The Query:
SELECT Decode (tsk_info_t.dest_dev_id,NULL,
tsk_info_t.dest_srv_id,
tsk_info_t.dest_dev_id) AS entity_id,
Decode (tsk_info_t.dest_dev_id,
NULL,1,3) AS entitytyp_code,
Decode (tsk_info_t.dest_dev_id,NULL,
tsk_info_t.dest_srv_name,
tsk_info_t.dest_dev_name) AS entity_name,
(
SELECT Count(*)
FROM pref_info_t
WHERE Nvl (dev_id, 0) = Nvl (tsk_info_t.dest_dev_id, 0)
AND srv_id = tsk_info_t.dest_srv_id) AS entity_favotire,
Decode (tsk_info_t.dest_dev_id,NULL,
(
SELECT path
FROM entity_path_view
WHERE dev_id IS NULL
AND srv_id = tsk_info_t.dest_srv_id),
(
SELECT path
FROM entity_path_view
WHERE dev_id = dest_dev_id
AND srv_id = dest_srv_id)) AS entity_path,
tsk_info_t.state_code AS state_code,
(
SELECT state_type_name
FROM ref_state_type
WHERE state_type_code = state_code ) AS state_name,
tsk_info_t.res_msg AS res_msg
FROM tsk_info_t
WHERE tsk_info_t.tsk_id = 5957
ORDER BY tsk_info_t.dest_srv_name,
tsk_info_t.dest_dev_name ASC)
AS task_destination_list_coltyp )
AS destination_list

Identifier is too long while loading from SQL*Loader

I have a table structure like this
CREATE TABLE acn_scr_upload_header
(
FILE_RECORD_DESCRIPTOR varchar2(5) NOT NULL,
schedule_no Number(10) NOT NULL,
upld_time_stamp Date NOT NULL,
seq_no number NOT NULL,
filename varchar2(100) ,
schedule_date_time Date
);
When I try to load my file via SQL*Loader I'm getting an error on this value in the column filename: Stock_Count_Request_01122014010101.csv. The error is:
Error on table ACN_SCR_UPLOAD_HEADER, column FILENAME.
ORA-00972: identifier is too long".
If I try to insert the same value into the table using an INSERT statement it works fine.
My data file Stock_Count_Request_01122014010101.csv looks like
FHEAD,1,12345,20141103
FDETL,7,100,W,20141231,SC100,B,N,1,5
FTAIL,8,6
and control file
LOAD DATA
INFILE '$IN_DIR/$FILENAME'
APPEND
INTO TABLE ACN_SCR_UPLOAD_HEADER
WHEN FILE_RECORD_DESCRIPTOR = 'FHEAD'
FIELDS TERMINATED BY ","
TRAILING NULLCOLS
(
FILE_RECORD_DESCRIPTOR position(1),
LINE_NO FILLER,
schedule_no ,
schedule_date_time,
upld_time_stamp sysdate,
seq_no "TJX_STOCK_COUNT_REQ_UPLD_SEQ.NEXTVAL",
FILENAME constant ""
)

Actual source line in ORA-06550 message

When developing an Oracle PL/SQL procedure in Toad, I encounter errors like
ORA-06550: line 97, column 25: PLS-00330: invalid use of type name or subtype name
ORA-06550: line 97, column 9: PL/SQL: Statement ignored
These given line numbers and column numbers seem to have little or nothing to do with source code line numbers. Where can I find tips or tricks that will help me identify the actual source line or actual code that caused the error? This is especially important in situations like the above (which is the result of a 700+ line source) where the error message doesn't provide clues as to details of the actual problem. (By the way, line 101 in that source is the third of a series of comment lines, and is followed by a blank line.)
(Note that this is not [yet] in a stored procedure; it is being developed and executed from source at this time. Not sure if that makes a difference since at present there is no database in which we developers have authority to CREATE PROCEDURE.)
Sample code:
SET SERVEROUTPUT ON;
DECLARE
TYPE bendemo_hdr IS RECORD
(
recid CHAR(1)
, client CHAR(30)
, filedesc CHAR(30)
, seqnum CHAR(2)
, crtdate CHAR(20)
, srtdate CHAR(8)
, stpdate CHAR(8)
);
TYPE bendemo_record IS RECORD
(
recid CHAR(1)
, ssn CHAR(9)
, empnum CHAR(15)
, eeflag CHAR(1)
, titlecode CHAR(6)
, fname CHAR(30)
, mname CHAR(30)
, lname CHAR(30)
, namesuffix CHAR(6)
, prefname CHAR(30)
, dob CHAR(8)
, dod CHAR(8)
, dverdte CHAR(8)
, dauddte CHAR(8)
, ddtesrc CHAR(6)
, gender CHAR(1)
, martstat CHAR(6)
, mstateffdt CHAR(8)
, lang CHAR(1)
, citzcde CHAR(6)
, vipflag CHAR(1)
, kyeeflag CHAR(1)
, orghrdte CHAR(8)
, lathrdte CHAR(8)
, adjhrdte CHAR(8)
, jobtitle CHAR(30)
, precntmthd CHAR(6)
, mailpref CHAR(6)
, phnepref CHAR(6)
, emalpref CHAR(6)
, hmaddrefdt CHAR(8)
, hmaddr1 CHAR(60)
, hmaddr2 CHAR(60)
, hmaddr3 CHAR(60)
, hmaddr4 CHAR(60)
, hmaddcity CHAR(60)
, hmaddstate CHAR(60)
, hmaddzip CHAR(10)
, hmaddcnty CHAR(3)
, hmphcnty CHAR(6)
, hmphnbr CHAR(16)
, hmphext CHAR(4)
, mbphcnty CHAR(6)
, mbphnbr CHAR(16)
, faxcnty CHAR(6)
, faxnbr CHAR(16)
, hmemail CHAR(100)
, wkaddrefdt CHAR(8)
, wkaddr1 CHAR(60)
, wkaddr2 CHAR(60)
, wkaddr3 CHAR(60)
, wkaddr4 CHAR(60)
, wkaddcity CHAR(60)
, wkaddstate CHAR(60)
, wkaddzip CHAR(10)
, wkaddcnty CHAR(3)
, wkphcnty CHAR(6)
, wkphnbr CHAR(16)
, wkphext CHAR(4)
, wkemail CHAR(100)
, hiresrc CHAR(30)
, bgnunit CHAR(30)
, qdroflag CHAR(1)
, hiresrcdt CHAR(8)
);
TYPE bendemo_trlr IS RECORD
(
recid CHAR(1)
, client CHAR(30)
, filedesc CHAR(30)
, reccount CHAR(9)
, field1 CHAR(15)
);
demo_hdr bendemo_hdr;
demo_rec bendemo_record;
demo_trlr bendemo_trlr;
i NUMBER;
PROCEDURE dump_hdr_rec IS
BEGIN
DBMS_OUTPUT.put(bendemo_hdr.recid);
DBMS_OUTPUT.put(bendemo_hdr.client);
DBMS_OUTPUT.put(bendemo_hdr.filedesc);
DBMS_OUTPUT.put(bendemo_hdr.seqnum);
DBMS_OUTPUT.put(bendemo_hdr.crtdate);
DBMS_OUTPUT.put(bendemo_hdr.srtdate);
DBMS_OUTPUT.put(bendemo_hdr.stpdate);
DBMS_OUTPUT.put_line('<');
END dump_hdr_rec;
PROCEDURE dump_demo_rec IS
BEGIN
-- IF l_output IS NULL THEN
DBMS_OUTPUT.put(bendemo_record.recid);
DBMS_OUTPUT.put(bendemo_record.ssn);
DBMS_OUTPUT.put(bendemo_record.empnum);
DBMS_OUTPUT.put(bendemo_record.eeflag);
DBMS_OUTPUT.put(bendemo_record.titlecode);
DBMS_OUTPUT.put(bendemo_record.fname);
DBMS_OUTPUT.put(bendemo_record.mname);
DBMS_OUTPUT.put(bendemo_record.lname);
DBMS_OUTPUT.put(bendemo_record.namesuffix);
DBMS_OUTPUT.put(bendemo_record.prefname);
DBMS_OUTPUT.put(bendemo_record.dob);
DBMS_OUTPUT.put(bendemo_record.dod);
DBMS_OUTPUT.put(bendemo_record.dverdte);
DBMS_OUTPUT.put(bendemo_record.dauddte);
DBMS_OUTPUT.put(bendemo_record.ddtesrc);
DBMS_OUTPUT.put(bendemo_record.gender);
DBMS_OUTPUT.put(bendemo_record.martstat);
DBMS_OUTPUT.put(bendemo_record.mstateffdt);
DBMS_OUTPUT.put(bendemo_record.lang);
DBMS_OUTPUT.put(bendemo_record.citzcde);
DBMS_OUTPUT.put(bendemo_record.vipflag);
DBMS_OUTPUT.put(bendemo_record.kyeeflag);
DBMS_OUTPUT.put(bendemo_record.orghrdte);
DBMS_OUTPUT.put(bendemo_record.lathrdte);
DBMS_OUTPUT.put(bendemo_record.adjhrdte);
DBMS_OUTPUT.put(bendemo_record.jobtitle);
DBMS_OUTPUT.put(bendemo_record.precntmthd);
DBMS_OUTPUT.put(bendemo_record.mailpref);
DBMS_OUTPUT.put(bendemo_record.phnepref);
DBMS_OUTPUT.put(bendemo_record.emalpref);
DBMS_OUTPUT.put(bendemo_record.hmaddrefdt);
DBMS_OUTPUT.put(bendemo_record.hmaddr1);
DBMS_OUTPUT.put(bendemo_record.hmaddr2);
DBMS_OUTPUT.put(bendemo_record.hmaddr3);
DBMS_OUTPUT.put(bendemo_record.hmaddr4);
DBMS_OUTPUT.put(bendemo_record.hmaddcity);
DBMS_OUTPUT.put(bendemo_record.hmaddstate);
DBMS_OUTPUT.put(bendemo_record.hmaddzip);
DBMS_OUTPUT.put(bendemo_record.hmaddcnty);
DBMS_OUTPUT.put(bendemo_record.hmphcnty);
DBMS_OUTPUT.put(bendemo_record.hmphnbr);
DBMS_OUTPUT.put(bendemo_record.hmphext);
DBMS_OUTPUT.put(bendemo_record.mbphcnty);
DBMS_OUTPUT.put(bendemo_record.mbphnbr);
DBMS_OUTPUT.put(bendemo_record.faxcnty);
DBMS_OUTPUT.put(bendemo_record.faxnbr);
DBMS_OUTPUT.put(bendemo_record.hmemail);
DBMS_OUTPUT.put(bendemo_record.wkaddrefdt);
DBMS_OUTPUT.put(bendemo_record.wkaddr1);
DBMS_OUTPUT.put(bendemo_record.wkaddr2);
DBMS_OUTPUT.put(bendemo_record.wkaddr3);
DBMS_OUTPUT.put(bendemo_record.wkaddr4);
DBMS_OUTPUT.put(bendemo_record.wkaddcity);
DBMS_OUTPUT.put(bendemo_record.wkaddstate);
DBMS_OUTPUT.put(bendemo_record.wkaddzip);
DBMS_OUTPUT.put(bendemo_record.wkaddcnty);
DBMS_OUTPUT.put(bendemo_record.wkphcnty);
DBMS_OUTPUT.put(bendemo_record.wkphnbr);
DBMS_OUTPUT.put(bendemo_record.wkphext);
DBMS_OUTPUT.put(bendemo_record.wkemail);
DBMS_OUTPUT.put(bendemo_record.hiresrc);
DBMS_OUTPUT.put(bendemo_record.bgnunit);
DBMS_OUTPUT.put(bendemo_record.qdroflag);
DBMS_OUTPUT.put(bendemo_record.hiresrcdt);
DBMS_OUTPUT.put_line('<');
END dump_demo_rec;
PROCEDURE dump_hdr_trlr IS
BEGIN
DBMS_OUTPUT.put(bendemo_trlr.recid);
DBMS_OUTPUT.put(bendemo_trlr.client);
DBMS_OUTPUT.put(bendemo_trlr.filedesc);
DBMS_OUTPUT.put(bendemo_trlr.reccount);
DBMS_OUTPUT.put(bendemo_trlr.field1);
DBMS_OUTPUT.put_line('<');
END dump_hdr_trlr;
BEGIN
demo_bendemo_hdr.recid := 'x';
demo_bendemo_hdr.client := 'Client';
demo_bendemo_hdr.filedesc := 'Descr';
demo_bendemo_hdr.seqnum := 'a';
demo_bendemo_hdr.crtdate := 'Created';
demo_bendemo_hdr.srtdate := 'Sorted';
demo_bendemo_hdr.stpdate := 'stop';
dump_demo_hdr(l_output, demo_hdr);
END;
Without seeing an example of the sort of code you are running it is hard to be sure if this answer is relevant, but the line number specified in the message relates to the overall block of PL/SQL being compiled, and ignores any blank lines or comments before that line. For example if your script says (with line numbers added for clarity only):
1
2 -- test script
3
4
5 begin
6
7 rubbish;
8
9 end;
Then when you try to run it you will get the error:
ORA-06550: line 3, column 3:
PLS-00201: identifier 'RUBBISH' must be declared ...
It says line 3 not line 7 because "rubbish;" is the 3rd line of the PL/SQL being compiled. The blank lines and comments above that do not count. Blank lines and comments within the block do count however.
EDIT
So, applying my rule to the code sample you posted we can ignore the 2 lines above DECLARE and so "line 97" is the 99th line:
DBMS_OUTPUT.put(bendemo_hdr.recid);
But bendemo_hdr is a TYPE not a variable, and so it makes no sense in this statement, hence the error. It is analagous to writing:
DBMS_OUTPUT.put(CHAR(1)); --!!!
What you probably meant was:
DBMS_OUTPUT.put(demo_hdr.recid);

Resources