1

Dynamic sql in Oracle

 2 years ago
source link: https://www.codesd.com/item/dynamic-sql-in-oracle.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Dynamic sql in Oracle

advertisements

How can i create dynamic sql in oracle according to if else statements.For example;

sql:= 'select n from where a = p_a';
if p_b is not null then
sql:= 'select n from where a = p_a and b = p_b';


Why would you want dynamic SQL when you can just do the following?

select n
from xx
where a = p_a and (b = p_b or p_b is null);

Related Articles

How to create a record type using dynamic sql in oracle?

I have a table named a with column x. create table A (x varchar2(4000)); insert into A values ('select p,q,r from o'); commit; Now I want to create a record type dynamically on the basis of above sql i.e. TYPE rc IS RECORD ( p o.p%type, q o.q%type, r

How to return a result set / cursor from an Oracle PL / SQL anonymous block that is running dynamic SQL?

I have this table: ALLITEMS --------------- ItemId | Areas --------------- 1 | EAST 2 | EAST 3 | SOUTH 4 | WEST The DDL: drop table allitems; Create Table Allitems(ItemId Int,areas Varchar2(20)); Insert Into Allitems(Itemid,Areas) Values(1,'east'); I

oracle plsql select pivot without dynamic SQL to group by

To whom it may respond to, We would like to use SELECT function with PIVOT option at a 11g r2 Oracle DBMS. Our query is like : select * from (SELECT o.ship_to_customer_no, ol.item_no,ol.amount FROM t_order o, t_order_line ol WHERE o.NO = ol.order_no

Oracle 8i dynamic SQL error on sub-selections in pl / sql blocks

I wrote an Oracle function (for 8i) to fetch rows affected by a DML statement, emulating the behavior of RETURNING * from PostgreSQL. A typical function call looks like: SELECT tablename_dml('UPDATE tablename SET foo = ''bar''') FROM dual; The functi

how to compile (*) the value in the local temporary variable in dynamic sql (ORACLE PLSQL)

I want to get count(*) value in dynamic plsql statement. We can write static stmt as: select count(*) into tmp_cnt from table_info where nbr_entry='0123456789'; but how to get tmp_cnt value while writing the dynamic sql stament? or any other way to g

Oracle Spool using dynamic SQL

I'm trying to pass a dynamic SQL statement to spool out to a text file using SQL*Plus, but I can't seem to execute the select statement I'm generating. set linesize 10000 pagesize 0 embedded on set heading off feedback off verify off trimspool on tri

Native dynamic SQL test in Oracle before execution

I have implemented a certain feature in my application where the user can compose queries dynamically from the user interface by pushing around buttons and inserting some values here and there. The user will not see the generated SQL statement at all

How to extract dynamic SQL output in Perl DBI?

I have a dynamic SQL SELECT statement generated using a PL/SQL code. declare sql_query clob; begin sql_query := 'select * from ...........'; execute immediate sql_query; end; I want to retrieve the output of the above dynamically generated SELECT sta

Why can not we use the ref cursor with the dynamic SQL statement?

I am trying to use a strong ref cur with dynamic sql statment but it is giving out an error,but when i use weak cursor it works,Please explain what is the reason and please forward me any link of oracle server architect containing matter about how co

Is it possible to create external tables dynamically in PLSQL / Oracle?

Am currently having a bit of trouble and am trying to dynamically pull values out of CSV files and dynamically create the external tables as each CSV file is going to have a different number of headers each time. Is there any way to dynamically to do

What is the workaround for using dynamic SQL in a stored procedure

The Stored Procedure DELIMITER $$ CREATE PROCEDURE `lms`.`leads_to_bak` () BEGIN SET @table1 = (SELECT `tabler_name` FROM `sets` WHERE `on_off`=0 LIMIT 1); SET @table2 = CONCAT(@table1, '_bak'); SET @SQL1 = CONCAT('INSERT INTO ',@table2, '(', (SELECT

Avoid SQL injection when using dynamic SQL

I am working on an security remediation of an existing java web application. The application has some dynamic sql code executed by JDBC.But, this is not accepted by Static Code analysis tool we use. So, I am looking for a way to remediate the issue.B

Dynamic SQL - Check syntax and semantics

With Oracle dynamic SQL one is able to execute a string containing a SQL statement. e.g. l_stmt := 'select count(*) from tab1'; execute immediate l_stmt; Is it possible to not execute l_stmt but check that the syntax and semantics is correct programm

Can I run a dynamic sql statement in a trigger after the update?

I am using the following statement: query_str='SELECT :NEW.FIRST_NAME||:NEW.LAST_NAME INTO HostID FROM INPUT_TABLE WHERE INPUT_ID=' The trigger has the following code: EXECUTE IMMEDIATE query_str ||:NEW.INPUT_ID; I'm getting the following error when

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK