I am using sqlplus to create a table called Person
the script
SQL> CREATE TABLE Person (
1. _id INT NOT NULL,
2. name VARCHAR(45) NOT NULL,
3. salary DOUBLE(7) NOT NULL,
4. CONSTRAINT chk_Person CHECK(salary > 0 AND salary < 1000000)
5. );
However I get the following error message
ERROR at line 3;
ORA_00905: missing keyword
Please help. thanks
I think sqlplus doesnot have double datatype.You can use double precision
SQL FIDDLE
SQL: DATA TYPES
Related
I keep having a cryptic "Syntax error" in this statement for an Informix database.
CREATE TABLE Historial
(
id_evento SERIAL PRIMARY KEY CONSTRAINT Historial_claves_primarias,
foranea_CI_Persona INT REFERENCES Personas (CI) CONSTRAINT Historial_fk_Personas_CI,
IP varchar(20) NOT NULL CONSTRAINT ip_vacia,
query lvarchar(1000) NOT NULL CONSTRAINT Historial_query_vacia,
fecha_hora DATETIME NOT NULL CONSTRAINT fecha_historial_vacio
);
Can someone help me and point out what it is? I seriously cant see it.
I have just found out that im supposed to give the precision of the measure as stated below, but with a cryptic error like that, what do you expect.
drop table if exists Historial;
CREATE TABLE Historial
(
id_evento SERIAL PRIMARY KEY CONSTRAINT Historial_claves_primarias,
foranea_CI_Persona INT REFERENCES Personas (CI) CONSTRAINT Historial_fk_Personas_CI,
IP varchar(20) NOT NULL CONSTRAINT ip_vacia,
query lvarchar(1000) NOT NULL CONSTRAINT Historial_query_vacia,
fecha_hora datetime year to minute not null constraint Historial_fecha_vacia
);
I just started working on Netezza, I would like to create a simple stored procedure to go through a table using cursor or temp table like MS SQL, anyway, this simple task starts with something wrong and I have no idea on it, here is the code:
CREATE OR REPLACE PROCEDURE My_FirstSP() RETURNS INT4 LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
ID int;
CREATE TABLE RX5201901
(
ID INT IDENTITY(1,1),
CreatedOn DATETIME
);
END_PROC;
Error:
^ found "" (at char 76) unterminated BEGIN_PROC string
Thank you very much.
Are you by chance executing the create from aginity?
In that case You need to right-click on the background and change the setting to 'procedure mode'
Otherwise netezza only submits the sql between the two nearest semi-colons (;)
Resolve this problem to create stored procedures
Click Right >> Option >>
Query kind : SP/ Function
Ok
2. CTRL + F5
I have 3 scenarios to implement.
Case 1- When IM.Code=IME.Code and IM.Effective_st_dt=IME.effective_st_dt and IM.Effective_end_dt =IME.Effective-end_date
Action-
In this case i need to update the IM with currentMrp and currentCp.
Case 2- When IM.Code=IME.Code and IM.Effective_st_dt!=IME.effective_st_dt and IM.Effective_end_dt =IME.Effective-end_date
Action-
1.)Pick the recent Effective_st_dt record from IM and Update the Effective_end_date with (IME.Effective_st_dt)-1
2.)then Insert a new record from IME which has new effective_st_dt also this record lastMRP and lastcp is the currentmrp and Currentcp of the previous record which is updated in 1
Case 3- When IM.Code=IME.Code and IM.Effective_st_dt!=IME.effective_st_dt and IM.Effective_end_dt !=IME.Effective-end_date
Action-
1.)Pick the recent Effective_st_dt record from IM and Update the Effective_end_date with (IME.Effective_st_dt)-1
2.)then Insert a new record from IME which has new effective_st_dt also this record lastMRP and lastcp is the currentmrp and Currentcp of the previous record which is updated in 1
This is the script of my tables
Create Table IM
(
ID int idenetity (1,1)
,Code varchar(100)
,CurrentMrp float
,CurrentCP float
,lastMrp float
,lastCp float
, effective_st_dt date
,effective_end_dt date
)
Create table IME
(
Code varchar(100)
,CurrentMrp float
,CurrentCP float
,Effective_st_dt date
,Effective_end_dt date
)
insert into IM (code, currentMrp, currentCp, lastMRP, lastCP, effective_st_dt, effective_end_dt)
Select
'CA123', 10.12, 5.0, 8.20, 4, '2014-05-01', '2014-05-31'
union
Select 'CA123',15.0,5.0,10.12,8.20,'2014-06-01','2014-08-31'
union
Select 'CA121',50.0,15.0,45.0,25.0,'2014-04-01','2014-05-31'
union
Select 'CA121',75.0,25.0,50.0,15.0,'2014-06-01','2014-06-30'
union
Select 'CA131',53.0,12.0,35.0,10.0,'2014-05-01','2014-05-31'
union
Select 'CA131',60.0,15.0,53.0,12.0,'2014-06-01','2014-08-31'
Insert into IME (code,effective_st_dt,effective_end_dt)
Select ('CA123',20.0,5.0,'2014-06-01','2014-08-31')
union
Select ('CA123',25.0,6.0,'2014-06-20','2014-08-31')
union
Select ('CA123',35.0,7.0,'2014-07-15','2015-03-31')
please help me to solve this
Your help is appreciated
its better you use left join instead of inner join in this particular case, else not equal to will not give you the correct results.
I would like to change a couple of column values before they get inserted.
I am using Informix as database.
I have a table consisting of 3 columns: Name (NVARCHAR), Type (INT), Plan (NVARCHAR).
Every time a new record is inserted, I would like to check the Name value before inserting it. If the Name starts with an F, I would like to set the Type value to 1 and the Plan Name to "Test"
In short, what I want the trigger to do is:
For every new insertion, first check if Name value starts with F.
If yes, set the Type and Plan to 1 and "Test" then insert.
If no, insert the values as-is.
I have looked up the CREATE TRIGGER statement with BEFORE and AFTER. However, I would like to have a clearer example. My case would probably involve BEFORE though.
The answer of #user3243781 get close, but did not work because it returns the error:
-747 Table or column matches object referenced in triggering statement.
This error is returned when a triggered SQL statement acts on the
triggering table, or when both statements are updates, and the column
that is updated in the triggered action is the same as the column that
the triggering statement updates.
So the alternative is handle with the NEW variable directly.
For that you need to use a procedure with the triggers reference resource, which means the procedure will able to act like the trigger by self.
Below is my example which I run with dbaccess over a Informix v11.70.
This resource is available only for versions +11 of the engine, as far I remember.
create table teste ( Name NVARCHAR(100), Type INT , Plan NVARCHAR(100) );
Table created.
create procedure check_name_values()
referencing new as n for teste ;;
define check_type integer ;;
define check_plan NVARCHAR ;;
if upper(n.name) like 'F%' then
let n.type = 1;;
let n.plan = "Test";;
end if
end procedure ;
Routine created.
;
create trigger trg_tablename_ins
insert on teste
referencing new as new
for each row
(
execute procedure check_name_values() with trigger references
);
Trigger created.
insert into teste values ('cesar',99,'myplan');
1 row(s) inserted.
insert into teste (name) values ('fernando');
1 row(s) inserted.
insert into teste values ('Fernando',100,'your plan');
1 row(s) inserted.
select * from teste ;
name cesar
type 99
plan myplan
name fernando
type 1
plan Test
name Fernando
type 1
plan Test
3 row(s) retrieved.
drop table if exists teste;
Table dropped.
drop procedure if exists check_name_values;
Routine dropped.
create trigger trg_tablename_ins
insert on tablename
referencing new as new
for each row
(
execute procedure check_name_values
(
new.name,
new.type,
new.plan
)
);
create procedure check_name_values
(
name NVARCHAR,
new_type integer,
new_plan NVARCHAR,
)
define check_type integer ;
define check_plan NVARCHAR ;
let check_type = 1;
let check_plan = "Test";
if name = 'F%'
then
insert into tablename (name,type,plan) values (name,check_type,check_plan);
else
insert into tablename (name,type,plan) values (name,new_type,new_plan);
end if ;
end procedure ;
Here is my version an adaptation of an old example I found in the informix usenet group.
It is possible to update columns in a trigger statement but not very straight forward. You have to use stored procedures an the into statement with the execute procedure command.
It worked here for IBM Informix Dynamic Server Version 12.10.FC11WE.
drop table if exists my_table;
drop sequence if exists my_table_seq;
create table my_table (
id INTEGER
NOT NULL,
col_a char(32)
NOT NULL,
col_b char(20)
NOT NULL,
hinweis char(64),
uslu char(12)
DEFAULT USER
NOT NULL,
dtlu DATETIME YEAR TO SECOND
DEFAULT CURRENT YEAR TO SECOND
NOT NULL
)
;
create sequence my_table_seq
increment 1
start 1;
drop procedure if exists get_user_datetime();
create function get_user_datetime() returning char(12),datetime year to second;
return user, current year to second;
end function
;
drop trigger if exists ti_my_table;
create trigger ti_my_table insert on my_table referencing new as n for each row (
execute function get_user_datetime() into uslu, dtlu
)
;
drop trigger if exists tu_my_table;
create trigger tu_my_table update on my_table referencing new as n for each row (
execute function get_user_datetime() into uslu, dtlu
)
;
insert into my_table values (my_table_seq.nextval, "a", "b", null, "witz", mdy(1,1,1900)) ;
SELECT *
FROM my_table
WHERE 1=1
;
I am trying to import a file as a table in SQLite 3 using a Ruby script. I need to assign a tab separator, and I used the following code:
db = SQLite3::Database.new("meshdb2.db")
db.execute("CREATE TABLE IF NOT EXISTS pubmed(id integer primary key,prideID INT NOT NULL,pubmedID VARCHAR(10) NOT NULL)
db.prepare(".separator '\t'")
I am coming back with a "/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/lib/sqlite3/errors.rb:62:in `check': near ".": syntax error (SQLite3::SQLException)" error, and I think it is because of the db.prepare() command. What is the proper command when I want to pass settings through Ruby to SQLite 3?
-Bobby
You're missing the ending quotation mark on the second line after your query.
db.execute("CREATE TABLE IF NOT EXISTS pubmed(id integer primary key,prideID INT NOT NULL,pubmedID VARCHAR(10) NOT NULL")
# >------------------->------------------->------------------->------------------->------------------->----------------^