SDO_UTIL.TO_WKTGEOMETRY(GEOMETRY) Value Not Allowed Error - oracle-spatial

i have an object table and SRID 2000273
TableGeometryImg
i execute the following query to get the wkt string of the geometry in the table
SELECT SDO_UTIL.TO_WKTGEOMETRY(GEOMETRY) FROM myTABLE
i get following errors;
ORA-24323: value not allowed
ORA-06512: location "MDSYS.MDPRVT_SRID",line 143
ORA-06512: location "MDSYS.SDO_UTIL", line 320
i insert mdsys.cs_srs table about my table's srid record
insert into MDSYS.cs_srs values ('TM 27 3 DERECE',2000273,2000273,'Oracle','PROJCS["TM 27 3 DERECE",GEOGCS["OpenGIS.European_Datum_1950",DATUM["OpenGIS.European_Datum_1950",SPHEROID["International 1924",6378388.000000,297.000000]],PRIMEM["Greenwich",0.000000],UNIT["Decimal Degree",0.01745329251994330]],PROJECTION["Transverse Mercator"],PARAMETER["Scale_Factor",1.000000],PARAMETER["Central_Meridian",27.000000],PARAMETER["False_Easting",500000.000000],PARAMETER["False_Northing",0],PARAMETER["Latitude_of_Origin",0],UNIT["Meter",1.000000000000]]',NULL);
What is the reason for this error? Where else should I check?

