Error (19,19): PLS-00049: bad bind variable 'P_WHERE '.
Hello worldMaking my first attempt to bind variables. What I've read it really improves performance.
The code below works fine until I try to do TEST1_PROC. P_WHERE a bind variable with the ':' prefixed, such as: P_WHERE.
Suggestions?
Thanks in advance for your help,
Lou
create or replace
PROCEDURE TEST2_PROC
AS
my_refcur SYS_REFCURSOR;
my_id ci_summrpt_report_codes.id% TYPE;
my_descr ci_summrpt_report_codes.descr% TYPE;
my_where VARCHAR2 (10): = '1.4'.
BEGIN
TEST1_PROC (my_refcur, my_where);
DBMS_OUTPUT. PUT_LINE ('ID DESCR');
DBMS_OUTPUT. PUT_LINE ('-');
LOOP
EXTRACTION INTO my_id, my_descr my_refcur;
OUTPUT
WHEN my_refcur % NOTFOUND;
DBMS_OUTPUT. Put_line(my_id ||) CHR (9) | my_descr);
END LOOP;
CLOSE My_refcur;
END TEST2_PROC;
CREATE OR REPLACE
PROCEDURE TEST1_PROC
(
p_refcur ON SYS_REFCURSOR,
p_where IN VARCHAR2)
IS
v_id NUMBER (2);
v_descr VARCHAR2 (25);
v_select VARCHAR2 (200);
BEGIN
v_select: ='SELECT * FROM
(SELECT 1 AS 'ID', 'ONE' AS 'DESCR' OF THE DOUBLE
UNION ALL
SELECT 2, 'TWO' OF THE DOUBLE
UNION ALL
SELECT 3, "THREE" DOUBLE
UNION ALL
SELECT OPTION 4, "FOUR" DOUBLE)
WHERE ID IN (' |: p_where |) ')';
DBMS_OUTPUT. Put_line (v_select);
P_refcur OPEN FOR v_select;
END TEST1_PROC;
You do not specify bind variables by a colon ': ' prefix in PL/SQL.
The stored procedure generates a query using the string concatenation. If you remove your name from the variable of the colon you still don't use bind variables.
If you want to use bind variables you should consider the following:
1. use the DBMS_SQL package.
Each has different advantages/disadvantages. If looks as if you want to pass in a dynamic list. If you are using bind variables, it will effectively address the entire list as a value surrounded by single quotes. If you really want a dynamic IN the list, you need to investigate another method. Tom Kyte contains information about the lists into dynamic here: [how to make a variable in the list? | http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:210612357425]
2. use EXECUTE IMMEDIATE with the USING clause.
3. use OPEN TO
Tags: Database
Similar Questions
-
PLS-00049: bad bind variable in the database trigger
Hi all
If the POSTAL code table has no matching records, the trigger must create a new record for the given value of the zipper before you add a new record to the STUDENT table
SQL > CREATE TABLE student
(
zip VARCHAR2 (5).
student_id NUMBER,
created_by VARCHAR2 (10),
CREATED_DATE DATE,
Modified_By VARCHAR2 (10),
MODIFIED_DATE DATE
);
SQL > CREATE TABLE zip code
(
zip VARCHAR2 (5).
zip_ID NUMBER,
created_by VARCHAR2 (10),
CREATED_DATE DATE,
Modified_By VARCHAR2 (10),
MODIFIED_DATE DATE
);
SQL > CREATE VIEW student_v
AS
SELECT *.
OF the student;
Created view.
SQL > CREATE OR replace TRIGGER student_ins
instead of INSERT ON student_v
FOR EACH LINE
DECLARE
v_zip VARCHAR2 (5);
BEGIN
BEGIN
SELECT zip
IN v_zip
ZIP CODE
WHERE zip =: NEW.zip;
EXCEPTION
WHEN no_data_found THEN
INSERT INTO postal code
(zip,
zip_ID,
created_by,
CREATED_DATE,
Modified_By,
MODIFIED_DATE)
VALUES (: NEW.zip,)
: NEW.zip_id-> not commented
USER,
SYSDATE,
USER,
SYSDATE);
END;
INSERT INTO student
(zip,
student_id,
created_by,
CREATED_DATE,
Modified_By,
MODIFIED_DATE)
VALUES (: NEW.zip,)
: NEW.student_id,.
USER,
SYSDATE,
USER,
SYSDATE);
end;
Decline: Trigger created with compilation errors.
SQL > show error
Errors for STUDENT_INS TRIGGER:
LINE/COL ERROR
-------- -------------------------------------------
19/21 PLS-00049: bad connection variable ' NEW. ZIP_ID'
SQL > ed
CREATE or replace TRIGGER student_ins
instead of INSERT ON student_v
FOR EACH LINE
DECLARE
v_zip VARCHAR2 (5);
BEGIN
BEGIN
SELECT zip
IN v_zip
ZIP CODE
WHERE zip =: NEW.zip;
EXCEPTION
WHEN no_data_found THEN
INSERT INTO postal code
(zip,
zip_ID,
created_by,
CREATED_DATE,
Modified_By,
MODIFIED_DATE)
VALUES (: NEW.zip,)
-: NEW.zip_id, -> replace commented with NULL
NULL,
USER,
SYSDATE,
USER,
SYSDATE);
END;
INSERT INTO student
(zip,
student_id,
created_by,
CREATED_DATE,
Modified_By,
MODIFIED_DATE)
VALUES (: NEW.zip,)
: NEW.student_id,.
USER,
SYSDATE,
USER,
SYSDATE);
end;
SQL > /.
SQL > insert into student_v (zip) values('111');
1 line of creation.
SQL > select * from student_v
2.
ZIP STUDENT_ID CREATED_BY CREATED_D MODIFIED_B MODIFIED_
----- ---------- ---------- --------- ---------- ---------
111 APPS APPS APRIL 3, 14 3 APRIL 14
SQL > select * from student
2.
ZIP STUDENT_ID CREATED_BY CREATED_D MODIFIED_B MODIFIED_
----- ---------- ---------- --------- ---------- ---------
111 APPS APPS APRIL 3, 14 3 APRIL 14
SQL > select * from zip code
2.
ZIP ZIP_ID CREATED_D MODIFIED_B MODIFIED_ CREATED_BY
----- ---------- ---------- --------- ---------- ---------
111 APPS APPS APRIL 3, 14 3 APRIL 14
You wrote trigger on the table of the student. So in the trigger, only the columns of this table must be offered for example: NEW.zip.
Since zip_id is not part of this table, the: NEW.zip_id must always generate the error.
insert into student_v (zip) values('111');
In the above statement, you can only provide the value for the column zip but not zip_id. Therefore, the: NEW.zip_id is not available in the trigger. Must extract this value in the sequence after it is created.
for example
create the test of the order;
INSERT INTO postal code
(zip,
zip_ID,
created_by,
CREATED_DATE,
Modified_By,
MODIFIED_DATE)
VALUES (: NEW.zip,)
test.nextval,
NULL,
USER,
SYSDATE,
USER,
SYSDATE);
-
PLS-00049: bad bind variable 'NEW.col1' (col1 exists in the table)
I use Oracle 12 c. And a bad bind variable error in this statement.
create or replace
check_tax_number relaxation
INSERT BEFORE THE "C ##MYUSER". "customer" FOR EACH ROW
BEGIN
'0' IF new.taxpayer <>THEN
: new.taxnumber: = "123456789"; -error here...
END IF;
END;
I don't know which exists taxnumber customer in the table column.
Here's desc 'C ##MYUSER '. "" customer ".
Name of Type Null
--------------------------- -------- -------------
taxpayer NOT NULL NUMBER (1)
taxnumber NOT NULL NVARCHAR2 (10)
Other passes...
Thanks for help.
Based on the declaration of the customer table you posted columns are created in lowercase. Therefore, you must use the names of column between quotation marks:
create or replace
check_tax_number relaxation
INSERT BEFORE THE "C ##MYUSER". "customer" FOR EACH ROW
BEGIN
IF : new. " taxpayer""" <> '0' THEN
: new. " " "taxnumber""": = "123456789"; -error here...
END IF;
END;
SY.
-
INSTEAD, error PLS-00049: bad connection variable
I try to use a PLACE for me to enter data in a table of bridge. Thanks in advance
I get the following error:
Error on line 4: PLS 00049: bad connection variable ' NEW. MEMBER_ID'
2 INSTEAD OF THE INSERT OR UPDATE OR DELETE
3 ON VI_Member_Talent_VW making REFERENCE AGAIN AS NINE OLD and OLD
4. FOR EACH LINE
5. START TO
6. IF THE INSERTION
Here is the code:
CREATE OR REPLACE TRIGGER VI_INSERT_UPDATE_MT
INSTEAD OF INSERT OR UPDATE OR DELETE
ON VI_Member_Talent_VW REFERENCING NEW AS NEW as OLD OLD
FOR EACH LINE
BEGIN
IF THE INSERTION
THEN
INSERT INTO VI_Member_Talent (Member_ID, Talent_ID) VALUES (: NEW.) Member_ID,: NEW. Talent_ID);
END IF;
IF THE UPDATE
THEN
UPDATE VI_Member_Talent SET Member_ID =: NEW. Member_ID, Talent_ID =: NEW. Talent_ID
WHERE ROWID =: OLD.ID;
END IF;
IF THE REMOVAL
THEN
DELETE FROM VI_Member_Talent WHERE ROWID =: OLD.ID;
END IF;
END;
Edited by: user13003575 may 2, 2010 08:53user13003575 wrote:
It's the viewCREATE OR REPLACE FORCE VIEW "VI_MEMBER_TALENT_VW" ("ID", "Member_ID", "Talent_ID") AS SELECT rowid id, Member_ID, Talent_ID FROM VI_Member_Talent /
and there is the problem.
The view was created with quotes around column names, so that they are case-sensitive. You need to either modify your trigger double quote column names, or rebuild the view without the quotes. Personally, I'd go with changing the display.
John
-
TRIGGER ERROR: bad bind variable
Hello
I just start with oracle and I try to do the same thing as auto_increment in mysql by creating this sequence and the trigger but the trigger, I get the following error:
error:
-----
This is the code for the relaxation, table and sequence:PLS-00049: bad bind variable 'TAKEOVER_USERS.TAKEOVER_UID'
triggering factor:
---------
Table:CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1" BEFORE insert on "TAKEOVER_USERS" for each row begin select TAKEOVER_UID.nextval into :takeover_users.TAKEOVER_UID from dual; end;
------
sequence:CREATE TABLE "TAKEOVER_USERS" ( "TAKEOVER_UID" NUMBER NOT NULL ENABLE, "TAKEOVER_FBID" VARCHAR2(20) NOT NULL ENABLE, "takeover_accepted_terms" NUMBER(1,1) NOT NULL ENABLE, "takeover_lastName" VARCHAR2(30), "takeover_firstName" VARCHAR2(30), "takeover_country" VARCHAR2(40), "takeover_session" VARCHAR2(50) NOT NULL ENABLE, "takeover_created" TIMESTAMP (6) NOT NULL ENABLE, CONSTRAINT "takeover_users_PK" PRIMARY KEY ("TAKEOVER_UID") ENABLE )
-----------
Any idea what I need to change to make it work?CREATE SEQUENCE "TAKEOVER_UID" MINVALUE 1 MAXVALUE 99999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
Thank you!
ChristineIf your DB is 11g, you can try this
CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1" BEFORE insert on "TAKEOVER_USERS" for each row begin :NEW.TAKEOVER_UID:=TAKEOVER_UID.nextval; end;
If 10g or more...
CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1" BEFORE insert on "TAKEOVER_USERS" for each ROW BEGIN SELECT TAKEOVER_UID.NEXTVAL INTO :NEW.TAKEOVER_UID FROM dual; end;
Kind regards
Prazy -
form of bad bind variable error in oracle 10g
I have a created a table in oracle database 10g
create table myimage (image_id number, nom_image BLOB);
I want to insert an image and recover an image through programming (don't want to block level) in oracle 10 g shape
without using java Bean (and finely working in the two windows XP2 and Solaries)
How can I do this please can someone give me the source code to do it because I am new in oracle forms.
I need an immediate replay to this answer why because I urgently need it in my project web ERPYou can use for WEBUTIL do, but
without using java Bean (and finely working in the two windows XP2 and Solaries)
WEBUTIL also contains javabean. I don't know why you have this restriction, I would say that you do not succeed without any java bean.
-
Bad connection variable? I'm doing a host variable.
Okay, so I said a global variable:
VARIABLE g_total NUMBER
and I want to use this variable to store the results of a stored procedure (I reduced my code to focus on the problem area):
CREATE OR REPLACE PROCEDURE my_procedure
(p_price IN m_movies.price%TYPE
p_quantity IN m_cart.quantity%TYPE)
IS
BEGIN
: g_total: = p_price * p_quantity;
DBMS_OUTPUT. Put_line ("the order total is: ' |: g_total");
END;
/
After all this, I get an error "bad bind variable g_total ' for the two lines I use it inside the procedure. What the heck is a variable binding? I use a host variable. (I think). If this has nothing to do with the fact that I can only give a very generic NUMBER data type to the host variable? Help, please!It's not the way it will work. You cannot create choice with lie (as you saw).
You had rather code like this:SQL> VARIABLE g_total NUMBER SQL> create or replace procedure my_procedure (p_price in number, p_quantity in integer, g_total out number) is begin g_total := p_price * p_quantity; end my_procedure; / Procedure created. SQL> exec my_procedure(50,3, :g_total) PL/SQL procedure successfully completed. SQL> print g_total g_total ---------- 150
-
SQL * more substitution vs bind variable question
Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...
example:
create table blah as
Select * from table
WHERE DATE between start_date and END_DAY;
the DATE is a numeric field, YYYYMMDD
The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.
The END_DAY is * always * last Friday and I realized that:
variable L_FRIDAY char (15);
Start
Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;
end;
/
The thing is that I get an error when I try to use the binding variable?
create table blah as
Select * from table
WHERE DATE between start_date and: L_FRIDAY;
Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...
When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?
Help!
:-)
Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables
I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.
Hello
Kodiak_Seattle wrote:
Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...
example:
create table blah as
Select * from table
WHERE DATE between start_date and END_DAY;
the DATE is a numeric field, YYYYMMDD
The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.
The END_DAY is * always * last Friday and I realized that:
variable L_FRIDAY char (15);
Start
Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;
end;
/
The thing is that I get an error when I try to use the binding variable?
create table blah as
Select * from table
WHERE DATE between start_date and: L_FRIDAY;
Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...
When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?
Help!
:-)
Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables
I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.
Or SQL * more bind variable or variable substitution can be DATEs. The best you can do is set a different type, as a string, representing a date. A string as June 19, 2015"represents a date, but so strings like 'SYSDATE' and ' SYSDATE - 7', so you can do something like this:
SET l_friday = ' NEXT_DAY ((SYSDATE-7), 'FRIDAY').
DEFINE start_date = "ADD_MONTHS (& l_friday, - 12)"
SELECT & start_date AS t_n
, & l_friday AS l_f
OF the double
;
Output (when executed on 25 June 2015):
L_F T_N
----------- -----------
June 19, 2014 19 June 2015
-
Appeal procedure on page and PLS-00049 stored error?
Hello guys!
I am facing many problems this morning! First of all, that I need to deal with is this.
I created the process page (see below: 1 code) in order to validate if all records where LNG_GEBIET is to have the status of 3 or 4. If this is the case I want to call the procedure 'set_status_arbeit_zu_gebiet '. If amountrs and countstat do not match, then nothing is meant to do.
The problem lies in the stored procedure itself. I have an error PLS-00049 bind variable for: new. LNG_GEBIET.
Can you please tell me what I forgot to declare in the code 2 below?
Thank you guys!
The process of the page:
Code 2 with the real problem!Declare amountrs number; countstat number; begin SELECT COUNT(*) INTO amountrs FROM TBL_PUNKTDATEN where LNG_GEBIET = :P4_CNT_GEBIET; SELECT COUNT(*) INTO countstat FROM TBL_PUNKTDATEN where LNG_GEBIET = :P4_CNT_GEBIET and INT_STATUS = 3 or LNG_GEBIET = :P4_CNT_GEBIET and INT_STATUS = 4; IF amountrs = countstat THEN set_status_arbeit_zu_gebiet; ELSE dbms_output.put('nothing'); END IF ; end;
Another question: is it possible to integrate the first validation that calls my stored procedure in code 2?CREATE OR REPLACE PROCEDURE set_status_arbeit_zu_gebiet IS cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET; v_c2 c2%ROWTYPE; BEGIN open c2; fetch c2 into v_c2; if c2%notfound then INSERT INTO TBL_ARBEIT_ZU_GEBIET ( LNG_GEBIET, LNG_ARBEITSSCHRITT, PNUM, INT_BEARBEITER, DATE_DATUM, GEPL_DATUM ) VALUES (:new.LNG_GEBIET, 52, 1114, 895, sysdate, to_date('01.01.1990', 'DD.MM.YYYY') ); commit; close c2; END set_status_arbeit_zu_gebiet;
Thanks for your time!
SebastianThe error is in training subsequently:
INSERT INTO TBL_ARBEIT_ZU_GEBIET (...) VALUES (: new.) LNG_GEBIET,...) ;
As the statement is part of a procedure and no trigger is not able to bind to this variable with any value.
As a resolution, pass this value to the procedure of the process and use it in the insert statement.
The process will have after the IF statement:_IF amountrs = countstat THEN
set_status_arbeit_zu_gebiet *(:P4_CNT_GEBIET) *;
ON THE OTHER
dbms_output.put ('nothing');
END IF;and the procedure will be as follows:_
CREATE OR REPLACE PROCEDURE set_status_arbeit_zu_gebiet *(p_lng_gebit varchar2) *.
IS
cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET = -: new. LNG_GEBIET - p_lng_gebit ;
v_c2 c2% ROWTYPE;
BEGIN
...
INSERT INTO TBL_ARBEIT_ZU_GEBIET (...)
VALUES
( -: new.) LNG_GEBIET - p_lng_gebit,...) ;...
END set_status_arbeit_zu_gebiet;
-
Hi guys
I need to spend some "student: 1234567" as below mentioned values function... but after having passed this value I get the error message
SP2-0552: Bind variable "1234567" not declared.
Please help me what I am doing wrong.
--------------------------------------------------------------------------------------------------------------
create or replace function func_get_employee (emp_id in varchar2)
return varchar2
as
return_value varchar2 (100);
Start
return_value: = emp_id;
for indx to 0... 20
loop
If (substr (emp_id, 1, 8) = ' :') student then)
return_value: = substr(emp_id,9)
elsif (substr (emp_id, 1, 6) =' location:') then
return_value: = substr(emp_id,7);
elsif (substr (emp_id, 1, 10) ='honorary:') then
return_value: = substr(emp_id,11);
on the other
return_value: = emp_id;
end if;
end loop;
return return_value;
end;
/I have found no problems with your code outside a missing semi colon on line 10
create or replace function func_get_employee(emp_id in varchar2) return varchar2 as return_value varchar2(100); begin return_value := emp_id; for indx in 0 .. 20 loop if (substr(emp_id,1,8) = 'student:') then return_value := substr(emp_id,9); elsif (substr(emp_id,1,6)='staff:') then return_value := substr(emp_id,7); elsif (substr(emp_id,1,10)='honorary:') then return_value := substr(emp_id,11); else return_value := emp_id; end if; end loop; return return_value; end; PRAZY@11gR1> / Function created. Elapsed: 00:00:00.04 PRAZY@11gR1> select func_get_employee('student:1234567') from dual; FUNC_GET_EMPLOYEE('STUDENT:1234567') ---------------------------------------------------------------------- 1234567 Elapsed: 00:00:00.00
Kind regards
Prazy -
Hey everybody,
I have a little trouble to create a report. I need the FROM part of the code in order to use bind variables. I came up with this piece of code below, but im getting the following error:
Failed to parse the SQL query:
ORA-06550: line 1, column 8:
PLS-00103: encountered the symbol "" when expecting one of the following values:
begin function package pragma procedure subtype type use
form
current cursor
The symbol "" was ignored.
ORA-06550: line 2, column 24:
PLS-00103: encountered the symbol "" when expecting one of the following values:
begin function package pragma procedure subtype type use
form
course
Where can I see im wrong?
Thanks in advance,
-N.S.N.O.
Code
DECLARE
x VARCHAR2 (4000);
BEGIN
x : = x || "select *";
x : = x || "from";
x : = x || : p13_schema;
x : = x || '.ddl_log @';
x : = x || : p13_db_name;
x : = x || ' _DBAAPEX. TNTEWW. COM';
RETURN (x);
END;AHA, but when you have changed the source, have you also changed the Type (from "SQL query" to "SQL Query-PL/SQL function return SQL Query")?
And clicked on "use generic names (analysis of query runtime only) column" option below the source code? -
Estimate of poor cardinality using Bind Variables
Hi I'm using the 11.2.0.4.0 Oracle version. I have a query that is underway for the plan of the poor execution by the estimate of poor cardinality for two tables (I've extracted and published this part only) as I mentioned below, the individual conditions for which the estimate goes bad and moving entire query execution path.
These are for two tables and currently we use BIND variable for them in our code, and I notice, its best estimate gives with literals. I need to know how to handle this scenario that I need this query to execute for all types of volumes. Is there something I can do without changing the code, as it works well for most of the execution? In the current scenario of the main query that uses those below tables providing a plan (index + nested loop) that works very well for small volume, but running for 10 hr + for large volume as ideally its going to the same regime.
And Yes, most time that this request will be hit for small volume, but killing some appearance of large volume presents the performance of the queries.
Here are the values of the variable binding.B1 VARIABLE VARCHAR2 (32);
B2 VARIABLE VARCHAR2 (32);
B3 VARIABLE NUMBER;
B4 VARIABLE VARCHAR2 (32);
B7 VARIABLE VARCHAR2 (32);
B5 VARIABLE NUMBER;
B6 VARIABLE NUMBER;EXEC: B1: = 'NONE ';
EXEC: B2: = NULL;
EXEC: B3: = 0;
EXEC: B4: = NULL;
EXEC: B7: = NULL;
EXEC: B5: = 0;
EXEC: B6: = 0;---- For TABLE1------- -- Published Actual VS Etimated cardinality -- With bind values select * from TABLE1 SF WHERE ( (SF.C1_IDCODE = :B4) OR (NVL (:B4, 'NONE') = 'NONE')) AND ( (SF.C2_ID = :B3) OR (NVL (:B3, 0) = 0)); Plan hash value: 2590266031 ----------------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem | ----------------------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 28835 |00:00:00.08 | 2748 | 46 | | | | |* 1 | TABLE ACCESS STORAGE FULL| TABLE1 | 1 | 11 | 28835 |00:00:00.08 | 2748 | 46 | 1025K| 1025K| | ----------------------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - storage((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0))) filter((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0))) -- With literals select * from TABLE1 SF WHERE ( (SF.C1_IDCODE = null) OR (NVL (null, 'NONE') = 'NONE')) AND ( (SF.C2_ID = 0) OR (NVL (0, 0) = 0)); Plan hash value: 2590266031 -------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem | -------------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 28835 |00:00:00.03 | 2748 | | | | | 1 | TABLE ACCESS STORAGE FULL| TABLE1 | 1 | 28835 | 28835 |00:00:00.03 | 2748 | 1025K| 1025K| | -------------------------------------------------------------------------------------------------------------------------------------- --------For TABLE2 ----------------------- -- Published Autotrace plan, as it was taking long time for completion, and actual cardinality is 45M, but its estimating 49 With bind value--- --withbind value select * from TABLE2 MTF WHERE ( (MTF.C6_CODE = TRIM (:B2)) OR (NVL (:B2, 'NONE') = 'NONE')) AND ( (MTF.C3_CODE = :B1) OR (NVL (:B1, 'NONE') = 'NONE')) AND ( (MTF.C4_CODE = :B7) OR (:B7 IS NULL)) AND ( (MTF.C5_AMT <= :B6) OR (NVL (:B6, 0) = 0)) AND ( (MTF.C5_AMT >= :B5) OR (NVL (:B5, 0) = 0)); Execution Plan ---------------------------------------------------------- Plan hash value: 1536592532 ----------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ----------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 49 | 10437 | 358K (1)| 01:11:43 | | | | 1 | PARTITION RANGE ALL | | 49 | 10437 | 358K (1)| 01:11:43 | 1 | 2 | |* 2 | TABLE ACCESS STORAGE FULL| TABLE2 | 49 | 10437 | 358K (1)| 01:11:43 | 1 | 2 | ----------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - storage(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR NVL(:B2,'NONE')='NONE')) filter(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR NVL(:B2,'NONE')='NONE')) -- with literal select * from TABLE2 MTF WHERE ( (MTF.C6_CODE = TRIM (null)) OR (NVL (null, 'NONE') = 'NONE')) AND ( (MTF.C3_CODE = 'NONE') OR (NVL ('NONE', 'NONE') = 'NONE')) AND ( (MTF.C4_CODE = null) OR (null IS NULL)) AND ( (MTF.C5_AMT <= 0) OR (NVL (0, 0) = 0)) AND ( (MTF.C5_AMT >= 0) OR (NVL (0, 0) = 0)); Execution Plan ---------------------------------------------------------- Plan hash value: 1536592532 ----------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ----------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 45M| 9151M| 358K (1)| 01:11:41 | | | | 1 | PARTITION RANGE ALL | | 45M| 9151M| 358K (1)| 01:11:41 | 1 | 2 | | 2 | TABLE ACCESS STORAGE FULL| TABLE2 | 45M| 9151M| 358K (1)| 01:11:41 | 1 | 2 | ----------------------------------------------------------------------------------------------------------- select column_name,num_nulls,num_distinct,density from dba_tab_col_statistics where table_name='TABLE2' and column_name in ('C3_CODE','C4_CODE','C5_AMT','C6_CODE'); C3_CODE 0 65 0.0153846153846154 C4_CODE 0 2 0.5 C5_AMT 0 21544 4.64166357222429E-5 C6_CODE 1889955 71 0.0140845070422535
933257 wrote:
((SF. C1_IDCODE =: B4) OR (NVL (: B4, 'NONE') = 'NONE'))
In fact for literals, I did not find any section of the predicate after running the sql code with activation "set autotrace traceonly explain."
The main problem is with another large query whose cardinality is underestimated due to the presence of these table (table1, table2) with the above mentioned clause, and the query is for the analysis of index + nested with values of Bind loops and take 10 hr +, whereas with literals, its completion in ~ 8minutes with FTS + Hash Join.
Your real problem is that you try to have just a single SQL query handle all POSSIBLE thanks to the use of embedded FILTERS ' either / or ' filters in the WHERE clause. You want only a select this OPTION to run whatever filters have been selected at run time by the user or the application using it. And it would never work. You really need to SELECT different queries for different combinations of filter conditions.
Why? Think for a minute. How Oracle works internally? A SQL SELECT query gets analyzed and an execution plan is produced which is stored in the library cache and gets REUSED on all subsequent executions of this query - except in certain cases where there may exist several plans run through several cursors of the child. So with only SELECT a query you only AN execution plan in the library cache, to be used by all THE executions of this query, regardless of the value of your run-time binding variables.
Lets put another way - each library cache execution plan is associated with a SQL statement. If you want a DIFFERENT execution plan then you need run a DIFFERENT SQL statement. That's how you get a different execution plan - by running a different SQL statement. Running the SAME SQL query generally you will get the SAME execution plan every time.
In addition, because of the "either / or" filters that you use you will end up generally with a full Table Scan on each of the referenced tables. Why? Given that the optimizer must produce an implementation plan that manages all possible contingencies for all values of possible bind variables in the SELECT. If the optimizer should choose to use any index based on one of these "either / or" filters then it would only help performance when real value was provided, but it would be really bad if a NULL value was supplied. If the optimizer ends up ignoring the index because they are not always optimal for all possible input values and instead chose a plan that is "good enough" for all input values possible. That means that it will use a scanning Table full.
I hope you can see that it is precisely what is happening for you with your query. You select this OPTION to manage the different combinations of filter, which leads to the execution plan only one, which leads to scans full Table on the referenced tables in these ' either / or ' filters.
The solution? Build queries SELECT DIFFERENT when input values are NULL. How you do that? Read this article to ask Tom that tells you:
http://www.Oracle.com/technetwork/issue-archive/2009/09-Jul/o49asktom-090487.html
To sum up - when you have real value for a bind variable 'bind_var1' add the following filter to your CHOICE:
AND column_name1 =: bind_var1
When the binding variable is NULL, add the filter according to your CHOICE:
AND (1 = 1 OR: bind_var1 IS NULL)
Now, you'll have 2 queries SELECT must be performed, which have exactly the same number of variables in the same order bind, which is important. When you then run one of these variations, Oracle can analyze and optimize each one SEPARATELY, with a single execution by the SELECT query plan.
When you provide a real value, the filter is a normal 'column = value' that the optimizer can use all indexes on this column, because NULL values are not referenced.
When there is no real value, the optimizer will analyze the '1 = 1 GOLD' and realize that "1 = 1" is set to TRUE and GOLD, it is quite TRUE regardless because the binding variable is null or not. This means that the optimizer will actually REMOVE this filter, because it filters nothing because it is always TRUE. You will end up with an operating plan based on the other filters in the query, which is what you want because you have no filter on this column.
What is it - producing distinct SELECT queries to determine if you have a real value to filter or not you end up with DIFFERENT execution plans for each of them, and each of them is OPTIMAL for this particular set of filters. Now you get good performance for each variation of the performance of the SELECTION, rather than sometimes good and sometimes very bad when using SELECT only one. It is impossible to try to get multiple shots of execution 'optimal' out of a SELECT query. That's why you get mediocre performance under different bound the values of the variables.
John Brady
-
Hello
I am trying to create a function inside the packaging.
In the Package BODY I've defined the function, but in the definition of the package, it gives me syntax errors.
- Error (15,3): PLS-00103: encountered the symbol ";" when expecting one of the following values: back
- Error (39.1): PLS-00103: encountered the symbol "END" when waiting for one of the following values: start the function pragma procedure subtype type current cursor removal exist prior
What can I do wrong here.
Thank you
Ken
Inner package BODY:
/ * FUNCTION to form the query * /.
FUNCTION UDF_FORMQUERY)
IN_CASEID VARCHAR2,
IN_SRCLYR VARCHAR2,
IN_SRC_CONDN VARCHAR2
)
RETURN VARCHAR2
AS
varSQLQuery VARCHAR2 (10000);
BEGIN
varSQLQuery: = "test query";
RETURN varSQLQuery;
DBMS_OUTPUT. Put_line (varSQLQuery);
END UDF_FORMQUERY;
Definition of package inside:
create or replace PACKAGE BODY MY_SQUERY
AS
FUNCTION UDF_FORMQUERY)
IN_CASEID VARCHAR2,
IN_SRCLYR VARCHAR2,
VARCHAR2 IN_SRC_CONDN( )
RETURN VARCHAR2
AS varSQLQuery VARCHAR2 (10000);
END MY_SQUERY;
your package definition is incorrect, you have included the part of the declaration of the variables of the function in the package definition. It should be like
FUNCTION UDF_FORMQUERY)
IN_CASEID VARCHAR2,
IN_SRCLYR VARCHAR2,
IN_SRC_CONDN VARCHAR2)
RETURN VARCHAR2;
-
Passing literal as a bind variable in Jena
Hi all
We are able to use bind variable with the id RDFVID. However, if we want to check for a literal using the jena/joseki adapter we are not able to perform the same operation. In our case the literal is of type string.
We use:
* WLS 12.1.0.3.
* Adapter Jena 2.11.1.
* Joseki 3.4.4.
* ARQ 2.9.2.
We try to run the following query on the stop of joseki.
PREFIX foaf: http://xmlns.com/FOAF/0.1/ >
PREFIX vcard: http://www.w3.org/2001/vCard-RDF/3.0# >
PREFIX xsd: http://www.w3.org/2001/XMLSchema# >
PREFIX oext: < http://Oracle.com/Semtech/Jena-adaptor/ext/function# >
PREFIX ORACLE_SEM_FS_NS: http://Oracle.com/Semtech#no_fall_back, ALLOW_DUP = T, s2s >
PREFIX ORACLE_SEM_HT_NS: http://Oracle.com/Semtech#monitor >
PREFIX ORACLE_SEM_UEAP_NS: http://oracle.com/semtech#f$ RDFVID % 20 (ORACLE_ORARDF_RES2VID(?)) >
PREFIX ORACLE_SEM_UEPJ_NS: http://Oracle.com/Semtech#f $RDFVID >
PREFIX ORACLE_SEM_UEBV_NS: http://Oracle.com/Semtech# 'Lee' >
SELECT? f
WHERE
{graph? g {? vcard:N p? vn.}}
? VN vcard:Family? f.
? FOAF:title p 'Sen'.}
}
The result set is empty. Replace the line 'ORACLE_SEM_UEBV_NS PREFIX: <http://oracle.com/semtech# "Lee"> "by any Variant is to be given an error or the empty set. (Some variants (& quot;)) Lee & quot; Lee, "Lee" & #39; Lee & #39; )
When we use the generated SQL code of jena/joseki, we are able to get the right result if we execute the query even in SQLDeveloper. To use the variable binding is "Lee" (the binding variable is the price included). This will give you a correct result in withdrawal.
Kind regards
Max
Hi Max,.
In the area of the UEBV, you must put "Lee" encoded in URL string
Please, try the following and see if it helps.
% 22Lee % 22
Thank you
Zhe Wu
-
I am writing a process to delete records based on dates.
Here is the chart:
Column name Data type Nullable Default Primary key ID NUMBER NO. - 1 CT_NAME VARCHAR2 (100) Yes - - CT_CATEGORY VARCHAR2 (100) Yes - - BASE_PTS NUMBER Yes - - PROD_PTS NUMBER Yes - - REF_PTS NUMBER Yes - - START_DATE DATE Yes - - END_DATE DATE Yes - - CREATED_ON DATE Yes - - CREATED_BY VARCHAR2 (50) Yes - - UPDATED_ON DATE Yes - - UPDATED_BY VARCHAR2 (50) Yes - - start_date and end_date are the fields of date key.
The query will remove the dates with specific start and end dates. The question I have, is that I get a ORA-01858: a non-digit character was found here where was waiting for a digital error while the query is running.
remove from ct_point_values
where start_date =: P4_START_DATE_V
and end_date =: P4_END_DATE_V
If I run the query in the sql window, no problem:
remove from ct_point_values
where start_date =' 01 / 01/2014 '
and end_date = 31 December 2014"
Find the query with the works of values hard-coded. Links to fail. I tried casting and to_char to_date variations with no luck.
One thing that I notice, is that when I go to enter my bind variables in the sql workshop, the fields are pre-populated with this:
1 & amp; #x2F 1 & amp; #x2F; 2014
12 & amp; #x2F 31 & amp; #x2F; 2014
01/01/2014 and 31/12/2014. I found that the only element relates to this suggests that this is a possible bug:
SQL Bind Variables workshop - Date issues
Any thoughts on how to address this issue, or is it really a bug?
I run on Apex 4.2, 11g.
Thank you!
Hello
I guess that these dates come from elements on the page to which the user can select a range of dates.
These fields have a custom format mask?
What seems to be the case for me, is that these fields have an explicit format mask (for example: DD/MM/YYYY) but the default database/session format mask is something different (e.g. DD-MON-YYYY).
I suppose also that the issue in the SQL workshop isn't something related.
Maybe you are looking for
-
How can I add apps to my widgets?
I don't have the same apps available in the widgets on my iPad, as I have on my iPhone. How can I add apps to widgets on my iPad?
-
Need of CD drive bootable compatible 16 bit for Portege R100
Hi all. I have a protected R100 I need to run the recovery cd on.So far, I discovered that I need a CD bootable (usb not supported) 16-bit pcm. My problem/query is that I can't find anywhere to establish: (A) a device approved, favorite or compatible
-
Cannot open the pictures library after the data transfer to my new macbook
I transferred all my data from my old MacBook Air to my new MacBook Pro via a restore from time machine. My first time to open my library on my News Photos Photos of MacBook says that he must perform the restore procedure (see screenshot in German la
-
I can't set up a new account with T-Mobile 4G
I have recently buy a slate of 10 HD 3600 us with Android JellyBean and I was just the initial game upward. Instructions to set up a new account 4G with T-Mobile seem simple enough in the tutorial:http://WWW8.HP.com/us/en/ads/free-mobility/overview.h
-
Change the name of the computer to apply to folders - Vista
My computer was a friend, but when they gave it to me I tried to change the name of the computer to mine but that you are unable to apply to the user folders (I hope that makes sense!) - the user account name is Elise, but the address (?-equivalent o