Questions tagged [dynamic-sql]

Dynamic SQL is a technique using SQL (Structured Query Language) whose main difference from traditional SQL is that Dynamic SQL allows to build SQL statements dynamically at runtime, which eases the automatic generation and execution of program statements.

2681 questions
0
votes
1 answer

dynamic evaluation of case-when oracle sql

I'm wondering if it's possible to dynamically evaluate a case-statement in the select statement in Oracle SQL. Take the following pseudo sql code as an example: WITH temp AS ( SELECT 'WHEN ' || when_col || ' THEN ''' || then_value ||…
DSH
  • 1,038
  • 16
  • 27
0
votes
0 answers

Dynamic SQL data INSERT

I am NOT working with SSIS, I need to use OPENROWSET and bcp to make this work: I am having a folder that is frequently updated with csv files which need to be imported into a database. At the moment only ONE file is imported into the database, how…
0
votes
0 answers

How to get dynamic SQL query output into declared variable in SQL Server?

In here I've declared two variables, one is for writing a query, the other is to store the output. declare @EM_NUMBER nvarchar(100) declare @SQL nvarchar(max) set @SQL='select vendor.VD_TABLE_KEY_VALUE from [HS_EM_VENDOR_DATA_MAP] as…
0
votes
1 answer

Missing right parenthesis error in EXECUTE IMMEDIATE statement

I have created a package and calling its procedure in a different anonymous block. When I call the procedure, there is missing right parentheses error. I keep getting this error but did not find any missing parenthesis. Package CREATE OR REPLACE…
Vasudha Dixit
  • 377
  • 8
  • 21
0
votes
1 answer

Copy all values from source table to destination table dynamically in SQL Server. If there is some value in destination table then delete and insert

I have created 2 tables and populated the values in my source table. Now, I want to populate these values into the destination table dynamically and also check if there is any value in the destination table then delete all those values and insert…
0
votes
1 answer

Postgres multiple statements excution in block

I am using the below function to drop a table and create it. After I execute the function, the table is not created. Can someone please help me? CREATE OR REPLACE FUNCTION dropAggTables111(tablename TEXT) RETURNS INTEGER AS $total$ DECLARE total…
v bhosale
  • 63
  • 1
  • 1
  • 5
0
votes
1 answer

Getting ERROR while running ALTER statement inside the SQL function

I wrote a SQL function to ALTER the SCHEMA Ownership. I am able to run the statement directly(without function) but getting error while running the ALTER statement within the function. Function "test" created successfully: CREATE OR REPLACE FUNCTION…
Anmol
  • 1
  • 2
0
votes
2 answers

How do I evaluate a cursor loop variable as a table name?

FOR _r IN curs1 LOOP ALTER TABLE QUOTE_IDENT(_r.table_name) ALTER COLUMN company_uuid SET NOT NULL; END LOOP; I am trying to convert the table name to an identifier so I can use it dynamically. The error is: ERROR: syntax error at or near "("
Ben
  • 2,122
  • 2
  • 28
  • 48
0
votes
2 answers

Adding a new column to a table getting the column name from another table

I'm using Microsoft SQL server management studio. I would like to add a new column to a table (altertable1), and name that column using the data from a cell (Date) of another table (stattable1). DECLARE @Data nvarchar(20) SELECT @Data = Date FROM…
0
votes
0 answers

Selecting only the satisfied conditions using dynamic SQL

I need to charge the customer if he matches one pricing system or two or more pricing systems from CONCAT_REL table and then come up with the pricing system. For e.g. Rahul wants an airway mode AND sending a box AND also needs acknowledgement, then…
Cool_Oracle
  • 311
  • 1
  • 4
  • 15
0
votes
0 answers

oracle dbms_sql evaluate expression in where clause

I learned from here that a complete where-clause expression cannot be evaluated using placeholders with native dynamic SQL; placeholders are for passing values. However, it was also mentioned in the comments that it may be possible to do this with…
DSH
  • 1,038
  • 16
  • 27
0
votes
1 answer

Dynamic Query Issue

Variable : path_start_date=14-MAY-21,17-MAY-21,06-APR-12 Query : select greatest(''||REPLACE(''''||&path_start_date||'''',',',''',''')||'') from dual; Expected Output = 17-MAY-21 Can anyone suggest what's wrong with the above query.
0
votes
1 answer

Dynamic PL-SQL programming - Issue with DBMS_SQL.PARSE

I wrote a query to fetch the details using some business logic. However, I got stuck at the below line DBMS_SQL.PARSE(CUR, SQLSTR, DBMS_SQL.NATIVE); And I got the below error. I checked the syntax again and again and it is perfectly fine. So,…
Cool_Oracle
  • 311
  • 1
  • 4
  • 15
0
votes
1 answer

Dynamic PL SQL in where condition for different operands

I have three tables, viz: Mains_Control Control_Mapping Control_Details along with several conditions and columns. But I am performing dynamic operations on the tables columns given below. I am unable to write a dynamic SQL block in PL-SQL…
Cool_Oracle
  • 311
  • 1
  • 4
  • 15
0
votes
2 answers

Partition by range in oracle using sysdate

I want to create partitions dynamicaly that depends on sysdate, like: create table partition_interval_demo ( id number(6) , val varchar2(50) , date_create date) partition by range (sale_date) interval (interval '1' day) ( partition…