Your insert actually fails. The CS_SRS table (it is actually a view) has more columns than the ones you provide, and therefore, your insert fails as written:
SQL> insert into MDSYS.cs_srs values ('TM 27 3 DERECE',2000273,2000273,'Oracle','PROJCS["TM 27 3 DERECE",GEOGCS["OpenGIS.European_Datum_1950",DATUM["OpenGIS.European_Datum_1950",SPHEROID["International 1924",6378388.000000,297.000000]],PRIMEM["Greenwich",0.000000],UNIT["Decimal Degree",0.01745329251994330]],PROJECTION["Transverse Mercator"],PARAMETER["Scale_Factor",1.000000],PARAMETER["Central_Meridian",27.000000],PARAMETER["False_Easting",500000.000000],PARAMETER["False_Northing",0],PARAMETER["Latitude_of_Origin",0],UNIT["Meter",1.000000000000]]',NULL);
insert into MDSYS.cs_srs values ('TM 27 3 DERECE',2000273,2000273,'Oracle','PROJCS["TM 27 3 DERECE",GEOGCS["OpenGIS.European_Datum_1950",DATUM["OpenGIS.European_Datum_1950",SPHEROID["International 1924",6378388.000000,297.000000]],PRIMEM["Greenwich",0.000000],UNIT["Decimal Degree",0.01745329251994330]],PROJECTION["Transverse Mercator"],PARAMETER["Scale_Factor",1.000000],PARAMETER["Central_Meridian",27.000000],PARAMETER["False_Easting",500000.000000],PARAMETER["False_Northing",0],PARAMETER["Latitude_of_Origin",0],UNIT["Meter",1.000000000000]]',NULL)
*
ERROR at line 1:
ORA-00947: not enough values
Let's correct this by using an explicit column list. This is always safer, because the actual ordering of the columns is actually uncertain ...
Notice this insert is only possible when connected as a privileged user. So, let's connect as SYSTEM and do the update:
SQL> connect system/******#localdb
Connected.
SQL> insert into cs_srs (cs_name,srid,auth_srid,auth_name,wktext)
2 values (
3 'TM 27 3 DERECE',
4 2000273,
5 2000273,
6 'Oracle',
'PROJCS["TM 27 3 DERECE",GEOGCS["OpenGIS.European_Datum_1950",DATUM["OpenGIS.European_Datum_1950",SPHEROID["International 1924",6378388.000000,297.000000]],PRIMEM["Greenwich",0.000000],UNIT["Decimal Degree",0.01745329251994330]],PROJECTION["Transverse Mercator"],PARAMETER["Scale_Factor",1.000000],PARAMETER["Central_Meridian",27.000000],PARAMETER["False_Easting",500000.000000],PARAMETER["False_Northing",0],PARAMETER["Latitude_of_Origin",0],UNIT["Meter",1.000000000000]]'
8 );
1 row created.
SQL> commit;
Commit complete.
Now the conversion to WKT will work:
SQL> select SDO_UTIL.TO_WKTGEOMETRY(sdo_geometry(2001,2000273,sdo_point_type(449319,4445908,null),null,null)) from dual;
SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOMETRY(2001,2000273,SDO_POINT_TYPE(449319,4445908
-------------------------------------------------------------------------------
POINT (449319.0 4445908.0)
1 row selected.

Related

How to add decimal places to numbers without them and add decimals to those with only one decimal column

So i have a column that is number by type, there are values in there with numbers like 8, 15.0, 89.1 or null. I need to add a decimal spot to them so they would look like 8.00, 15.00, 89.10 and the nulls replaced with 0.00.( there are hundreds of number values not just the 4 examples) I figured I needed to do an update with a case, the null part is simple enough
update table
set cost = case
when null then 0.00
not sure how to tackle the other three situations, any help is much appreciated !!
So i have a column that is number by type
To me, it looks like a presentation issue, not storage. Justin tried to convince you that you don't have to do anything about it, I suggest you re-read what he said.
Table looks like this:
SQL> create table test (col) as
2 select 8 from dual union all
3 select 15.0 from dual union all
4 select 89.1 from dual union all
5 select null from dual; --> only NULL should be replaced by 0
Table created.
SQL> update test set col = 0 where col is null;
1 row updated.
SQL>
If you don't do anything, this is the result:
SQL> select * from test;
COL
----------
8
15
89,1
0
SQL>
As of presentation: it depends on a tool you use. For example: if it were SQL*Plus, you could format the column as
SQL> column col format 90D00
SQL> select * from test;
COL
------
8,00
15,00
89,10
0,00
SQL>
Comma is a decimal character in my database; change it to a dot:
SQL> alter session set nls_numeric_characters = '.,';
Session altered.
SQL> select * from test;
COL
------
8.00
15.00
89.10
0.00
SQL>
Or, in any tool, use the TO_CHAR function with appropriate format mask:
SQL> select col, to_char(col, '90D00', 'nls_numeric_characters = ''.,''') result from test;
COL RESULT
---------- ------
8 8.00
15 15.00
89,1 89.10
0 0.00
SQL>
Or, if it is some GUI tool (be it Oracle Forms, Reports, Apex, ...), it contains the Format mask property you should use for the same purpose - presentation - and put 90D00 into it to format value displayed to end users.
Therefore, once again: there's nothing wrong with values stored in that column; it is just about the way users will see them.

SQL Server : trying to make a check statement, but having a problem when I try in practise

I have created a function that checks how many items are in storage:
alter function dbo.preveriZalogo(#St int,#ID int)
returns int
as
begin
declare #Kol int;
select #Kol=sum(Kolicina) from Stanje
where IzdelekID=#ID
return (#Kol+#St);
end;
GO
It checks in view:
CREATE VIEW Stanje
AS
select
Skladisce.Naziv as Skladisce,
UvozIzvoz.IzdelekID,
Izdelek.Naziv as Pijaca,
sum(UvozIzvoz.Kolicina) as Kolicina
from UvozIzvoz
inner join SkladisceDelavec
on SkladisceDelavec.ID = UvozIzvoz.SkladisceDelavecID
inner join Skladisce
on Skladisce.ID = SkladisceDelavec.SkladisceID
inner join Izdelek
on Izdelek.ID = UvozIzvoz.IzdelekID
group by
Skladisce.Naziv,
IzdelekID,
Izdelek.Naziv;
Then I created a CHECK constraint:
alter table UvozIzvoz
add constraint PreveriAliJeNaZalogi
check (dbo.preveriZalogo(Kolicina,IzdelekID)>=0);
When I ran:
select * from Stanje;
I get the following result:
Skladisce
IzdelekID
Izdelek
kolicina
Skladišče 1
1
Coca Cola 1.5L
12
Skladišče 1
2
Coca Cola 0.33L
24
Skladišče 1
3
Ledeni čaj breskev Sola 0.33L
24
Skladišče 1
4
Red bull 0.25L
24
Skladišče 1
6
Vino Sauvignonasse Gor.Brda 20L
3
Skladišče 1
7
Jagermeister 1L
2
Skladišče 1
8
Whisky Jack Daniels old No.7 1L
4
Skladišče 1
10
Pivo Laško Zlatorog Svetlo 0.5
16
Skladišče 1
11
Pivo Union 6*0.5
4
and if try to run a insert statement that will deduct 12 from Coca Cola 1,5L supply, the check statement interferes.
The error:
"The INSERT statement conflicted with the CHECK constraint "PreveriAliJeNaZalogi". The conflict occurred in database "SkladisceTD", table "dbo.UvozIzvoz"."
the select statement:
insert into UvozIzvoz(Kolicina,IzdelekID,SkladisceDelavecID)
values(-12,1,1);
I find the problem. I didn't know that when you make a insert with a check statement, that it will first insert into the table and then check if that is correct.

SQL Inserting in loop using value (sysguid) multiple times

I currently have the following script for inserting some dummy data into one of my tables for testing purposes.
I can call it and pass the number of entries I would like to have. That's working well.
Now the problem is that some of the data is not working.
The CRecordID should have in all three lines (12, 17, 19) the same value.
Is there a way to archive this?
WHENEVER SQLERROR EXIT
PROMPT inserting
INSERT INTO MySchema.MyTable (MYRECORD, TMSTAMP, SHORTRECORD, CRecordID) (
SELECT
'<MYRECORD>
<TimeStamp>'||TO_CHAR(SYSDATE,'DD.MM.YY')||' '||to_char(to_date('2000-01-01', 'yyyy-mm-dd')+dbms_random.value(1,1000), 'HH24:MI:SS')||'</TimeStamp>
<User>Test_User_1</User>
<Application>Application1</Application>
<Action>Dummy action text</Action>
<INFO>dummy info text</INFO>
<CRecordID>'||'CID_'||sys_guid()||'</CRecordID> -- line 12
</MYRECORD>',
to_date(SYSDATE,'DD.MM.YY'),
'<SHORTRECORD>
<User>Test_User_1</User>
<CRecordID>'||'CID_'||sys_guid()||'</CRecordID> -- line 17
</SHORTRECORD>',
'CID_'||sys_guid() -- line 19
FROM DUAL connect by level <= &1
);
COMMIT;
PROMPT inserting done
Note: The Database is an Oracle DB.
Select SYS_GUID() separately (using a CTE, for example, as in my example) and concatenate its value with your columns (I used L12 and L17 to indicate lines 12 and 17 you mentioned).
SQL> with gujda as
2 (select sys_guid() guj
3 from dual
4 connect by level <= 4
5 )
6 select 'L12_' || g.guj l12,
7 'L17_' || g.guj l17
8 from gujda g;
L12 L17
------------------------------------ ------------------------------------
L12_EFB5A4947D2E4B7BBE6017E57C673ABF L17_EFB5A4947D2E4B7BBE6017E57C673ABF
L12_3E2D5B50D7C44C7FA6073A9F739687CF L17_3E2D5B50D7C44C7FA6073A9F739687CF
L12_724C21F7914B423B8CBDDC6A44AD2016 L17_724C21F7914B423B8CBDDC6A44AD2016
L12_F15D6C9865424E5C8FFFEA9C09DD6D37 L17_F15D6C9865424E5C8FFFEA9C09DD6D37
SQL>

How to modify multiple rows of a single column in postgresql?

I have following columns and data set to my table. I need to fill the multi column as id*number (i.e. the first value in multi column would be 1*1025=1025, second value would be 2*2587=5174 and so on. I need a postgresql query for this. Do I need a for loop or can be done by some other trick (but I don't want to do it one by one column instead of doing altogether)?
id multi number
1 1025
2 2587
3 1475
4 5698
5 254
6 912
7 442
8 8756
9 1123
Then I have got the following query is the simplest way
SELECT
id,
number,
(id * number) as multi
FROM
tableName
This SELECT is working but INSERT or UPDATE is not working with this.
UPDATE tableName
SET multi = id * number;
Or am I missing something?

Create table on the fly with Insert Into

Is this possible? I got a big .sql file full of Insert Into statements without the database schema. Can I just create table on the fly?
Here is an example:
INSERT INTO [g_fuel_site] ([SiteID], ... ,[EMVEnabled])
VALUES('Sep 23 2011 3:05:51:000PM', ... ,0)
EDIT: There is no tables! The script assumed I do!
Aaron beat me by 20 seconds.
For an example change the first insert from:
INSERT INTO [g_fuel_site] ([SiteID],[CurrentOperatingLevelID],[CurrentPriceBookID], [NumberFuelSaleBuffers],[LinearUnitOfMeasure],[VolumeUnitOfMeasure],[PreAuthAllowed],[StackedSalesAllowed],[MaxLiveDispensers],[AllowedZeroPPUs],[MaxPPU],[MinPPU],[InitialConfigDone],[DispenserOptionModeID],[GenAuthEnabled],[PendingPriceBookID],[AllowPresetWithHandleUp],[UseFixedGradeName],[UseFixedServiceLevelName],[UseFixedGradeProductCodes],[TokenAttendantRcptCtl],[TokenAttendantNtwrkRcptCtl],[TokenAttendantPrpayRcptCtl],[RunAttendantInBufferedMode],[AllowAttendantBalanceQuery],[TokenOrStandardOperation],[TokenPrefix],[EnablePostPayLimit],[PostPayLimit],[EMVEnabled])VALUES('Sep 23 2011 3:05:51:000PM',1,1,2,'CM','L',1,1,12,0,9.9990,0.7500,1,1,1,2,1,0,0,0,0,0,0,0,0,0,'',0,100.0000,0)
to be:
SELECT
'Sep 23 2011 3:05:51:000PM' [SiteID],
1 [CurrentOperatingLevelID],
1 [CurrentPriceBookID],
2 [NumberFuelSaleBuffers],
'CM' [LinearUnitOfMeasure],
'L' [VolumeUnitOfMeasure],
1 [PreAuthAllowed],
1 [StackedSalesAllowed],
12 [MaxLiveDispensers],
0 [AllowedZeroPPUs],
9.9990 [MaxPPU],
0.7500 [MinPPU],
1 [InitialConfigDone],
1 [DispenserOptionModeID],
1 [GenAuthEnabled],
2 [PendingPriceBookID],
1 [AllowPresetWithHandleUp],
0 [UseFixedGradeName],
0 [UseFixedServiceLevelName],
0 [UseFixedGradeProductCodes],
0 [TokenAttendantRcptCtl],
0 [TokenAttendantNtwrkRcptCtl],
0 [TokenAttendantPrpayRcptCtl],
0 [RunAttendantInBufferedMode],
0 [AllowAttendantBalanceQuery],
0 [TokenOrStandardOperation],
'' [TokenPrefix],
0 [EnablePostPayLimit],
100.0000 [PostPayLimit],
0 [EMVEnabled]
INTO g_fuel_site
After this the table will exist. It just infers column types, and will only work if the first select into contains all the columns that later inserts expect.
If you change the first one (and only the first one) to SELECT INTO, yes. Assuming the first INSERT has correctly deducible data types. Note that it won't magically create keys, indexes, constraints, computed columns, etc. for you.
However your example also includes a leading DELETE, which leads me to believe the table already exists. DELETE deletes all of the rows from the table, it doesn't drop the table. If the table doesn't exist, then your script should (a) check if it exists before running a delete and (b) run the first command a SELECT INTO so that it creates it. However you will probably want to define data types (I also find it hard to believe that SiteID is a DATETIME).
IF OBJECT_ID('dbo.g_fuel_site') IS NOT NULL
BEGIN
DELETE g_fuel_site;
END
ELSE
BEGIN
SELECT SiteID = CONVERT(INT, 1), ...
INTO dbo.g_fuel_site
WHERE 1 = 0; -- creates table but with 0 rows
END
INSERT dbo.g_fuel_site(SiteID, ...) VALUES(...); -- first row
INSERT ...
INSERT ...