Below are two proc running in sybase. The first has param name with value, the second only value. The first one runs fine, but when I run the second I get Implicit conversion from datatype 'INT' to 'VARCHAR' is not allowed. Use the CONVERT function to run this query Can someone tell me why?
First:
exec pu #a=null, #b=null, #c=null, #d=null, #e=null, #f=null, #g='2013-Jun-12 22:10:00.670', #h=100, #i=2, #j=null, #k=null, #l=null, #m=null, #n=0, #o='P', #p=null, #q=null, #r=null, #s=null, #t='junit', #u=null, #v=null, #w=null
Second:
exec pu ( null, null, null, null, null, null, '2013-Jun-12 22:10:00.187', 100, 2, null, null, null, null, 0, 'P', null, null, null, null, 'junit', null, null, null )
What could also be happening is that the parameters are not defined in the same as order as you are expecting them.
In scenario 1, you won't see a problem since parameters are referenced by name.
In scenario 2 however you are using positional reference which could be exposing this issue.
Please check the proc definition and make sure parameters are declared in same order as expected.
Related
I am trying to a build an SQLite database from an existing CSV file following the steps from this answer. However I already get an error in the second step where the database should be created from the defined table with
sqlite3 worldcities.db < worldcities.sql
The error message reads
Error: near line 1: near ")": syntax error
My worldcities.sql file looks like this:
CREATE TABLE worldcities(
city TEXT NOT NULL,
city_ascii TEXT NOT NULL,
lat REAL NOT NULL,
lng REAL NOT NULL,
country TEXT NOT NULL,
iso2 TEXT NOT NULL,
iso3 TEXT NOT NULL,
admin_name TEXT NOT NULL,
capital TEXT NOT NULL,
population INT NOT NULL,
id INT NOT NULL,
);
What did I do wrong here?
I suspect the orphaned , just before your )to cause your problem.
I tried here https://extendsclass.com/sqlite-browser.html
this
CREATE TABLE newtoy2 (MID INT, BID INT);
without a problem.
But this, having the same problem I suspect in your code
CREATE TABLE newtoy1 (MID INT, BID INT,);
gets the same error you quote: near ")": syntax error
Which confirms my suspicion.
There was an extra comma ',' before end of block.
Commas are used after all column description but not after the last column description.
Try and Run this below code.
create table worldcities(
city TEXT NOT NULL,
city_ascii TEXT NOT NULL,
lat REAL NOT NULL,
lng REAL NOT NULL,
country TEXT NOT NULL,
iso2 TEXT NOT NULL,
iso3 TEXT NOT NULL,
admin_name TEXT NOT NULL,
capital TEXT NOT NULL,
population INT NOT NULL,
id INT NOT NULL);
I need to perform location based search based on latitude and longitude pairs, to find out the near by locations of stores within a radius/distance of given KMs.
I am to use (for certain) Oracle's SDO_GEOMETRY for searching the locations.
Also, the table structure are parent-child based such that store address (zip, lat/long) is in parent table but store details (name, contact, etc) are in the child table.
This is to make sure that we do not have redundant data (as multiple store can have same lat/long and by some dark magic same address)
I have the following scenario (tables provided):
Version - Oracle Database 12c Enterprise Edition Release 12.2.0.1.0
Table: STORE_LOCATION
CREATE TABLE STORE_LOCATE
(
ID NUMBER DEFAULT STORE_LOCATE.nextval,
POSTAL_CODE VARCHAR2(18) NOT NULL,
ADDRESS VARCHAR2(382) NOT NULL,
GEO_LOCATION SDO_GEOMETRY NOT NULL
);
Table: STORE_DETAIL
CREATE TABLE STORE_DETAIL
(
ID NUMBER DEFAULT STORE_DETAIL_SEQ.nextval,
STORE_CODE VARCHAR2(20) NOT NULL,
STORE_NAME VARCHAR2(150) NOT NULL,
IS_ACTIVE NUMBER(3) DEFAULT 0 NOT NULL,
fk_store_locate_id INT NOT NULL. -- FK to ID of parent
);
I have inserted data in parent as:
INSERT INTO STORE_LOCATE (ZIP, ADDRESS, GEO_LOCATION) VALUES
('567875', '84 Paddar Road',
SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE (80.34234431,26.12354422, NULL), NULL, NULL));
Likewise, child table has entries:
INSERT INTO STORE_DETAIL (STORE_CODE, STORE_NAME, FK_STORE_LOCATION_ID) VALUES
('ST01', 'STORE 1', 1);
So, now when a user shares his location to me (lat/long), I need to search all nearby locations of stores within a specified radius.
I tried the following query, but I am getting error with this:
SELECT
s.store_code,
s.store_name,
loc.zip,
loc.address,
loc.geo_location
FROM store_detail s,
store_locate loc
where MDSYS.SDO_WITHIN_DISTANCE(loc.geo_location,
(MDSYS.SDO_GEOMETRY(2001, 8307,
MDSYS.SDO_POINT_TYPE(80.21456732,26.23117864, NULL) ,NULL, NULL)),
'distance=1000 unit=KM') = 'TRUE';
Getting the below error:
ORA-29900: operator binding does not exist
ORA-06553: PLS-306: wrong number or types of arguments in call to 'SDO_WITHIN_DISTANCE'
29900. 00000 - "operator binding does not exist"
*Cause: There is no binding for the current usage of the operator.
*Action: Change the operator arguments to match any of the existing
bindings or add a new binding to the operator.
I am breaking my head around this for a while now but in vain.
Ref:
https://issues.redhat.com/browse/TEIID-751?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
https://docs.oracle.com/cd/E17781_01/appdev.112/e18750/xe_locator.htm#XELOC562
Q's:
Is this the correct way to perform location search on Oracle SQL?
Is there any other way if the above is incorrect?
There are a number of syntax errors in your code (POSTAL_CODE called ZIP, etc)
Here is the corrected example (I also removed the sequences for simplicity)
CREATE TABLE STORE_LOCATE (
ID NUMBER primary key,
POSTAL_CODE VARCHAR2(18) NOT NULL,
ADDRESS VARCHAR2(382) NOT NULL,
GEO_LOCATION SDO_GEOMETRY NOT NULL
);
CREATE TABLE STORE_DETAIL (
ID NUMBER primary key,
STORE_CODE VARCHAR2(20) NOT NULL,
STORE_NAME VARCHAR2(150) NOT NULL,
IS_ACTIVE NUMBER(3) DEFAULT 0 NOT NULL,
fk_store_locate_id INT NOT NULL references STORE_LOCATE
);
INSERT INTO STORE_LOCATE (ID, POSTAL_CODE, ADDRESS, GEO_LOCATION) VALUES (1, '567875', '84 Paddar Road', SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE (80.34234431,26.12354422, NULL), NULL, NULL));
INSERT INTO STORE_DETAIL (ID, STORE_CODE, STORE_NAME, FK_STORE_LOCATE_ID) VALUES (1001,'ST01', 'STORE 1', 1);
commit;
Here is running your query:
SELECT
s.store_code,
s.store_name,
loc.postal_code,
loc.address,
loc.geo_location
FROM store_detail s, store_locate loc
where SDO_WITHIN_DISTANCE(
loc.geo_location,
SDO_GEOMETRY(2001, 8307,
SDO_POINT_TYPE(80.21456732,26.23117864, NULL),NULL, NULL
),
'distance=1000 unit=KM'
) = 'TRUE';
STORE_ STORE_NAME POSTAL ADDRESS GEO_LOCATION(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES
------ ---------- ------ -------------------- ----------------------------------------------------------------------------------
ST01 STORE 1 567875 84 Paddar Road SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(80.3423443, 26.1235442, NULL), NULL, NULL)
1 row selected.
The error you get probably means Oracle Spatial is not or incorrectly installed in your database. What exact database version do you use ?
IMPORTANT NOTE:
Those queries really need a spatial index on the GEO_LOCATION column. Without one, the query is rejected in versions up to 12.1. From 12.2 and later, the query will run, but will be very slow as soon as the number of locations goes above a few 100s. Once you go into the 100000 or more, it will be very slow.
See https://docs.oracle.com/en/database/oracle/oracle-database/19/spatl/indexing-querying-spatial-data.html#GUID-07129836-0DAE-4BCC-B290-942C456AE2EA for details
I am trying to create array in groovy where multiple dates can be stored.
e.g : I am checking availability in various dates and if found available, I want to add it to my array.
So basically I have while loop with a variable which decides how many times the loop iterate. Array length should be equal to the number of time loop iterate.
The expected result should look like :
"2019/12/02","2019/12/03","2019/12/04"
My Code :
def SeriesDaysNumber = context.expand('${#Project#SeriesDaysNumber}')
def dates = new String[SeriesDaysNumber]
while(isAvailable == false)
{
log.info "Inside While loop"
for (i = 0; i < SeriesDaysNumber.toInteger(); i++)
{
// some DB query to check availability
if(res[0].toString() == '0')
{
isAvailable = true
seriesEndDate2 = "${SeriesEndDate1.format(outputDateFormatSeries)}"
context.testCase.testSuite.project.setPropertyValue('SeriesEndDate', seriesEndDate2)
// this date is available so add it to array, here i use zero index but i want it dynamically.
dates[i] = seriesEndDate2.toString()
log.info "dates : " + dates
use(TimeCategory)
{
// here i am incrementing the date
}
}
}
}
Actual Result
Mon Dec 02 15:24:56 IST 2019:INFO:dates : [2019/12/02, 2019/12/05, 2019/12/08, 2019/12/11, 2019/12/14, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
There are 4 things I need to do to achieve the expected result :
dates[i] instead of dates[0]
To store all dates in an array.
def dates = new String[SeriesDaysNumber.toInteger()]
To resolve the null issue.
dates[i] = "\""+seriesEndDate2.toString()+"\""
To put dates into double quotes.
log.info "dates : " + dates.join(", ") To remove square brackets from array.
I am making an Electron application, which uses an SQLite Database. Inside of the app's directory, I have a folder named db and as a child, another one - seeder. In that seeder directory there are a bunch of .sql files, needed for creating the db architecture and seeding the database with information needed:
Electron App/
|---main.js
|---index.html
|---node_modules
|---package.json
|---db/
|---seed.js
|---seeder/
|---bunch of .sql files
When I run seed.js it is supposed to get all filenames inside of seeder/ and run every single one successively. The files are named as follows:
01.tables.sql
02.countries.sql
03.ekatte.sql - (this one contains all the villages and cities in Bulgaria)
04.programmes.sql
05.schedules.sql
06.subjects.sql
Everything works as expected, except one thing: 01.tables.sql is supposed to create all the tables, and all other files contain INSERT INTO statements. Some of the tables are not created and when the Electron app tries to INSERT INTO them - sqlite returns an error: no such table (but only for oblasti, programmes, schedules and subjects).
Here are the contents of 01.table.sql:
CREATE TABLE countries (
countryID integer NOT NULL CONSTRAINT countries_pk PRIMARY KEY,
countryName text NOT NULL,
countryISO text NOT NULL
);
CREATE TABLE grades (
gradeID integer NOT NULL CONSTRAINT grades_pk PRIMARY KEY,
gradeValue integer NOT NULL,
gradeStudent integer NOT NULL,
gradeSchedule integer NOT NULL
);
CREATE TABLE oblasti (
oblastID integer NOT NULL CONSTRAINT oblasti_pk PRIMARY KEY,
oblastName text NOT NULL,
oblastCode text NOT NULL
);
CREATE TABLE obshtini (
obshtinaID integer NOT NULL CONSTRAINT obshtini_pk PRIMARY KEY,
obshtinaName text NOT NULL,
obshtinaOblast integer NOT NULL
);
CREATE TABLE programmes (
programmeID integer NOT NULL CONSTRAINT programmes_pk PRIMARY KEY,
programmeName text NOT NULL
);
CREATE TABLE schedules (
scheduleID integer NOT NULL CONSTRAINT schedules_pk PRIMARY KEY,
scheduleProgramme integer NOT NULL,
scheduleSemester integer NOT NULL,
scheduleSubject integer NOT NULL
);
CREATE TABLE selishta (
selishteID integer NOT NULL CONSTRAINT selishta_pk PRIMARY KEY,
selishteName text NOT NULL,
selishteObshtina integer NOT NULL,
selishteOblast integer NOT NULL
);
CREATE TABLE students (
studentID integer NOT NULL CONSTRAINT students_pk PRIMARY KEY,
studentName text NOT NULL,
studentFamily text NOT NULL,
studentPicture blob NOT NULL,
studentBirthplace integer,
studentForeignCountry integer,
studentForeignOblast text,
studentForeignObshtina text,
studentForeignSelishte text,
studentEGN integer NOT NULL,
studentAddress text NOT NULL,
studentPhone text NOT NULL,
studentNationality integer NOT NULL,
studentEduForm integer NOT NULL,
studentOKS integer NOT NULL,
studentSemester integer NOT NULL,
studentClass integer NOT NULL,
studentFakNomer integer NOT NULL,
studentStatus integer NOT NULL,
studentValid integer NOT NULL
);
CREATE TABLE subjects (
subjectID integer NOT NULL CONSTRAINT subjects_pk PRIMARY KEY,
subjectName text NOT NULL
);
and this is the part of seed.js, responsible for the actual seeding:
const db = new sqlite3.Database('db/database.db');
fs.readdir('db/seeder/', function(err, dir) {
let fileList = new Array();
$.each(dir, function(index, fileName){
fileList.push(fileName);
});
fileList.sort();
seedDB(fileList);
});
function seedDB(files){
if(files.length > 0){
let fileName = files.shift();
fs.readFile('db/seeder/'+fileName, 'utf-8', function(err, data){
db.serialize(function() {
db.run(data);
});
seedDB(files);
});
}
}
In TSQL, I need to do a cross-reference from our value for a given field, to the specified client's value. We have many clients and each client's encoding of values is different. The db is a CRM Dynamics 2011 db.
I set up a scalar-valued function like this:
[dbo].[fn_GetXRef]
(#Guid uniqueidentifier, #LookupType nvarchar(20),
#OurValue nvarchar(20), #Parm4 nvarchar(20) = null,
#Parm5 uniqueidentifier = null, #Parm6 nvarchar(1) = null,
#Parm7 nvarchar(1) = null)
Parms 4, 5, 6 and 7 may be null; they are used for some cross-references but not others.
If I run execute the logic outside the function, it works. When I execute the function it returns NULL.
For example:
Select dbo.fn_getXRef('22BF20B1-55F1-E211-BF73-00155D062F00',
'Lookup Type 1', 'Our value', null, null, null, '3')
It returns null but pulling the logic out of the function and running it as a separate query, and using the same input parameter values, returns the correct client-value.
What am I not seeing?
update: 12/11/13
Thanks all for trying to help. While researching I found some nifty code that looked more efficient than my own so I re-wrote the function using that technique and now it works. It uses OPTION (RECOMPILE):
SELECT #TheirValue = X.carriervalue
FROM dbo.Filteredcrossreference X
WHERE
X.carrier = #CarrierId
and X.lookuptype = #LookupType
and X.ourvalue = #OurValue
and (#Parm4 IS NULL OR (X.parm4 = #Parm4))
and (#Parm5 IS NULL OR (X.parm5 = #Parm5))
and (#Parm6 IS NULL OR (X.parm6 = #Parm6))
OPTION (RECOMPILE)
Hard to tell, without seeing the body of your function. But a common place to look will be at what parms are actually passed. Chances are, you may think you're passing null, when actually you're passing an empty string, or a default value, or something along those lines.