SQL & PL/SQL :: How To Execute Sql Statement With Table_name As A Variable

Apr 20, 2012

I have statement like SELECT * FROM DIVISIONS;

i have to run this statement for different table, and I would like to pass the table name as variable

ex:
create or replace precedure dynamic_execute
v_tbl varchar2(30);

begin
---- assign table name here
v_tbl := DIVISIONS;

EXECUTE IMMEDIATE('SELECT * FROM '||v_tbl);
end;
/

When I executed the procedure I got error, how to pass the table name as variable and execute the statement successfully.

View 5 Replies


ADVERTISEMENT

Variable Usage In Type Of Table Declaration Statement And Execute Immediate Statement

Aug 10, 2011

HOW to use variable P_TMPLID in following statement

TYPE typ_unrecon IS TABLE OF REC_' || P_TMPLID ||'_UNRECON%ROWTYPE index by binary_integer;

because its throwing error while compiling

and also in statement
FORALL i IN unrecondata.FIRST .. unrecondata.LAST SAVE
EXCEPTIONS
--STRSQL := '';
--STRSQL := ' INSERT INTO REC_' || P_TMPLID ||'_UNRECON VALUES ' || unrecondata(i);
-- EXECUTE IMMEDIATE STRSQL;
INSERT INTO REC_' || P_TMPLID ||'_UNRECON VALUES unrecondata(i);---throwing error on this statement
commit;
--dbms_output.put_line(unrecondata(2).TRANSID);
EXCEPTION

View 2 Replies View Related

SQL & PL/SQL :: How To Execute Type Variable Procedure

Apr 26, 2013

I have created the following procedure. Since I am using this first time I don't know how to execute this.

CREATE OR REPLACE PACKAGE GAFT_PROG_DIT.ram_package
IS
TYPE type_ots IS TABLE OF ORDER_TREND_SCORE%ROWTYPE INDEX BY PLS_INTEGER;
PROCEDURE InsertTrend( P_TYPE_OTS_REC IN type_ots );
END;
/

[Code]...

View 2 Replies View Related

SQL & PL/SQL :: How To Pass List Of Columns From Variable To Execute Immediate

Feb 24, 2012

I am trying to perform a dml operation(insert) to insert data into a table. I created a procedure in which a insert statement is generated. In another procedure I am trying to execute this auto generated statement using execute immediate. For that I created 2 variables . First one contain the insert statement and other one contain the list of columns. I m passing these strings to execute immediate like this

Execute Immediate(v_query) using(v_col_list)

after execution i m getting the following error

ORA-01008: not all variables bound
ORA-06512": at ' db_name.load_data' , line no 217

but when i tried it with list of column into using clause it is working like

Execute Immediate(v_query) using col1,col2,col3

I have more than 150 tables in the schema and i am creating a single procedure to load the data into base tables by using external tables. By passing the table name to procedure it generates the update and insert statements but i am getting error while executing the statements with dynamic sql.

View 11 Replies View Related

PL/SQL :: Execute Immediate On SELECT Statement

May 3, 2013

Execute Immediate on SELECT Statement

declare l_stmt VARCHAR2(1000);
begin
l_stmt := 'Select * from mytable' ;
EXECUTE IMMEDIATE l_stmt;
--- dbms_output.put_line( l_stmt);
end;

it is not returning any output. I have hardcoded the table name here where as in real time Mytable name will differ.

View 14 Replies View Related

SQL & PL/SQL :: Execute The Expression In Select Statement

Feb 12, 2013

CREATE TABLE TEST1
(
OFFICE_PRODUCTS NUMBER,
OFFICE_ELECTRONICS NUMBER
)
Insert into TEST1 (OFFICE_PRODUCTS, OFFICE_ELECTRONICS) Values(1, 0);
COMMIT;

CREATE TABLE TEST2
(
EXPORT_FIELD_NAME VARCHAR2(100 BYTE),
EXPORT_COLUMN_EXPRESSION VARCHAR2(100 BYTE)
)
Insert into TEST2
(EXPORT_FIELD_NAME, EXPORT_COLUMN_EXPRESSION)
Values ('A1', 'least(OFFICE_PRODUCTS, OFFICE_ELECTRONICS)');
COMMIT;

