I have a query (that I cannot modify) that starts like this
with CodeSet (
code_context_c
, bom_index_c
, src_qs_c
, src_code_set_c
, src_code_set_x
, src_code_value_c
, src_code_value_x
, tgt_code_set_c
, tgt_code_value_c
) as (
SELECT ...
and then goes on. Now I need to use it as a subquery and do something like
select * from (with CodeSet (
code_context_c
, bom_index_c
, src_qs_c
, src_code_set_c
, src_code_set_x
, src_code_value_c
, src_code_value_x
, tgt_code_set_c
, tgt_code_value_c
) as (
SELECT ...
but Teradata does not like it... Anyone has seen this before? Changing the query would require some time and I would prefer not to. Anyone can help me out here?
Error message is:
SELECT Failed. [3707] Syntax error, expected something like a name or a Unicode delimited identifier or '(' between the 'from' keyword and the 'as' keyword.
Thanks in advance,
Umberto
Not sure if you are still looking for the answer, but you need to run the SELECT after your WITH statement. WITH doesn't actually materialize a table until you SELECT from it. So something like this:
;WITH CodeSet (
blah
, blah
, ...
) AS (
SELECT blah
, blah
, ...
)
;
SELECT * FROM CodeSet;
Related
According to all examples my query should be executing. I am trying to update new column on my table with the last 4 digits of the phone number like so :
UPDATE users
SET users.phone_last_4 = t.lastFour
FROM
(
select substr( phone_number, -4) as lastFour from users
) t;
Also tried this:
UPDATE users
SET users.phone_last_4 = t.lastFour
FROM
(
select substr( phone_number, -4) as lastFour from users
) AS t;
Both fail with same error :
near ".": syntax error: UPDATE users
SET users.
What could I possibly do wrong here?
SQLite does not support joins for the UPDATE statement and also this syntax containing FROM .
In your case I can't see why you need it.
Just do:
UPDATE users
SET phone_last_4 = substr(phone_number, -4)
I would like to display the contents of a BLOB using the functions provided by Anton Scheffer using this query in sql developer: [1.] select * from table( as_read_xlsx.read( v_blob ) ); --"v_blob" is a variable containing blob with xlsx but I have BLOB in some other table. To get BLOB i have to use this: [2.]select bb from at_table_temp where id_c=4
So, the question is how to put [2.] as an argument to [1.]:
select * from table( as_read_xlsx.read([2.]) );
I already tried the following but it didn't work:
select * from table( as_read_xlsx.read( $"[2.]" ) );
select * from table( as_read_xlsx.read( #"[2.]" ) );
select * from table( as_read_xlsx.read( $([2.]) ) );
Looking forward to your answers!
Try this:
select * from at_table_temp t cross join table(as_read_xlsx.read(t.bb));
Here is my INSERT statement:
INSERT INTO customer_payment (payment_type_id, PAYMENT_METHOD, PAYMENT_STATUS, sql_sequence)
((SELECT emcpm.payment_method_type_id,
epmt.description, ecba.mandate_status
FROM cust_pay_map emcpm, payment_method_type epmt, customer_bank_account ecba
WHERE emcpm.payment_method_type_id = ecba.payment_method_type_id), MY_SEQ.nextval);
I get the error
ORA-00907: missing right parenthesis
when I run it. Please help me correct the mistake.
Add the sequence in the select statement like this:
INSERT
INTO customer_payment
(
payment_type_id,
PAYMENT_METHOD,
PAYMENT_STATUS,
sql_sequence
)
SELECT emcpm.payment_method_type_id,
epmt.description,
ecba.mandate_status ,
MY_SEQ.nextval
FROM cust_pay_map emcpm,
payment_method_type epmt,
customer_bank_account ecba
WHERE emcpm.payment_method_type_id = ecba.payment_method_type_id;
I'm trying to write a PL/SQL to convert comma separated string into an array and iterate through that.
for that I created a datatype as follows:
"CODE_TABLE_TYPE" AS TABLE OF VARCHAR2(500)
crated a function - STR_TO_CODE_TABLE to convert the comma separated string in to the table of CODE_TABLE_TYPE.
and the PL/SQL looks like this:
FOR DEP IN ( SELECT * FROM TABLE ( CAST( STR_TO_CODE_TABLE( IN_DES_AIRPORTS ) AS CODE_TABLE_TYPE ) ) ) LOOP
SELECT * INTO RESULTS FROM MY_TABLE
WHERE IN_ID = MY_TABLE.ID
AND ( SELECT 1 FROM TEMP_TABLE WHERE DEPARTURE LIKE '%' || DEP || '%' )= 1;
END LOOP;
But it gives an error saying "expression is of wrong type". But the datatype is varchar2.
Can anyone please suggest what's the possible cause for this. What should I do to avoid this issue?
---- Done with Symfony2.3.1 and Doctrine2 ----
Sorry, i hope i was not too stupid to find a suitable solution for my problem. I try to build a Query for hours.
SELECT * FROM product
WHERE product_id in
(
SELECT product_id from (
SELECT count(*) as result_amount, product_id FROM product_x_attribut
JOIN productattribut on productattribut_id = productattribut.id
WHERE (
productkey = "price" and
stringType = "premium"
) or (
productkey = "size" and
stringType = "S"
)
GROUP BY product_id
HAVING result_amount = 2
) as temp
)
GROUP BY product_id
ORDER BY p0_.name ASC
This is the SQL which works fine in phpmyAdmin.
This can be seen like
Select * from abc where abc.x in ( Select * from ( select * from ) as abcd )
So there is one core query, i call it subSubQuery, the second query around the core will be called subQuery and the outer Query is just the outer Query, no a Subquery.
I could build the subSubQuery with Doctrine2.
But i cannot built the subQuery like this
Select product_id from ( $subSubQuery->getQuery()->getDQL() )
I want to do the subQuery like this
$subQuery = $repositoryProduct->createQueryBuilder('product');
$subQuery->add('select', 'product_id');
$subQuery->add('from',$subSubQuery->getDQL() );
// However to set an alias is a miracle for me, this didnt work off course
$subQuery->add('as','tmp' );
This is the subQuery.
I also cannot build the outer Query
Select * from abc where abc.x in ( $subQuery->getQuery()->getDQL() )
I want to do this like this
$query->where(
$query->expr()->in('product.id', $subQuery->getDQL() )
);
But i try to build this with Doctrine2 like this:
I am so down, i tried ->getSQL(), ->getDQL(), i tried as much as i was able to detect as a suitable tiny step to a solution for this problem and i has tried as much keyword in google as my finger were able to write... I hope someone could help me to find a solution...
Thanks a lot to each helpful advise.
I know that statements like this work:
$qbGames->andWhere($qbGames->expr()->in('game.id',$qbGameId->getDQL()));
Your question is kind of hard to follow. Consider using pastebin to show all your mappings as they currently exist. And then maybe presenting a simplieid query?
My $qbGameId query was built with:
$qbGameId = $em->createQueryBuilder();
$qbGameId->addSelect('distinct gameGameId.id');
$qbGameId->from('ZaysoCoreBundle:Event','gameGameId');
// Assorted joins and where conditions