this is my problem, I got a database in ISO-8859-1
and I have my webpage in UTF-8, I want to remove the accents from my queries
I'm able to find names without accents but if they have them I'm unable to find them
(down there I have a name with accent, I can't find the name) Help, please, I'm dying here...
I have this:
$el=array(); //<----------------------------------------------------vowels to remove
$el[]=iconv('UTF-8','ISO-8859-1','á');
$el[]=iconv('UTF-8','ISO-8859-1','é');
$el[]=iconv('UTF-8','ISO-8859-1','í');
$el[]=iconv('UTF-8','ISO-8859-1','ó');
$el[]=iconv('UTF-8','ISO-8859-1','ú');
$string='Francisco Gutiérrez'; //<----------------------------------------target
$string=strtolower($string); ///<----------------------------------string to iso
$string=iconv('UTF-8','ISO-8859-1',
$string);
$tem3="SELECT nom||' '||app||' '||apm as NAME
FROM STUDENTS
where
(
upper(
replace(
replace(
replace(
replace(
replace(
lower(NAME),'".$el[0]."','a'),
'".$el[1]."','e'),
'".$el[2]."','i'),
'".$el[3]."','o'),
'".$el[4]."','u')
)
like '%'||
upper(
replace(
replace(
replace(
replace(
replace(
'".$string."','".$el[0]."','a'),
'".$el[1]."','e'),
'".$el[2]."','i'),
'".$el[3]."','o'),
'".$el[4]."','u')
)||'%'
)";
You can do SQL CONVERT(string, destination_encoding, source_encoding), which gives ? for unconvertible chars, you could drop with a replace.
If you do
$string = iconv('UTF-8','ASCII//TRANSLIT', $string);
SELECT CONVERT(nom, 'US7ASCII', 'WE8ISO8859P1')
FROM STUDENTS LIKE ... $string ... ;
You fall back on ASCII which should do nicely.
ISO-8859-1 might do too.
Related
I have a text file with the following format.
"01|""sample""|""Test"|""testing""|""01"|"""".
I have created an external table in Azure Synapse by setting the format option STRING_DELIMITER to '"'. But while processing the file through an sp, i am getting the below-given error.
"Could not find a delimiter after string delimiter"
Is there any solution available for this? Any help would be appreciated.
Regards,
Sandeep
In my tests with that sample string, the quotes caused a problem because they are so uneven. You would be better off creating the external table ignoring the quotes and cleaning them afterwards, eg set your external file format like this:
CREATE EXTERNAL FILE FORMAT ff_pipeFileFormat
WITH (
FORMAT_TYPE = DELIMITEDTEXT,
FORMAT_OPTIONS (
FIELD_TERMINATOR = '|',
--STRING_DELIMITER = '"', -- removed
USE_TYPE_DEFAULT = FALSE
)
);
Clean the quotes out using REPLACE, eg:
SELECT
REPLACE( a, '"', '' ) a,
REPLACE( b, '"', '' ) b,
REPLACE( c, '"', '' ) c,
REPLACE( d, '"', '' ) d,
REPLACE( e, '"', '' ) e,
REPLACE( f, '"', '' ) f
FROM dbo.yourTable
My results:
CREATE EXTERNAL FILE FORMAT does not support STRING_DELIMITER char within the value of a column.
https://feedback.azure.com/forums/307516-sql-data-warehouse/suggestions/9882219-fix-string-delimiter-implementation-in-polybase
I have the an XML Column and it is similiar to the one mentioned below.
<appl>
<sftp_job name = "test1_ftp">
<ftp_job name = "test2_ftp">
<link name="testlink1">
<tag name ="task1_ftp">
<unix_job name="test123_ftp">
</appl>
My requirement is to get the value of all the atrributes that ends with "_ftp" like mentioned below.
test1_ftp
test2_ftp
task1_ftp
test123_ftp
I have the below SQL statement and it is working fine.
SELECT JOB_NAME
FROM
(SELECT q.jobname AS JOB_NAME
FROM DFTAB1
LEFT JOIN xmltable('/appl/*[contains(name(),"_job") or
contains(name(),"link") or
contains(name(),"task") ]'
PASSING XMLTYPE(DEF) columns jobname VARCHAR2(20) path '#name')q ON (1=1)
)
WHERE JOB_NAME LIKE '%_ftp%'
and this is working.
Is there a way that I can do in a single SELECT statement.
You can combine boolean operators inside your XPath query:
SELECT x.job_name
FROM DFTAB1 d
CROSS JOIN XMLTable(
'/appl/*[(contains(name(),"_job")
or contains(name(),"link")
or contains(name(),"task"))
and (ends-with(#name, "_ftp"))]'
PASSING XMLTYPE(d.DEF)
COLUMNS job_name VARCHAR2(20) path '#name'
) x;
I've used a cross join instead of a left outer join, which was essentially an inner join anyway, and effectively a cross join because of the dummy condition. I've also just called the generated column what you want it to end up as, so you don't need the alias.
Demo with your sample XML (with tag closures)
with DFTAB1 (DEF) as (
select '<appl>
<sftp_job name = "test1_ftp" />
<ftp_job name = "test2_ftp" />
<link name="testlink1" />
<tag name ="task1_ftp" />
<unix_job name="test123_ftp" />
</appl>' from dual
)
SELECT x.job_name
FROM DFTAB1 d
CROSS JOIN XMLTable(
'/appl/*[(contains(name(),"_job")
or contains(name(),"link")
or contains(name(),"task"))
and (ends-with(#name, "_ftp"))]'
PASSING XMLTYPE(d.DEF)
COLUMNS job_name VARCHAR2(20) path '#name'
) x;
JOB_NAME
--------------------
test1_ftp
test2_ftp
test123_ftp
which is the same result your original query gets; task1_ftp isn't included because tag doesn't match your original contains checks.
There is a slight difference, but I think from the question wording this is actually correct and your original wasn't quite. When you do LIKE '%_ftp%' the underscore is also a single-character wildcard, so that would match say abcftp, which I don't think you wanted. The equivalent would be escaped, as LIKE '%\_ftp%' ESCAPE '\'.
A more significant change, as MTO mentioned, is that your query looks for _ftp (or, as mentioned above, in fact just ftp) anywhere in the job name. Your question actually says 'ends with "_ftp"' so your description and query don't match. If you do want it anywhere in the attribute value, just use contains again instead of ends-with:
SELECT x.job_name
FROM DFTAB1 d
CROSS JOIN XMLTable(
'/appl/*[(contains(name(),"_job")
or contains(name(),"link")
or contains(name(),"task"))
and (contains(#name, "_ftp"))]'
PASSING XMLTYPE(d.DEF)
COLUMNS job_name VARCHAR2(20) path '#name'
) x;
though the result is the same with your sample.
SELECT q.jobname AS JOB_NAME
FROM DFTAB1 d
CROSS JOIN
XMLTABLE(
'/appl/*[contains(name(),"_job") or
contains(name(),"link") or
contains(name(),"task") ]'
PASSING XMLTYPE(d.DEF)
columns jobname VARCHAR2(20) path '#name'
) q
WHERE q.JOBNAME LIKE '%_ftp%'
I have the following query :
SELECT
ix.dt AS DT,
ix.UDBENCH_UDIDX AS UDFO,
' .' || REPLACE(REPLACE( ix.UDBENCH_UDIDX,' ',''),'IS','') AS PF_TICKER,
i.szbez AS PORTFOLIO_NAME,
ix.rm_generic_inst_type_l1,
ix.rm_generic_inst_type_l2,
ix.scd_sec_type,
m.ud_isin AS SECURITY_ID,
'%' AS POS_TYPE,
ix.sec_weight AS QUANTITY,
ix.sec_ccy,
ix.sec_price AS MKT_PRICE,
'' AS COST_PX,
'' AS POSITION_VALUE_AC,
'' AS POSITION_VALUE_FC,
m.ud_sedol AS UD_SEDOL,
m.ud_bbgid AS UD_ID_BB_UNIQUE,
m.ud_cusip AS UD_CUSIP,
m.ud_bbgid AS UD_BBGID,
m.inst_name AS INST_NAME,
ix.idas AS IDAS,
m.ud_scd_securityid AS UD_SCD_SECURITYID
FROM XXXX ix
INNER JOIN XXXXR i ON (i.udidx = ix.UDBENCH_UDIDX),
XXXXX m
WHERE ix.dt >= to_date(sdt_start,'DD.MM.YYYY')
AND ix.dt <= to_date(sdt_end,'DD.MM.YYYY')
AND ix.UDBENCH_UDIDX IN (select listagg( udfo,',') within group(ORDER BY udfo)
from XXXXX where pf_ticker is null )
AND i.szbez LIKE '%DFLT%'
AND ix.idas = m.idas;
I would like the part :
AND ix.UDBENCH_UDIDX IN (select listagg( udfo,',') within group(ORDER
BY udfo)
from XXXXX where pf_ticker is null )
Equivalent to : ix.UDBENCH_UDIDX IN ('blal','bll',blc') but it shows ix.UDBENCH_UDIDX IN (blal,bll,blc) and the result of my query is an empty table, do you know how to set listagg to have this result ( 'blal','bll',blc' instead of blal,bll,blc)?
Thanks
The IN operator doesn't work like that. You'd be comparing the UDBENCH_UDIDX values with a single string containing all udfo values, not all of the individual values of that column.
You can just use a subquery without the listagg():
AND ix.UDBENCH_UDIDX IN (select udfo from XXXXX where pf_ticker is null)
Or you can join to that table instead of using a subquery at all; something like:
FROM XXXX ix
INNER JOIN XXXXR i ON (i.udidx = ix.UDBENCH_UDIDX)
INNER JOIN XXXXX m ON (m.udfo = ix.UDBENCH_UDIDX)
WHERE ix.dt >= to_date(sdt_start,'DD.MM.YYYY')
AND ix.dt <= to_date(sdt_end,'DD.MM.YYYY')
AND i.szbez LIKE '%DFLT%'
AND ix.idas = m.idas
AND m.pf_ticker is null;
... assuming the old-style join to XXXXX m is supposed to be getting the data related to the subquery you're doing - it's hard to tell with obfuscated names. (It's not a good idea to mix old and new style joins anyway; or to use old-style joins at all). It's possible you might want that to be an outer join, or the driving table, or something else - again can't infer that from the information provided.
If you already had a set of string literals to look for then you would do something like:
IN ('val1', 'val2', 'val3')
but you don't have string literals, you have string values from a table, which are not the same. You don't need to, and shouldn't, enclose those column values in single quotes within the query. The single quotes denote a literal value which is to be treated as a string; the values in the column are already strings.
You can actually do what you asked:
select '''' || listagg(udfo, ''',''') within group (order by udfo) || '''' from ...
which would give you a comma-separated list of quoted values from your table (or an empty string, which is the same as null, if there are no matching rows. If you were generating a statement to run later then that might make some sense, but that isn't the case here.
Given an object identified by the form owner.tablename; how do I split the owner and table name up?
Both my ideas of either string tokenization or select owner, object_name from all_objects where owner || '.' || object_name = 'SCHEMA.TABLENAME' seem like hacks.
You can use DBMS_UTILITY.name_tokenize for this purpose.
This procedure calls the parser to parse the given name as "a [. b [.
c ]][# dblink ]". It strips double quotes, or converts to uppercase if
there are no quotes. It ignores comments of all sorts, and does no
semantic analysis. Missing values are left as NULL.
e.g.
DBMS_UTILITY.NAME_TOKENIZE
( name => 'SCHEMA.TABLENAME'
, a => v_schema
, b => v_object_name
, c => v_subobject -- ignore
, dblink => v_dblink
, nextpos => v_nextpos -- ignore
);
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_util.htm#BJEFIFBJ
SELECT SUBSTR('SCHEMA.TABLENAME', 0, INSTR('SCHEMA.TABLENAME', '.') - 1) OWNER,
SUBSTR('SCHEMA.TABLENAME', INSTR('SCHEMA.TABLENAME', '.') + 1) TABLE_NAME
FROM DUAL
I have written a sql query like
DECLARE #OpenDays VARCHAR(15)
SET #OpenDays = (SELECT LTRIM(RTRIM(REPLACE(SUBSTRING(OpenDays,3,LEN(OpenDays)),' - ','')))
FROM
(
SELECT DISTINCT
STUFF((SELECT ' - ' + CONVERT(VARCHAR(30),SSF.OpenDayOfWeek )
FROM #FacilityDayOpen SSF
FOR XML PATH('')
), 1, 2, ' ') as OpenDays
FROM #FacilityDayOpen S
) TS
)
How to convert this query into LINQ
it looks like a stored procedure I can recommend you use the following program
http://sqltolinq.com/
but you might want to replace you #values with values you think may work in query and then you so you can check if it working