I want to be execute the expression should run in select statement how to do? and tried as like below,it's not working.

select (select EXPORT_COLUMN_EXPRESSION from test2 where EXPORT_FIELD_NAME='A1') FROM TEST1;

View 15 Replies View Related

Forms :: Windows Won't Allow To Execute SQL Statement

Oct 25, 2011

reconciliation logic using Oracle

Version

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

Current written logic for reconciliation:

1. Load data from source_a in a staging table using date filter

2. Load data from a file (Source_B) in temp table

3. Algo for reconciliation:

fetch value from source_B and if an entry exists in source_a then match say 10 columns if they match update reconciliation_oke = TRUE

there is an and written for testing all the 10 columns There is report generated out this which shows non matched columns and the entries which are missing....Now the requirement is to modify the logic in a way which shows which all columns are mismatched on the report in case present.

Since there are around 10 thousand records which would be reconciled on a daily basis, performance also needs to be taken care of...I guess i would be required to use PL/SQl tables...

View 3 Replies View Related

PL/SQL :: ORA-00900 Invalid SQL Statement When Doing Execute Immediate Using

Jun 21, 2012

I'm writing simple code db is 9.2.0.8

create or replace procedure gather_part_stats(p_schema in varchar2, p_table in varchar2)
as
l_quarter varchar2(8) := to_char(sysdate, '"Y"YYYY"_Q"q') ;
l_sql varchar2(2000) := 'exec dbms_stats.gather_table_stats(:schema, :table, method_opt => ''for all columns size 1'' , cascade => true , estimate_percent => 1 , granularity => ''PARTITION'', partname=>:part);';
[code].......

I'm using using to avoid sql injection,

Error is:
SQL> exec gather_part_stats('TEST' , 'TEST');
l_quarter: Y2012_Q2
exec dbms_stats.gather_table_stats(:schema, :table, method_opt => 'for all columns size 1' , cascade => true , estimate_percent => 1 , granularity => 'PARTITION', partname=>:part);
BEGIN gather_part_stats('TEST' , 'TEST'); END;
*
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at "INSTALL.GATHER_PART_STATS", line 8
ORA-06512: at line 1

View 12 Replies View Related

PL/SQL :: Create Sequence Using EXECUTE IMMEDIATE Statement?

Dec 14, 2012

Is it possible to create sequence using EXECUTE IMMEDIATE statement. The sequence name will be the bind variable.

DECLARE
TEMP   VARCHAR2(20);
BEGIN
TEMP     := :P2_INFO;
EXECUTE IMMEDIATE 'CREATE SEQUENCE' TEMP;
END;

This creates a sequence named TEMP, but i want the name :P2_INFO entered by user.

View 10 Replies View Related

PL/SQL :: Finding Table_name Or Column_name

Jan 15, 2013

I have inserted through frontend which is ORACLE ADF and if i want to see those inserted data's in a table then how to check it when i dont know the table names and if there are large number of tables available.. Its I need a solution in this way as i know the values of fields so by giving values alone I want to fetch the table and column names as wherever this values are present...I am already aware about user_tab_columns and user_tables or all_tables .. So i want to try through fetching of tables or column names though values or data's as reference ...

View 21 Replies View Related

SQL & PL/SQL :: How To Execute The Statement Exist In CLOB Column

Jun 30, 2010

I have oracle table with a column of datatype CLOB. In the clob column having the manipulation statements (update, insert) as records.

How to execute the statements exists in a clob column as records?

my table structure and one record is

