Exporting data from query results - user-defined-functions

I am using MS SQL server 2014.
I have a table-valued function
ALTER FUNCTION [dbo].[Resultsaddresssearch](#addressLine nvarchar, #locality nvarchar, #adminDistrict nvarchar, #postalCode nvarchar, #countryRegion nvarchar)
RETURNS TABLE (
[Name] nvarchar NULL,
[Point] [geography] NULL,
[BoundingBox] [geography] NULL
) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [xtest2].[addresssearch.UserDefinedFunctions].[GeocodeTVF]
that I use this query
SELECT * FROM dbo.Resultsaddresssearch('999 NE 10th%', '', '', '', 'USA');
The results I wish to export to a premaded csv that is addy,csv. When I used the export manager, I selected the sql native client 11 as source. Then select Flat File as destination. I enter the query from above and hit next and I get this error:
- Column "Point": Source data type "204" was not found in the data type mapping file.
- Column "BoundingBox": Source data type "204" was not found in the data type mapping file.
Thanks

It is not what I what but creating an sql query
Insert into [dbo].[ConversionofGeotest2]
Select * from Geotest2 ('62 NE 10th Ave', '', '', '97211', 'US');

Related

ORACLE: The best way to parse JSON into collection of object types

I have an object type: create type t_ref_rec is object(id number, name varchar2(256));
And a table type: create type t_ref_tbl is table of t_ref_rec;
I parse JSON onto a collection like this:
declare
var_ref_tbl t_ref_tbl;
begin
...
select
t_ref_rec(id, name)
bulk collect into
var_ref_tbl
from
json_table
(
'[{"id":1, "name":"one"}, {"id":2, "name":"two"}]',
'$[*]'
columns
(
id number path '$.id',
name varchar2 path '$.name'
)
);
....
end;
Is there a better way to parse data from JSON into a collection of t_ref_tbl type?
If you're on 19c or higher, the best way is to state your object as the return type for a JSON_value call and the database will map it for you:
create type t_ref_rec is object(id number, name varchar2(256));
/
create type t_ref_tbl is table of t_ref_rec;
/
select json_value (
'[{"id":1, "name":"one"}, {"id":2, "name":"two"}]',
'$' returning t_ref_tbl
) obj
from dual;
OBJ(ID, NAME)
---------------------------------------------------
T_REF_TBL(T_REF_REC(1, 'one'), T_REF_REC(2, 'two'))
The on mismatch clause enable you to define what happens if there's a difference between the JSON document and the object type.

Insert records into collection type Oracle

I want to inserted into my collection some SQL records, but I can not. I'm a beginner. Can you help me ?
This is my tables :
CREATE TYPE article_type AS OBJECT (idA CHAR(10), nomA CHAR(10), prixA CHAR(10) )
CREATE TYPE facture_type AS OBJECT (idF CHAR(10), dateFact DATE)
CREATE TYPE ens_collection_fact AS OBJECT (refFact facture_type, refArticle article_type)
CREATE TYPE collection_fact AS TABLE OF ens_collection_fact
CREATE TYPE client_type AS OBJECT (idC NUMBER, nomC CHAR(10),adresse CHAR(10), Compose collection_fact )
CREATE TABLE Article OF article_type
CREATE TABLE Facture OF facture_type
CREATE TABLE Client OF client_type (PRIMARY KEY(idC)) NESTED TABLE Compose STORE AS temp
This is my query that I want to insert, but I have an error from the Oracle : ORA-02315
INSERT INTO ECOLER.CLIENT VALUES
(100, 'Jules Verne', '1', Collection_fact(Ens_collection_fact(reffact('A','2002-12-10'), ens_collection_fact(refarticle('D','E','F'))) ))
Thank in advance
reffact and refarticle are identifiers for objects within other objects, not types; you need to refer to the actual types. You also need to supply both values for each Ens_collection_fact attribute for the default constructor; you can pass null if you only want one or the other:
INSERT INTO CLIENT VALUES
(100, 'Jules Verne', '1',
Collection_fact(
Ens_collection_fact(facture_type('A',date '2002-12-10'), null),
Ens_collection_fact(null, article_type('D','E','F'))
)
)
Also notice that I've added the date keyword so it's providing an actual date literal rather than a string, which would be converted - if you're lucky - with your session NLS settings.
This will still error because 'Jules Verne' is 11 characters and you've defined the name attribute as 10 characters/bytes, but it will work with a shorter string literal.
db<>fiddle

Unable to create table through another table in oracle SQL developer

I have been trying to create a new table by using below query :
"Create table d1_details_test2
as
select * from d1_details"
this above query gives me an error :
actually "d1_details" table has one column which has "Long" datatype and i cannot change it.
so i want to know the any other way to create the table.
Thanks
The long data type is subject to many restrictions. Create table as select is one of these.
You can get around it by applying to_lob in the select, which converts it to a clob:
create table views as
select view_name, text from user_views;
ORA-00997: illegal use of LONG datatype
create table views as
select view_name, to_lob ( text ) lob
from user_views;
desc views
Name Null? Type
VIEW_NAME VARCHAR2(128)
LOB CLOB

SQL Server Polybase create external table ERROR to Oracle with column datatype TIMESTAMP WITH TIME ZONE

Created database scoped credential and an external datasource to Oracle OK.
Creating external table on Orcle table with a column datatype TIMESTAMP WITH TIME ZONE fails no matter what datatype I try to use.
CREATE EXTERNAL TABLE MYSCHEMA.MY_EXT_TABLE
(
SOMECOL NVARCHAR(21) COLLATE Finnish_Swedish_BIN, -- OK
SOME_DATETIME DATETIME2, -- OK
SOME_DATE_COMM DATE,-- OK
SOME_FLOAT float,-- OK
SOME_TIMESTAMP datetimeoffset(7) -- NOK
)
WITH
(
LOCATION = N'ORACLEDATABASE.SCHEMA.TABLE',
DATA_SOURCE = my_oracle_ds
)
GO
Fails with error:
Msg 105083, Level 16, State 1, Line 2
105083;The following columns in the user defined schema are incompatible with the external table schema for table 'SOME_TABLE': 'SOME_TIMESTAMP' failed to be reflected with the error: 'The detected backend type TIMESTAMP(6) WITH TIME ZONE is not supported for external generic tables.'
I tried with datetime, datetime2, datetimeoffset, NVARCHAR but the same error occurs.
Is there a workaround for polybase/generic tables or do I have to skip these columns?
CREATE EXTERNAL TABLE MYSCHEMA.MY_EXT_TABLE
(
SOMECOL NVARCHAR(21) COLLATE Finnish_Swedish_BIN,
SOME_DATETIME DATETIME2,
SOME_DATE_COMM DATE,
SOME_FLOAT FLOAT,
SOME_TIMESTAMP TO_TIMESTAMP_TZ('America/Los_Angeles', 'TZR')
) WITH ( LOCATION = N'ORACLEDATABASE.SCHEMA.TABLE' , DATA_SOURCE = my_oracle_ds ) GO

Oracle Error Inconsistent Datatype on select statement

I'm using the Oracle's console Database Express Edition and I'm creating a database with my own data types. Everything is OK creating and inserting new data, but when I make a select from my data type, for example, "direccion", Oracle returns me the error 00932, "inconsistent datatypes".
I execute this code:
CREATE TYPE lista_tel_t AS VARRAY(10) OF VARCHAR2(20) ;
CREATE TYPE direccion_t AS OBJECT (
calle VARCHAR2(200),
ciudad VARCHAR2(200),
prov CHAR(2),
codpos VARCHAR2(20)
) ;
CREATE TYPE cliente_t AS OBJECT (
clinum NUMBER,
clinomb VARCHAR2(200),
direccion direccion_t,
lista_tel lista_tel_t
) ;
CREATE TABLE cliente_tab OF cliente_t(clinum PRIMARY KEY);
The problem comes when I make a select from a type, for example:
SELECT direccion FROM cliente_tab;
When I make this select it returns me the following error:
ORA-00932: inconsistent datatypes: expected NUMBER got DIRECCION_T
My question is... How can I make the select and show the result properly?
Try:
SELECT direccion.calle,
direccion.ciudad,
direccion.prov,
direccion.codpos
FROM cliente_tab;
Or, if you want to work in PL/SQL with objects you may try to Bulk Collect the table into a collection of objects.
For more information see the Oracle® Database Object-Relational Developer's Guide

Resources