create table JSON_TAB (JSON_VAL CLOB);
-- tried to add the constraint like this CONSTRAINT JTE_CK check (JSON_VAL is json) butt says it expects null so I didn't create it for now.
I am trying to execute the statement
SELECT JT.Ime, JT.Broj, JT.Pozicija
FROM JSON_TAB JTE,
JSON_TABLE (JTE.JSON_VAL, '$.players[*]'
COLUMNS (Ime VARCHAR2(20) PATH '$.name',
Broj NUMBER PATH '$.number',
Pozicija VARCHAR2 PATH '$.position')) JT ;
and receiving an error SQL command not properly ended.
JSON_VAL is a CLOB!
Is it a problem with syntax, data type or something else?
I took the example from youtube tutorial and entered it manually.
ORACLE version is 12.1.0.2.0.
Related
I have problem inserting values in my SQL server database on Azure, I am getting the following error:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
I don't understand where I am wrong, I just created the server, and I am trying to experiment but cant fix this.
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
Creating the table works fine, the only thing that doesn't work is the second command INSERT
I suspect that the reason is that you haven't defined a lenght for varchar and it defaults to 1 as length. Therefore your value gets truncated.
Set a varchar length to something like varchar(200) and you should be good to go.
This looks like the fact that the CREATE portion of your procedure for the table doesn't include a length of varchar, so you'd have to specify a length such as varchar(50) since the default is 1. Refer to the official MS docs in the link, in the remarks.
docs.miscrosoft.com
Also, here is the syntax for the CREATE TABLE in Azure which might be helpful as well.
Syntax of Azure CREATE TABLE
Does anyone know which of the DB2 special registers are allowed in CREATE TABLE statement for DB2 temporal tables or in general in CREATE TABLE statement?
I am trying to CREATE TABLE COLUMNS WITH CURRENT PACKAGESET or CLIENT_APPNAME, they are not being identified by DB2. I tried almost all combinations of key words (marked in bold).
Create table Statement
CREATE TABLE EMPLOYEE
(EMP_NR INT NOT NULL
,FIRST_NAME CHAR(20) NOT NULL
,LAST_NAME CHAR(20) NOT NULL
,TSROWBEGIN TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN
,TSROWEND TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END
,TSPGMSTART TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS TRANSACTION START ID
**,IDTERMANV CHAR(8) GENERATED DEFAULT WITH CURRENT PACKAGESET
,IDTERM VARCHAR(128) GENERATED DEFAULT WITH CLIENT_APPLNAME**
,STDB2ACTION CHAR(1) GENERATED ALWAYS AS ( DATA CHANGE OPERATION )
,PERIOD SYSTEM_TIME(TSROWBEGIN, TSROWEND)
);
It results in
ILLEGAL USE OF KEYWORD CURRENT. TOKEN WAS EXPECTED. SQLCODE=-199, SQLSTATE=42601, DRIVER=3.68.61
or
ILLEGAL USE OF KEYWORD CLIENT_APPLNAME. TOKEN WAS EXPECTED. SQLCODE=-199, SQLSTATE=42601, DRIVER=3.68.61
Any suggestions on how to create column with default value of program name which is doing CUD operation on the table?
You can use the special registers for current date / time / timestamp and for user information (user, session user, system user). Take a look at the CREATE TABLE reference.
The same reference also has a section about what cannot be used, in case you try to use a function or put the CREATE statement into a procedure. Among other things, the GENERATED value cannot be based on the following:
Special registers and built-in functions that depend on the value of a special register.
A table exists in the environment of production with the following structure:
CREATE TABLE gold_dwh_reload (
msisdn NUMBER(13,0) NOT NULL,
recharge_date TIMESTAMP(6) NOT NULL,
impacted_balances VARCHAR2(4000) NULL,
lc_state VARCHAR2(5) NOT NULL)
TABLESPACE sopfun_tab
NOCOMPRESS
/
A normal consultation would the following result by example:
MSISDN RECHARGE_DATE IMPACTED_BALANCES LC_STATE
584124723950 29.04.15 13:23:38.000 <balance><name>B_LPP_Bs_Main</name><label></label><before>697.21429</before><after>797.21429</after><amount>100</amount><start></start><end></end><unit>Bs</unit></balance><balance><name>B_LPP_KB_National</name><label>PA_Adjustment</label><before>0</before><after>10240</after><amount>10240</amount><start>29042015000000</start><end>29052015000000</end><unit>Kbytes</unit></balance><balance><name>B_LSP_Bs_Promotions</name><label>PA_Adjustment</label><before>0</before><after>25</after><amount>25</amount><start>29042015000000</start><end>29052015000000</end><unit>Bs</unit></balance> ACT
But i need to break the IMPACTED_BALANCES field in columns. Anyone know how I do it?
This is typically done using XMLTable
select
msisdn, recharge_date,
x_name, x_label, x_before, x_after, x_amount,
to_date(x_start, 'DDMMYYYYHH24MISS') x_start,
to_date(x_end, 'DDMMYYYYHH24MISS') x_end,
x_unit,
lc_state
from gold_dwh_reload
cross join
xmltable('/balances/balance'
passing xmltype('<balances>'||impacted_balances||'</balances>')
columns
x_name path '/balance/name',
x_label path '/balance/label',
x_before number path '/balance/before',
x_after number path '/balance/after',
x_amount number path '/balance/amount',
x_start path '/balance/start',
x_end path '/balance/end',
x_unit path '/balance/unit'
);
Here's a SQL Fiddle.
Mixing SQL and XML is powerful but creates many potential type safety issues. A single invalid date, number, or XML file will crash the whole query. The string in your example is not valid XML, that's why I concatenated another tag to the beginning and end.
I am creating table in hive like:
CREATE TABLE SEQUENCE_TABLE(
SEQUENCE_NAME VARCHAR2(225) NOT NULL,
NEXT_VAL NUMBER NOT NULL
);
But, in result there is parse exception. Unable to read Varchar2(225) NOT NULL.
Can anyone guide me that how to create table like given above and any other process to provide path for it.
There's no such thing as VARCHAR, field width or NOT NULL clause in hive.
CREATE TABLE SEQUENCE_TABLE( SEQUENCE_TABLE string, NEXT_VAL bigint);
Please read this for CREATE TABLE syntax:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable
Anyway Hive is "SQL Like" but it's not "SQL". I wouldn't use it for things such as sequence table as you don't have support for transactions, locking, keys and everything you are familiar with from Oracle (though I think that in new version there is simple support for transactions, updates, deletes, etc.).
I would consider using normal OLTP database for whatever you are trying to achieve
only you have option here like:
CREATE TABLE SEQUENCE_TABLE(SEQUENCE_NAME String,NEXT_VAL bigint) row format delimited fields terminated by ',' stored as textfile;
PS:Again depends the types to data you are going to load in hive
Use following syntax...
CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.] table_name
[(col_name data_type [COMMENT col_comment], ...)]
[COMMENT table_comment]
[ROW FORMAT row_format]
[STORED AS file_format]
And Example of hive create table
CREATE TABLE IF NOT EXISTS employee ( eid int, name String,
salary String, destination String)
COMMENT ‘Employee details’
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘\t’
LINES TERMINATED BY ‘\n’
STORED AS TEXTFILE;
I'm not able to update a table with Hibernate.
The table is created with the following statement and stored in a PostgreSQL Database.
CREATE TABLE staat
(
sta_id serial NOT NULL, -- ID des Staates
sta_bezeichnung character varying(50) NOT NULL, -- Langbezeichnung
sta_lkz character varying(10) NOT NULL, -- Laenderkennzeichen
sta_vorwahl character varying(10), -- Telefon Landesvorwahl
sta_eu boolean DEFAULT false, -- Ist der Staaat ein EU-Mitglied?
CONSTRAINT staat_pkey PRIMARY KEY (sta_id),
CONSTRAINT staat_sta_bezeichnung_key UNIQUE (sta_bezeichnung)
)
WITH (
OIDS=FALSE
);
Rights are set correct, because select, insert and update are possible with a SQL Manager. The following update statement also works with the SQL Manager.
But now the problem: when I want to update the table with my application, it generates PSQLException with the following output:
WARNUNG: SQL Error: 0, SQLState: 22004 and ERROR: query string argument of EXECUTE is null
The source code:
Query q = s.createQuery("Update Staat set sta_bezeichnung = 'BlaBla' where sta_id = 1");
int status = q.executeUpdate();
I think the problem has something to do with NOT NULL columns, because tables without NOT NULL columns can be updated with the same source code...
Does anyone has an idea of what is wrong or what I have to do???
Edit: tried with SQL (q.executeSQLUpdate) and HQL
Transaction tr = s.beginTransaction();
staat = (Staat)s.get(Staat.class, new Integer(0));
staat.setStaBezeichnung("BlaBla");
s.update(staat);
tr.commit();
Generates followin error: ERROR: query string argument of EXECUTE is null and Could not synchronize database state with session
Edit2: update works fine without hibernate
Please check your Hibernate mapping file for Staat maybe you have not configured a not-null constraint for some attribute/field, which is not-null in database.
It looks like you are trying to use SQL query where HQL query is expected. Try
Query q = s.createSQLQuery(....);
Or better yet, use mapped classes with HQL. But I don't know your mapped classes, so can't speculate on specifics.