CREATE TABLE ACTN_CFG_T
(
OBJ_ID NUMBER(32) NOT NULL,
ACTN_ID NUMBER(38) NOT NULL,
ACTN_SEQ NUMBER(2) NOT NULL,
RU_DEF CLOB NOT NULL

[code]....

I want to execute the update statement when i call the obj_id. I used the follwing procedure but error.

1 DECLARE
2 V_ABC CLOB;
3 BEGIN
4 SELECT RU_DEF INTO V_ABC FROM ACTN_CFG_T WHERE OBJ_ID = 1625;
5 EXECUTE IMMEDIATE V_ABC;
6 END;

error is...

ORA-06550: line 5, column 20:
PLS-00382: expression is of wrong type
ORA-06550: line 5, column 2:
PL/SQL: Statement ignored

View 10 Replies View Related

SQL & PL/SQL :: Variable In Select Statement

Jul 5, 2011

I'm trying to write a simple query so I can do some testing on my application. I am trying to do something like this:

SELECT
Location,
LEVEL,

FROM
S_ORG_EXT

where
Location = 'North America' and LEVEL ='Software'
OR location = 'North America'
and Active = 'N'

in the where statement, I have put in the 'Active' that isn't a column. I want to be able to be able to change that in the select part. But I am not able to do so.

this is what I have tried:
SELECT
Location,
LEVEL,
Active = 'N' --I want to change this in the to N or Y so I can get different results.

FROM
S_ORG_EXT

where
Location = 'North America' and LEVEL ='Software'
OR location = 'North America'
and Active = 'N'

View 7 Replies View Related

SQL & PL/SQL :: Date Variable / IF Statement?

May 26, 2010

am new to oracle based coding and am having a heck of a time trying to figure this out. Basically i need to declare 2 date variables, Begin date and End Date.

I then need an if statement that says if begin date = 0 or is null then set it to the first day of the previous month. and if end date = 0 or is null then set it to the last day of the previous month.

So for today 5/26/2010 i would need

begin date = 4/1/2010
end date = 4/30/2010

I have searched and tried but so far to no avail.

View 10 Replies View Related

SQL & PL/SQL :: Oracle Error For Invalid Identifier In Execute Immediate Statement

Apr 5, 2011

I have a procedure as below. To sum up the procedure in one line it dynamically forms a string to get the values of the type which is passed as an input to the procedure.

I call the procedure as

exec exec_imm( exec_imm_t(1,'asd','1/2-34'));

ERROR:
Error starting at line 9 in command:
exec exec_imm( exec_imm_t(1,'asd','1/2-34'))
Error report:
ORA-00904: "P_TYPE_DATA"."ADDRESS": invalid identifier
ORA-06512: at "PTK_ADM.EXEC_IMM", line 26
ORA-06512: at line 1
00904. 00000 - "%s: invalid identifier"

NOTE:
When I try to execute the procedure with the execute immediate statement I get the above error. But when I execute the select statement which is nothing but the value in v_type_data directly (as seen in the comments in the code below) there is no error. But when the same v_type_data is used in execute immediate, I get an error.

CREATE OR REPLACE procedure exec_imm(p_type_data exec_imm_t)
AS
v_type_str CLOB := NULL;
v_type_data CLOB := NULL;
v_type_name VARCHAR2(25) := NULL;
BEGIN
[code]......

View 6 Replies View Related

Using Declared Variable Within Select Statement?

Apr 5, 2011

here is what i am trying to do: im as using oracle 8 with sqltool

i have a Very large query. and i notice that many things are repeating. so i want to add them to a variable, instead of re-typing them. for example:

select SomeID from SomeTable;

i want SomeID to be put into a variable. but i still want to be able to get a normal select query at the end so that i can see the returned value:

i tried things like:
declare x number;
begin
set x=45454
select x from SomeTable;
end;

but could not get it to work.

View 2 Replies View Related

SQL & PL/SQL :: Used Variable In Open Cursor Statement

Mar 1, 2012

open cp_cursor for 'Select curtailprogramkey from curtailProgram where curtailprogramid like 'l_rec.curtailprogramid%'';

NOTE: l_rec.curtailprogramid is varible. what is wrong in the above statement?

View 2 Replies View Related

TimesTen In-Memory :: Execute Statement SELECT CURRENT_DATE FROM DUAL On 11.2.2?

Sep 24, 2013

We are trying to execute a statement SELECT CURRENT_DATE FROM DUAL on Timesten 11.2.2  . It throws error unknown referenced column error. Command> select current_date from dual; 2211:

Referenced column CURRENT_DATE not foundThe command failed. But the following doc shows the support. 

TimesTen PL/SQL Support: Reference Summary CURRENT_DATE function

Returns the current date in the session time zone. YIn TimesTen this returns the current date in UTC (universal time). TimesTen does not support local time zones.

View 4 Replies View Related

SQL & PL/SQL :: Convert Update Query To Dynamic To Be Executed From Execute Immediate Statement

Oct 25, 2010

I want to convert the below SQL to a dynamic sql to be executed from execute immediate statement.

UPDATE transaction SET loannum = lpad(loannum,12,'0')

View 15 Replies View Related

PL/SQL :: DML Query Execution - Length Exceeds 4000 Characters With Execute Immediate Statement

Jun 18, 2013

I want to execute a DML query with execute immediate statement. That DML query length exceeds 4000 characters. This query has Xquery related conditions, i can not split the query. when i tried execute it is giving "string literal too long".  I tried with DBMS_SQL.Parse() and DBMS_SQL.Execute also, but it is giving same error. I have to execute this DML query inside a Procedure. We are using oracle 10g version

View 13 Replies View Related

SQL & PL/SQL :: Display Boolean Value Of A Variable In DBMS Print Statement?

May 29, 2012

I want to display Boolean value of a variable in DBMS Print statement. I am able to do it by using simple if condition checking .How to print the value of Boolean variable directly ?

SQL> declare
2 boo boolean := true;
3 begin
4
5 if boo then
6 dbms_output.put_line('boolean variable value TRUE by checking if condition ');

[code]....

ORA-06550: line 9, column 24:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 9, column 3:
PL/SQL: Statement ignored

View 6 Replies View Related

Forms :: Dynamic Variable In Place Of Username In Each Select Statement Throughout Application

Jul 25, 2010

I have a problem that i have hard coded the username.tablename in each select statement of all forms of my application. Now i want to use a dynamic variable in place of username in each select statement throughout the application. The example is:

select * from scott.emp
and i want to write it as:
select * from variable.emp

But at compilation of the form the compiler should know the above variable name.

I have tried to use following select statement but it does not work.

select user into :global.username from user_users

I think perhaps my problem would be solved with Dynamic SQL Statement but i have no experience by using this statement.

View 4 Replies View Related

Security :: Difference Between Grant All On Any Table And Grant All On Table_name

Oct 31, 2012

I would like to know what happens when we fire:

grant all on any table to user_name;

and

grant all on table_name to user_name;

Actually I was performing "grant all on table_name to user_name;" to grant the privilege but 1 of my friends suggested "grant all on any table to user_name;"

View 5 Replies View Related

SQL & PL/SQL :: Using Dbms_sql.execute To Build / Execute Dynamic Sql?

Oct 23, 2013

I'm working with old code that uses dbms_sql.execute to build/execute dynamic sql. In our case, the user can select varying columns(I think up to 20) with different where conditions as needed.

After building the sql, here's an example

WITH ph AS
(SELECT ph.* FROM po_header ph WHERE 1 = 2),
pf AS
(SELECT DISTINCT pf.order_id, pf.fund
FROM po_fau pf, ph
WHERE 1 = 1
AND ph.order_id = pf.order_id

[code]....

Where table records for

po_header = ~567746
po_fau = ~2153570

and PK "order_id" is a NUMBER(10) not null and a snippet of the code looks like

nDDL_Cursor := dbms_sql.open_cursor;
dbms_sql.parse(nDDL_Cursor, sSQLStr, 2);
FOR x IN 1 .. nCols LOOP
sCols(x) := '';
dbms_sql.define_column(nDDL_Cursor, x, sCols(x), 100);
END LOOP;
nError := dbms_sql.execute(nDDL_cursor);

why when the "execute" statement is fired off the elapsed time takes ~4.5 seconds but If I change "1 = 1" above to "1 = 2" it takes ~.2 seconds. If I run the above query interactively it takes ~.2 seconds. Shouldn't the above query when joining

ph.order_id = pf.order_id

return zero rows back instantly or does the "dbms_sql_execute" do some other type of parsing internally that takes cpu time.

View 14 Replies View Related

Execute Dynamic SQL Using Both Execute Immediate And Ref Cursor

Jan 8, 2009

We can execute dynamic sql using both execute immediate and ref cursor..But what is the difference between the two and performance-wise which is better?

View 5 Replies View Related

SQL & PL/SQL :: Select Statement From Schemas In MERGE Statement In USING Clause

Sep 13, 2013

In the following merge statement in the USINg clause...I am using a select stament of one schema WEDB.But that same select statement should take data from 30 schemeas and then check the condition below condition

ON(source.DNO = target.DNO
AND source.BNO=target.BNO);

I thought that using UNIONALL for select statement of the schemas as below.

SELECT
DNO,
BNO,
c2,
c3,
c4,
c5,
c6,
c7
[code]....

View 5 Replies View Related

SQL & PL/SQL :: Select Statement Is Blocking A Delete Statement

Jan 11, 2012

I am using JDBC to run a few queries from my Java program (multi-threaded one).I am facing an issue where a select statement is blocking a delete statement. From the java code point of view, there are 2 different threads accessing the same tables (whith different DB connection objects).

When the block occurs (which i was able to find out from the java thread dump that there is a lock on oracle), the below is the output:

SQL> SELECT TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS')
2 || ' User '||s1.username || '@' || s1.machine
3 || ' ( SID= ' || s1.sid || ' ) with the statement: ' || sqlt2.sql_text
||' is blocking the SQL statement on '|| s2.username || '@'
4 5 || s2.machine || ' ( SID=' || s2.sid || ' ) blocked SQL -> '
6 ||sqlt1.sql_text AS blocking_status FROM v$lock l1, v$session s1, v$lock l2 ,
7 v$session s2,v$sql sqlt1, v$sql sqlt2
8 WHERE s1.sid =l1.sid
9 AND s2.sid =l2.sid AND sqlt1.sql_id= s2.sql_id
AND sqlt2.sql_id= s1.prev_sql_id AND l1.BLOCK =1
10 AND l2.request > 0 AND l1.id1 = l2.id1 AND l2.id2 = l2.id2;
[code]...

From the above it can be seen that a select statement is blocking a delete. Unless the select is select for Update, it should not block other statements is not it ?

View 10 Replies View Related

SQL & PL/SQL :: Insert Into Statement Doesn't Insert All Rows Return By Select Statement?

Jan 12, 2011

If i inserted the values in table it gets inserting very few rows only.I dont know y it is?

View 15 Replies View Related

Execute Immediate In Trigger

Apr 17, 2013

I am trying to use execute immediate in a trigger. See the below example

create table test_tbl(col1 number,col2 varchar2(10), col3 date);
create table test_tbl_log as select * from test_tbl where 1 = 2;

create or replace trigger test_trig
after insert or update or delete on test_tbl
for each row
declare
v_str varchar2(4000);
[code].......

insert into test_tbl values(3,'test',sysdate);

I got the Error : -1008->ORA-01008: not all variables bound

In the execute immediate statement if I change the v_using_str variable to :new.col1,:new.col2,:new.col3 trigger is running fine. But here I have to create trigger on all the tables in my schema and I dont want to list all the column names for each table manually and I am using a for loop to build the v_using_str string in my original code.

View 2 Replies View Related

Execute Sql File From Pl / Sql?

Aug 18, 2010

Need to execute @/sql file after checking an output of below sql.

SELECT COUNT(*) FROM all_directories WHERE DIRECTORY_NAME='RMANDUMP';

If directory exist then oonly we require to run sql file.

If there a way we can execute sql files depending on sql output.

View 4 Replies View Related

SQL & PL/SQL :: Execute Immediate With DBLink

Feb 23, 2011

I need to write several variations of this statement below to query a remote database, but am having trouble with the syntax.

execute immediate 'select count(*) from ' || v_tablename || '@dblink ' || into v_rowcount;
PLS-00103: Encountered the symbol "INTO"....

What's the correct way to format this kind of dynamic query?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved