Sql to convert mdsys.geometry to wkt or wkb
I've been looking through the sdoapi for 10g (the only available now) for a way to convert a geometry column to wkt or wkb. There was a method with the old version (get_wkt and get_wkb). Does anyone know how to do it with the 10g sdoapi
Mike Smith
Our Java code actually does have a (protected) member variable or switch, representing whether the output by default should be big-endian or little-endian.
However, the SQL/mm standard does not define any parameter to determine the output encoding. Neither have we added any proprietary signature to that effect. Thus, the Java constructor sets the switch to "big-endian".
On the other hand, when the Java code reads WKB, the WKB specifies whether it is encoded in little-endian or in big-endian. This is why we can read both encodings.
If there is a requirement to also write both encodings, we could add a function specifying the output encoding.
Mike
Similar Messages
-
Export Geometry to WKT or WKB but include ARCs too - Do not densify
Dear all,
I have been having some issues when exporting the spatial data to WKT or WKB. I can get the WKT without any problems but the issue is that all ARCs are not exported as ARCs but rather as line segments. Looks like during the export process there is some Densify process that gets run.
Can someone please help me if there is a way to export the ARCs as ARCs and do not densify.
WKT has support for Circular Arcs so there should be no problems.
And the second problem was that when i export to WKB this data can not be read by SQL Server or any other tool.
Any advice much apprciated.
DanDan,
Without actual examples we cannot help you solve you problem.
Here are some tests I ran in Oracle and SQL Server.
Oracle Export
select a.name, a.geom.get_wkt() as text
from (select 'Line segment' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,2,1), sdo_ordinate_array (10,10, 20,10)) as geom from dual union all
select 'Line string' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,2,1), sdo_ordinate_array (10,25, 20,30, 25,25, 30,30)) as geom from dual union all
select 'Arc segment' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,2,2), sdo_ordinate_array (10,15, 15,20, 20,15)) as geom from dual union all
select 'Arc string' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,2,2), sdo_ordinate_array (10,35, 15,40, 20,35, 25,30, 30,35)) as geom from dual union all
select 'Closed arc string' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,2,2), sdo_ordinate_array (15,65, 10,68, 15,70, 20,68, 15,65)) as geom from dual union all
select 'Compound line string' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,4,3, 1,2,1, 3,2,2, 7,2,1), sdo_ordinate_array (10,45, 20,45, 23,48, 20,51, 10,51)) as geom from dual union all
select 'Closed mixed line' as name,sdo_geometry (2002, null, null, sdo_elem_info_array (1,4,2, 1,2,1, 7,2,2), sdo_ordinate_array (10,78, 10,75, 20,75, 20,78, 15,80, 10,78)) as geom from dual
) a;
-- results
NAME TEXT
Line segment LINESTRING (10.0 10.0, 20.0 10.0)
Line string LINESTRING (10.0 25.0, 20.0 30.0, 25.0 25.0, 30.0 30.0)
Arc segment CIRCULARSTRING (10.0 15.0, 15.0 20.0, 20.0 15.0)
Arc string CIRCULARSTRING (10.0 35.0, 15.0 40.0, 20.0 35.0, 25.0 30.0, 30.0 35.0)
Closed arc string CIRCULARSTRING (15.0 65.0, 10.0 68.0, 15.0 70.0, 20.0 68.0, 15.0 65.0)
Compound line string COMPOUNDCURVE ((10.0 45.0, 20.0 45.0), CIRCULARSTRING (20.0 45.0, 23.0 48.0, 20.0 51.0), (20.0 51.0, 10.0 51.0))
Closed mixed line COMPOUNDCURVE ((10.0 78.0, 10.0 75.0, 20.0 75.0, 20.0 78.0), CIRCULARSTRING (20.0 78.0, 15.0 80.0, 10.0 78.0))
7 rows selectedNo densification there.
SQL Server Denali Import
Now, take the above WKT and import into SQL Server.
select geometry::STGeomFromText('LINESTRING (10.0 10.0, 20.0 10.0)',0).STAsText() as text union all
select geometry::STGeomFromText('LINESTRING (10.0 25.0, 20.0 30.0, 25.0 25.0, 30.0 30.0)',0).STAsText() as text union all
select geometry::STGeomFromText('CIRCULARSTRING (10.0 15.0, 15.0 20.0, 20.0 15.0)',0).STAsText() as text union all
select geometry::STGeomFromText('CIRCULARSTRING (10.0 35.0, 15.0 40.0, 20.0 35.0, 25.0 30.0, 30.0 35.0)',0).STAsText() as text union all
select geometry::STGeomFromText('CIRCULARSTRING (15.0 65.0, 10.0 68.0, 15.0 70.0, 20.0 68.0, 15.0 65.0)',0).STAsText() as text union all
select geometry::STGeomFromText('COMPOUNDCURVE ((10.0 45.0, 20.0 45.0), CIRCULARSTRING (20.0 45.0, 23.0 48.0, 20.0 51.0), (20.0 51.0, 10.0 51.0))',0).STAsText() as text union all
select geometry::STGeomFromText('COMPOUNDCURVE ((10.0 78.0, 10.0 75.0, 20.0 75.0, 20.0 78.0), CIRCULARSTRING (20.0 78.0, 15.0 80.0, 10.0 78.0))',0).STAsText() as text ;
-- results
LINESTRING (10 10, 20 10)
LINESTRING (10 25, 20 30, 25 25, 30 30)
CIRCULARSTRING (10 15, 15 20, 20 15)
CIRCULARSTRING (10 35, 15 40, 20 35, 25 30, 30 35)
CIRCULARSTRING (15 65, 10 68, 15 70, 20 68, 15 65)
COMPOUNDCURVE ((10 45, 20 45), CIRCULARSTRING (20 45, 23 48, 20 51), (20 51, 10 51))
COMPOUNDCURVE ((10 78, 10 75, 20 75, 20 78), CIRCULARSTRING (20 78, 15 80, 10 78))Can you provide us with similar examples where the process fails?
And the second problem was that when i export to WKB this data can not be read by SQL Server or any other tool.Let's try and solve the first problem before the second. Are Oracle and SQL Server both on the same hardware?
regards
Simon -
PL/SQL package converted to java
Hi everyone!
I have a question. Has anyone use this function of jdeveloper?
I mean the option of take a PL/SQL and convert it to .java with jDeveloper 11gTP4.
I´m prooving it, and I´m having some problems with the code that jdeveloper insert.
sqlj.runtime.ref.DefaultContext __sJT_cc = getConnectionContext();
if (__sJT_cc==null)
sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
If someone have experience with this? ....
Thanks,
RowanSorry for not explaining well
After this code:
sqlj.runtime.ref.DefaultContext __sJT_cc = getConnectionContext();
if (__sJT_cc==null)
sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
I´ve got the next error:
ADVERTENCIA: java.lang.NullPointerException
javax.faces.el.EvaluationException: java.lang.NullPointerException
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
My app, is a table and a button to modify a Row.
Rowan -
Sql Timestamp converter problem in Tomcat
Hi all,
I have a table that one of the columns is an Oracle date type. So, I use SQL Timestamp converter in static text that is bound to the column. Here I want to display only the time part of the field, so in the converter properties I changed the pattern to HH:mm (for 24 hours format), and the type property I changed to time only.
Everything is perfect in development using sun app server. Problem is when I deploy that to Tomcat, the column displays 00:00 regardless of the real value. Tried to change the property of the converter, but has no effect.
The differences between sun app and tomcat besides the application server is the jdbc driver. The Tomcat uses Oracle JDBC driver.
Could someone give me some solution about that?
Thanks in advance.You should try changing java.sql.Timestamp to java.util.Calendar.
java.util.Calendar maps to the dateTime type in XML Schema, and TIMESTAMP as a JDBC type.
Regards,
Mike Wooten -
hii. i try to run these codes but i got an error shown below. i use oracle 10g.R2
why do i get this error.
select m.geometry.get_wkt() from mahal m
ORA-13199: ENGINEERING is not supported by geometry WKB/WKT generation.
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 17
ORA-06512: at "MDSYS.SDO_UTIL", line 2439
ORA-06512: at "MDSYS.SDO_GEOMETRY", line 36
thanksi run this code
SELECT c.ID, SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(c.geometry, 0.005)
FROM mahal c
and get this.
ID,SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(C.GEOMETRY,0.005)
380,13367 [Element <1>] [Ring <1>]
381,13367 [Element <1>] [Ring <1>]
382,13367 [Element <1>] [Ring <1>]
383,13349 [Element <1>] [Ring <1>][Edge <7>][Edge <8>]
384,TRUE
385,13367 [Element <1>] [Ring <1>]
386,13349 [Element <1>] [Ring <1>][Edge <1>][Edge <30>]
387,13349 [Element <1>] [Ring <1>][Edge <1>][Edge <4>]
388,13367 [Element <1>] [Ring <1>]
389,13367 [Element <1>] [Ring <1>]
390,13367 [Element <1>] [Ring <1>]
379,13367 [Element <1>] [Ring <1>]
378,13356 [Element <1>] [Coordinate <8>][Ring <1>]
852,13367 [Element <1>] [Ring <1>]
853,TRUE
854,13367 [Element <1>] [Ring <1>]
855,TRUE
856,13367 [Element <1>] [Ring <1>]
857,TRUE
858,13367 [Element <1>] [Ring <1>]
859,13367 [Element <1>] [Ring <1>]
860,13367 [Element <1>] [Ring <1>]
861,13356 [Element <1>] [Coordinate <5>][Ring <1>]
862,13367 [Element <1>] [Ring <1>]
863,13367 [Element <1>] [Ring <1>]
864,13367 [Element <1>] [Ring <1>]
865,TRUE
825,13367 [Element <1>] [Ring <1>]
823,13367 [Element <1>] [Ring <1>]
824,13349 [Element <1>] [Ring <1>][Edge <1>][Edge <20>]
826,13367 [Element <1>] [Ring <1>]
827,13356 [Element <1>] [Coordinate <4>][Ring <1>]
828,13367 [Element <1>] [Ring <1>]
829,13367 [Element <1>] [Ring <1>]
830,13367 [Element <1>] [Ring <1>]
831,13367 [Element <1>] [Ring <1>]
832,13367 [Element <1>] [Ring <1>]
833,13367 [Element <1>] [Ring <1>]
834,13367 [Element <1>] [Ring <1>]
835,13367 [Element <1>] [Ring <1>]
836,TRUE
837,13367 [Element <1>] [Ring <1>]
838,13367 [Element <1>] [Ring <1>]
839,13367 [Element <1>] [Ring <1>]
840,13367 [Element <1>] [Ring <1>]
841,13367 [Element <1>] [Ring <1>]
842,13367 [Element <1>] [Ring <1>]
843,13367 [Element <1>] [Ring <1>]
844,13367 [Element <1>] [Ring <1>]
845,TRUE
846,TRUE
847,13367 [Element <1>] [Ring <1>]
848,13367 [Element <1>] [Ring <1>]
849,13367 [Element <1>] [Ring <1>]
850,13367 [Element <1>] [Ring <1>]
851,13367 [Element <1>] [Ring <1>]
is there something wrong here? -
SQL Dev converts MS SQL to Oracle - issue with numeric prefix column name
Hi,
We're working on migrating MS SQL data into Oracle 10g. An issue we encountered is that some of MS SQL's tables have column names with numeric prefix like 1Q07, 2Q07, ..., 4Q08, and so on. The converted model as well as script can be created. But one thing I notice is that SQL Dev appends a prefix "A" for column names with numeric prefix. This makes sense because Oracle does not allow a column with number. But somehow this does not work with only 4Q
1Q04 => A1Q01
2Q07 => A2Q07
3Q08 => A3Q08
4Q08 => 4Q08 ???
Why? Any place in the tool where I can override this?
Obviously I can manually modify column name 4Q08 to A4Q08 in the script. But by doing this when moving data, it would fail because tool has no knowledge of updated column name.
Thanks in advance.Hi ittichai,
In <repository>.MIGRATION_TRANSFORMER body
FUNCTION first_char_check(p_work NVARCHAR2) RETURN NVARCHAR2
v_allowed := C_DISALLOWED_CHARS || '012356789_$';
should be
v_allowed := C_DISALLOWED_CHARS || '0123456789_$';
If you make this change and convert the 4Q08 will be
A4Q08 is expected, without any manual rename.
-Turloch
Message was edited by:
Turloch O'Tierney -
Report Builder SQL Queries - Convert CN to clear text
I am trying to customize a query in Report Builder to message values as they are delivered, and running into value expression errors.
My query returns data from the AD Computer Object "managedBy" field. The problem is that this field returns data in the format of:
CN=Security Group Name,OU=blah,OU=blah,DC=stuff,DC=com etc
I am trying to get it to return just the "Security Group" value which is much more useful. I found this great article which almost works for me: https://social.technet.microsoft.com/forums/systemcenter/en-US/6610d238-72f2-4e75-a0cc-e1383dd8e94b/ad-system-discovery-convert-cn-to-clear-text
However, once I try to save the report in Report Builder I get:
System.Web.Services.Protocols.SoapException: The Value expression for the text box ‘managedBy0’ refers to the field ‘managedBy0’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified
dataset scope. Letters in the names of fields must use the correct case.
This is the original SQL query:
select all SMS_R_System.Name0,SMS_R_System.managedBy0,SMS_R_System.description0,SMS_G_System_OPERATING_SYSTEM.Caption00,SMS_R_System.Resource_Domain_OR_Workgr0,SMS_R_System.whenCreated0,SMS_R_System.Last_Logon_Timestamp0 from vSMS_R_System AS SMS_R_System
INNER JOIN Operating_System_DATA AS SMS_G_System_OPERATING_SYSTEM ON SMS_G_System_OPERATING_SYSTEM.MachineID = SMS_R_System.ItemKey INNER JOIN _RES_COLL_CAS000A9 AS SMS_CM_RES_COLL_CAS000A9 ON SMS_CM_RES_COLL_CAS000A9.MachineID = SMS_R_System.ItemKey
My edited query:
select all SMS_R_System.Name0,REPLACE(SUBSTRING(SMS_R_System.managedBy0,4,CHARINDEX(',OU',SMS_R_System.managedBy0,3)-4),'\,',','),SMS_R_System.description0,SMS_G_System_OPERATING_SYSTEM.Caption00,SMS_R_System.Resource_Domain_OR_Workgr0,SMS_R_System.whenCreated0,SMS_R_System.Last_Logon_Timestamp0
from vSMS_R_System AS SMS_R_System INNER JOIN Operating_System_DATA AS SMS_G_System_OPERATING_SYSTEM ON SMS_G_System_OPERATING_SYSTEM.MachineID = SMS_R_System.ItemKey INNER JOIN _RES_COLL_CAS000A9 AS SMS_CM_RES_COLL_CAS000A9 ON SMS_CM_RES_COLL_CAS000A9.MachineID
= SMS_R_System.ItemKey
Thoughts?Hey,
Since you manipulate the original value of
ManagedBy0 in your SELECT, the column name will change to
(No column name). I did a test on my side and look what I get.
Error : "The Value expression for the text box ‘managedBy0’ refers to the field ‘managedBy0’."
He search for a variable
ManagedBy0 in your query but don't find any because there's no name assigned.
Try to run this query. Add
AS ManagedBy0 after your REPLACE.
select all
SMS_R_System.Name0,
REPLACE(SUBSTRING(SMS_R_System.managedBy0,4,CHARINDEX(',OU',SMS_R_System.managedBy0,3)-4),'\,',',') AS ManagedBy0,
SMS_R_System.description0,
SMS_G_System_OPERATING_SYSTEM.Caption00,
SMS_R_System.Resource_Domain_OR_Workgr0,
SMS_R_System.whenCreated0,
SMS_R_System.Last_Logon_Timestamp0 from vSMS_R_System AS SMS_R_System INNER JOIN Operating_System_DATA AS SMS_G_System_OPERATING_SYSTEM ON SMS_G_System_OPERATING_SYSTEM.MachineID = SMS_R_System.ItemKey INNER JOIN _RES_COLL_CAS000A9 AS SMS_CM_RES_COLL_CAS000A9 ON SMS_CM_RES_COLL_CAS000A9.MachineID = SMS_R_System.ItemKey
Let me know.
Nick Pilon | Blog : System Center Dudes -
SQL Query converted to PL/SQL?
I am trying to get my sql query here (which works) converted over to a pl/sql function so I can use an IF / THEN statement to determine whether my 2nd search field has been submitted with something in it.
My current query:
select
comm_Devices.ID,
comm_Devices.PhonePager,
comm_Devices.FirstName,
comm_Devices.LastName,
comm_Devices.Vendor,
comm_DeviceType.Device,
comm_Devices.PhoneNo,
comm_Devices.Location,
comm_Vendors.VendorName
from comm_Devices
Inner Join comm_DeviceType
on comm_Devices.DeviceTypeID = comm_DeviceType.ID
Inner Join comm_Vendors
on comm_Vendors.vendorId = comm_Devices.vendor
where
comm_Devices.LastName LIKE '%' || upper(:P1_SEARCH_LAST_NAME) || '%'
and comm_Vendors.VendorName LIKE '%' || upper(:P1_SEARCH_VENDOR) || '%'
What I am wanting to do is convert it to pl/sql so I can do this:
if :P1_SEARCH_VENDOR != '' then
q:=q||'and comm_Vendors.VendorName LIKE '%' || upper(:P1_SEARCH_VENDOR) || '%';
end if;
Any help would be greatly appreciated!You are fairly close to figuring this out. Basically you want to create a Quesry Region of type :SQL Query (Pl/SQL Function Body Returning Sql Query).
Then as most of the Dynamic query examples shouw you would do something like
declare
q varchar2(32767); -- query
w varchar2(4000); -- where clause
we varchar2(1) :='N'; -- identifies if where clause exists
begin
q := 'select "comm_Devices"."ID", ' ||
' "comm_Devices"."PhonePager", ' ||
' "comm_Devices"."FirstName",' ||
' "comm_Devices"."LastName", ' ||
' from "comm_Devices" ' ||
' Inner Join "comm_DeviceType" on "comm_Devices"."DeviceTypeID" = "comm_DeviceType"."ID" ' ||
' Inner Join "comm_Vendors" on "comm_Vendors"."vendorId" = "comm_Devices". "vendor" ';
if :P1_SEARCH_VENDOR != '' then
w := "where statement";
we := 'Y';
END IF;
IF we = 'Y' THEN
q := q || w;
END IF;
return q;
end;
This should get you started.
James
Message was edited by:
[email protected] -
Error with sql developer converter....
I am converting a view to pl/sql from ms SQL.
I have a particular line of code that is causing an error.
MS SQL:
NULLIF(dbo.ItemVarValues.ItemVarValueName, '') IS NOT NULL
PL/SQL:
AND NULLIF(itemvarvalues.itemvarvaluename, ' ' ) IS
NOT NULL;
Getting an error on the above statement.
Does anyone know what the correct syntax is for the second part of the NullIf expression?
TIAEmpty strings already are NULL in Oracle, so just lose the NULLIF.
K. -
Dynamic SQL Pivoting(Converting Row to Columns)
Hi All,
I am using Oracle 9i (Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production)
and also 10g version
I am facing difficulties to find out the logic for
converting the set of values in one of the columns into the column headings for the entire query.
create TABLE my_tab ( deptno VARCHAR2(5), job VARCHAR2(50), sal NUMBER);
insert into my_tab ( deptno,JOB, sal) values ( 10, 'ANALYST', 23000);
insert into my_tab ( deptno,JOB, sal) values ( 10, 'SALESMAN', 1500);
insert into my_tab ( deptno,JOB, sal) values ( 10, 'CLERK', 3550);
insert into my_tab ( deptno,JOB, sal) values ( 20, 'SALESMAN', 700);
insert into my_tab ( deptno,JOB, sal) values ( 20, 'ANALYST', 4200);
insert into my_tab ( deptno,JOB, sal) values ( 30, 'SALESMAN', 5600);
insert into my_tab ( deptno,JOB, sal) values ( 30, 'CLERK', 12000);
insert into my_tab ( deptno,JOB, sal) values ( 30, 'ANALYST', 19000);
COMMIT;
SELECT * FROM my_tab
DEPTNO ______ JOB ________ SAL
10 ______ ANALYST ________ 23000
10 ______ SALESMAN ________ 1500
10 _______ CLERK ________ 3550
20 _______ SALESMAN ________ 700
20 _______ ANALYST ________ 4200
30 _______ SALESMAN ________ 5600
30 _______ CLERK _______ 12000
30 _______ ANALYST _______ 19000
--And I wish to convert it into this structure:
DEPTNO ________ ANALYST ________ SALESMAN _________ CLERK
10 ________ 23000 ________ 1500 _________ 3550
20 ________ 4200 ________ 700 _________ NULL
30 ________ 19000 ________ 5600 _________ 12000
It may be dynamic. i.e Later i inserted more two records into My_tab.
insert into my_tab ( deptno,JOB, sal) values ( 20, 'CLERK', 3400);
insert into my_tab ( deptno,JOB, sal) values ( 30, 'MANAGER', 48000);
So it should be dynamic.
output is like this.
DEPTNO ________ ANALYST ______ SALESMAN ______ CLERK ______ MANAMGER
10 ________ 23000 ______ 1500 ______ 3550 ______ NULL
20 ________ 4200 ______ 700 ______ 3400 ______ NULL
30 ________ 19000 ______ 5600 ______ 12000 ______ 48000
Please help me regarding this.
With warm regards,
PrasantaHi, Prasanta,
Displaying one column from many rows as many columns on one row is called Pivoting . The following thread shows the basics of how to pivot:
Help for a query to add columns
That example uses the aggregate COUNT function; you'll want SUM (or possibly MIN or MAX) instead.
Getting a dynamic number of columns requires Dynamic SQL . As a simpler alternative to pivoting and dynamic SQL, you might consider String Aggregation , where you concatenate a column from many rows into one big string, to be displayed on one row.
See the following thread for more about string aggregation and other options on pivoting into a variable number of columns:
Re: Report count and sum from many rows into many columns -
Blank values returned from SQL Server Convert to Query Template
I am attempting to migrate Query Templates from Oracle to SQL Server. In the Oracle version I am using TO_CHAR to convert a date to a particular string format. To return the same string format in SQL Server I have to use CONVERT. The TO_CHAR returns a value which is displayed by the Query Template Test function. However, in the case of the CONVERT a blank is returned even though it works perfectly well when I run the same query in SQL Server Management Studio. Can anyone tell me why is this happening or suggest a fix? Thanks. John.
John,
Glad that did the trick.
Native client tools like SQLPlus, Toad, Query Analyzer, etc. will often not care about column names, sometimes labelling the column as the full messy expression and sometimes calling it Expr1, but when doing aggregate expression or conversion type columns in an MII query you should adopt the habit of aliasing the columns in the query.
What a better way to control the situation than to dictate it in your request
Regards,
Jeremy -
SQL to convert rows with more than one columns to columns
Hi All,
I have a typical question here. As must have been in most of the recent databases, the attributes of a master table are put in a child table. So an SQL query will return multiple rows with each row having each attribute.
Eg: Object OBJ has 5 attributes - A, B, C, D, E. The tables would be
TABLE OBJ
======
OBJ_ID (PK) (Say ID1)
OBJ_COL1
OBJ_COL2
TABLE OBJ_CHILD
========
OBJ_CHILD_ID (PK)
OBJ_ID(FK)
ATTRIBUTE (The data will be A,B,C,D,E for each OBJ_ID)
ATTRIBUTE_VALUE (Value for each attribute. say 1,2,3,4,5)
Query : SELECT OBJ_ID, ATTRIBUTE, ATTRIBUTE_VALUE FROM OBJ < OBJ_CHILD where OBJ.OBJ_ID = OBJ_CHILD.OBJ_ID
This will return 5 rows as :
OBJ ATTRIBUTE ATTRIBUTE_VALUE
=== ======== =============
ID1 A 1
ID1 B 2
ID1 C 3
ID1 D 4
ID1 E 5
I need to return rows as follows:
ID1 A 1 B 2 C 3 D 4 E 5
Is this thing possible in SQL? Even with a function ? (Its a transpose but with two columns in every row)
Thanks,
Midhun.
P.S. I am on Oracle 10g.Hi
user8830587 wrote:
... I need to return rows as follows:
ID1 A 1 B 2 C 3 D 4 E 5How many columns is that?
If it's 11 or 12 separate columns, then look for Pivot .
If it's 2 or 3 columns (where the last one is all the data from obj_child concatenated together), then look for String Aggregation .
Either can be done with any number of columns.
If you have a choice, you'll probably want to do string aggregation rather than pivot.
If you'd like help, post a little sample data (CREATE TABLE and INSERT statements) for both tables.
Also post the results you want from that data, clearly formatted to show the columns. When you post formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) before and after each section of formatted text, to preserve spacing.
Edited by: Frank Kulash on May 14, 2010 6:26 AM -
A basic question from a SQL Server convert
Hello:
I am new to Oracle coming in with a SQL server background. I wanted to create a stored procedure that returns a SELECT result set.
When I tried the following code:
CREATE OR REPLACE PROCEDURE spTest
AS
BEGIN
SELECT
Last_Name_C || ', ' || First_Name_C as Name_C, User_ID_C, Email_C, Phone_C
FROM
S_USER
ORDER BY
Name_C;
END;
I get an error message, "an INTO clause is expected in this SELECT statement"
How can I return the SELECT result set via a stored procedure?
Thanks.
VenkiSQL> create or replace function f return sys_refcursor as
2 c sys_refcursor;
3 begin
4 open c for select * from emp;
5 return c;
6 end;
7 /
Function created.
SQL> var c refcursor
SQL> exec :c := f
PL/SQL procedure successfully completed.
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> create or replace procedure p (p_c out sys_refcursor) as
2 begin
3 open p_c for select * from emp;
4 end;
5 /
Procedure created.
SQL> exec p(:c)
PL/SQL procedure successfully completed.
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> -
SQL Error-Converting the nvarchar value to datatype int
I am having error when I use the range of july but other date range are okay.
here is error:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value 'Vital Ventures Mgt. Corp.' to data type int.
Select A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P From (SELECT CONVERT(nvarchar,a.TaxDate,101) A,a.LicTradNum B,a.CardCode C,ISNULL(a.CardName,' ') D,Case When a.DocType='I' Then a.Comments When a.DocType='S' then (Select top 1 (dscription) from INV1 where docEntry=d.docentry and VatGroup=d.VatGroup)End E,ISNULL(f.SeriesName,'')+Cast(a.DocNum as nvarchar) F,Case When a.DocType='I' Then a.Max1099 When a.DocType='S' Then SUM(d.PriceAfVat) End G,0 H
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End I
,Case when e.Name LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End J
,Case when e.Name LIKE '%VAT EXEMPT' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End K
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.vatSum When a.DocType='S' Then SUM(d.vatSum) End Else 0 End L,'' M,a.DocType N,'SI' O,a.DocNum P
from OINV a inner join OCRD c on a.CardCode=c.CardCode inner join INV1 d on a.DocEntry=d.DocEntry left join NNM1 f on a.Series=f.Series
inner join OVTG e on d.VatGroup=e.Code Where a.DocDate Between '07/01/2014' AND '07/31/2014' and (f.SeriesName = 'SI' or a.Series = '-1') GROUP BY d.VatGroup,CONVERT(nvarchar,a.TaxDate,101),a.LicTradNum,a.CardCode, a.CardName,a.Doctype,a.comments,a.docnum,a.Max1099,e.name,a.vatsum,d.docentry,ISNULL(f.SeriesName,'')
UNION ALL
SELECT CONVERT(nvarchar,a.TaxDate,101) A,a.LicTradNum B,a.CardCode C,ISNULL(a.CardName,' ') D,Case When a.DocType='I' Then a.Comments When a.DocType='S' Then (Select top 1 (dscription) from RIN1 where docEntry=d.docentry and VatGroup=d.VatGroup) End E,ISNULL(g.SeriesName,'')+Cast(a.DocNum as nvarchar) F,Case When a.DocType='I' Then a.Max1099*-1 When a.DocType='S' Then SUM(d.PriceAfVat*-1) End G,Case When f.AcctName='SALES DISCOUNTS (Trading)' Then SUM(d.LineTotal) Else 0 End H
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End I
,Case when e.Name LIKE '%Zero Rated' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End J
,Case when e.Name LIKE '%VAT EXEMPT' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End K
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.vatSum*-1 When a.DocType='S' Then SUM(d.vatSum*-1) End Else 0 End L,'' M,a.DocType N,'SR/D' O,a.DocNum P
from ORIN a inner join OCRD c on a.CardCode=c.CardCode inner join RIN1 d on a.DocEntry=d.DocEntry inner join OACT f ON d.acctCode=f.acctCode left join NNM1 g on a.Series=g.Series
inner join OVTG e on d.VatGroup=e.Code Where a.DocDate Between '07/01/2014' AND '07/31/2014' and (g.SeriesName = 'SR/D' or a.Series = '-1') GROUP BY d.VatGroup,CONVERT(nvarchar,a.TaxDate,101),a.LicTradNum,a.CardCode, a.CardName,a.Doctype,a.comments,a.docnum,a.Max1099,e.name,a.vatsum,d.docentry,f.AcctName,ISNULL(g.SeriesName,'')
UNION ALL SELECT CONVERT(nvarchar,a.TaxDate,101) A,f.LicTradNum B,c.CardCode C,ISNULL(c.CardName,' ') D,c.comments E,'OR'+Cast(a.Ref1 as nvarchar) F,Case When d.Debit<>0 Then SUM(d.basesum + d.debit)*-1 Else SUM(d.basesum + d.credit) End G,0 H
,Case When d.debit<>0 then d.BaseSum*-1 Else d.BaseSum End I,0 J,0 K,Case When d.debit<>0 then d.debit*-1 Else d.Credit End L,'' M,'S' N,'OR' O,a.Ref1 P
from OJDT a inner join ORCT c on a.Ref1=c.DocNum inner join JDT1 d on a.TransId=d.TransId Inner Join OCRD f on c.CardCode=f.Cardcode
inner join OVTG e on d.VatGroup=e.Code Where a.TaxDate Between '07/01/2014' AND '07/31/2014' and d.VatGroup='Output-S' and a.TransType=30 GROUP BY d.VatGroup,CONVERT(nvarchar,a.TaxDate,101),f.LicTradNum,c.CardCode, c.CardName,c.comments,a.Ref1,a.loctotal,d.credit,d.debit,d.baseSum
) A Group By A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P Order By O,PHi Raphael...
Try This
Select A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P From (SELECT a.TaxDate A,a.LicTradNum B,a.CardCode C,ISNULL(a.CardName,' ') D,Case When a.DocType='I' Then a.Comments When a.DocType='S' then (Select top 1 (dscription) from INV1 where docEntry=d.docentry and VatGroup=d.VatGroup)End E,ISNULL(f.SeriesName,'')+Cast(a.DocNum as nvarchar) F,Case When a.DocType='I' Then a.Max1099 When a.DocType='S' Then SUM(d.PriceAfVat) End G,0 H
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End I
,Case when e.Name LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End J
,Case when e.Name LIKE '%VAT EXEMPT' Then Case When a.DocType='I' Then a.Max1099-a.VatSum When a.DocType='S' Then SUM(d.LineTotal) End Else 0 End K
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.vatSum When a.DocType='S' Then SUM(d.vatSum) End Else 0 End L,'' M,a.DocType N,'SI' O,a.DocNum P
from OINV a inner join OCRD c on a.CardCode=c.CardCode inner join INV1 d on a.DocEntry=d.DocEntry left join NNM1 f on a.Series=f.Series
inner join OVTG e on d.VatGroup=e.Code Where a.DocDate Between '07/01/2014' AND '07/31/2014' and (f.SeriesName = 'SI' or a.Series = '-1') GROUP BY d.VatGroup,a.TaxDate,a.LicTradNum,a.CardCode, a.CardName,a.Doctype,a.comments,a.docnum,a.Max1099,e.name,a.vatsum,d.docentry,ISNULL(f.SeriesName,'')
UNION ALL
SELECT a.TaxDate A,a.LicTradNum B,a.CardCode C,ISNULL(a.CardName,' ') D,Case When a.DocType='I' Then a.Comments When a.DocType='S' Then (Select top 1 (dscription) from RIN1 where docEntry=d.docentry and VatGroup=d.VatGroup) End E,ISNULL(g.SeriesName,'')+Cast(a.DocNum as nvarchar) F,Case When a.DocType='I' Then a.Max1099*-1 When a.DocType='S' Then SUM(d.PriceAfVat*-1) End G,Case When f.AcctName='SALES DISCOUNTS (Trading)' Then SUM(d.LineTotal) Else 0 End H
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End I
,Case when e.Name LIKE '%Zero Rated' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End J
,Case when e.Name LIKE '%VAT EXEMPT' Then Case When a.DocType='I' Then (a.Max1099-a.VatSum)*-1 When a.DocType='S' Then SUM(d.LineTotal*-1) End Else 0 End K
,Case when e.Name NOT LIKE '%VAT EXEMPT' And e.Name NOT LIKE '%Zero Rated' Then Case When a.DocType='I' Then a.vatSum*-1 When a.DocType='S' Then SUM(d.vatSum*-1) End Else 0 End L,'' M,a.DocType N,'SR/D' O,a.DocNum P
from ORIN a inner join OCRD c on a.CardCode=c.CardCode inner join RIN1 d on a.DocEntry=d.DocEntry inner join OACT f ON d.acctCode=f.acctCode left join NNM1 g on a.Series=g.Series
inner join OVTG e on d.VatGroup=e.Code Where a.DocDate Between '07/01/2014' AND '07/31/2014' and (g.SeriesName = 'SR/D' or a.Series = '-1') GROUP BY d.VatGroup,a.TaxDate,a.LicTradNum,a.CardCode, a.CardName,a.Doctype,a.comments,a.docnum,a.Max1099,e.name,a.vatsum,d.docentry,f.AcctName,ISNULL(g.SeriesName,'')
UNION ALL SELECT a.TaxDate A,f.LicTradNum B,c.CardCode C,ISNULL(c.CardName,' ') D,c.comments E,'OR'+Cast(a.Ref1 as nvarchar) F,Case When d.Debit<>0 Then SUM(d.basesum + d.debit)*-1 Else SUM(d.basesum + d.credit) End G,0 H
,Case When d.debit<>0 then d.BaseSum*-1 Else d.BaseSum End I,0 J,0 K,Case When d.debit<>0 then d.debit*-1 Else d.Credit End L,'' M,'S' N,'OR' O,a.Ref1 P
from OJDT a inner join ORCT c on a.Ref1=c.DocNum inner join JDT1 d on a.TransId=d.TransId Inner Join OCRD f on c.CardCode=f.Cardcode
inner join OVTG e on d.VatGroup=e.Code Where a.TaxDate Between '07/01/2014' AND '07/31/2014' and d.VatGroup='Output-S' and a.TransType=30 GROUP BY d.VatGroup,a.TaxDate,f.LicTradNum,c.CardCode, c.CardName,c.comments,a.Ref1,a.loctotal,d.credit,d.debit,d.baseSum
) A Group By A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P Order By O,P
Regards
Kennedy -
MS sql test converted to long and job log states that 1 row read at time
I am going from ms sql to ms sql server. The source text datatype is being covnerted to a long. No problem there. However, when the job runs, there is a warning: Rows per committ has been reset to 1 because table conatins a long column.
11.7 of DI
How can I get around this?Michael,
This is indeed a limitation in the DI 11.7 (and earlier) releases which might result in a slower performance when loading data with long or CLOB datatypes.
In DI XI 3.0 (or version 12.0) we significantly improved the large object support. Main improvements were supporting BLOB (in addition to CLOB), extending support to more BLOB/CLOB datatypes for all databases and an optimized intermediate storage of the large objects. Removing the commit=1 restriction was a side effect of these optimizations.
Ben.
Maybe you are looking for
-
Hi i got an error during my programming "ACCESS DENIED" while working with files. I'm not able to load the file into "BufferedInputStream". What could be the possible mistake i might have done? my GUI goes like this::: I have a JTree which browses th
-
Hi, I want to Maintain MM ( GR Document ) number ranges for the fiscal year 2010 - 2011 . Can we do it ? Wats the procedure ? Regards Rajesh
-
Gurus/Experts I have to delete and reload the 0IC_C03 infocube in the middle now. Can any one tell me the steps from R3 side for setting up the delta update please Is the BX datasource needed for initialization ?? if yes then i have to do the SBIW-->
-
Favorites not staying put!
I had a recent issue where a message popped up that said, Codec not found. Well, I figured out the issue, but only after deleting my preferences and .plist files. Anyway, after I resolved my "Codec not found" issue, I had to rebuild my Favorite trans
-
MOVED: A75MA-G55 Static-y, echo-y audio output from local files
This topic has been moved to Linux/Unix. https://forum-en.msi.com/index.php?topic=156801.0