SQL:-the Variables reset
HelloI have a question about the SQl query below. I have 2 variables that are used in the two declarations. I don't want to be invited twice to the variables, so I used & &. I want to be able to run the same script again, but I want to be prompted for the date.
The SQl is for tasks that violate a given period of time. I want to be able to define the period each time, but only once per race for each variable
SET PAGESIZE 10000
SET VERIFY OFF
SET FEEDBACK OFF
SET ECHO OFF
/ * Tasks which has lack of ALS to add new asset - Single * /.
SELECT x.NUMBERPRGN're 18
OF CM3TM1 x
where x.ASSIGN_DEPT = 'CBCONF. '
and GROUP like '% ESP, % '.
and x.brief_desc like '% add new asset - Single% '.
and x.ORIG_DATE_ENTERED > = ' & & Date_From'
AND x.ORIG_DATE_ENTERED < = ' & & Date_To'
and (x.close_time > = (x.ORIG_DATE_ENTERED + 5));
/ * Tasks that missed SLAS for the categorization of the Incident * /.
SELECT x.NUMBERPRGN're fifteen years old
Of. CM3TM1 x
where x.ASSIGN_DEPT = 'CBCONF. '
and x._INIT_GROUP like '% ESP, % '.
and x.brief_desc like '% Incident categorization % '.
and x.ORIG_DATE_ENTERED > = ' & & Date_From'
AND x.ORIG_DATE_ENTERED < = ' & & Date_To'
and (x.close_time > = (x.ORIG_DATE_ENTERED + 5));
GAME TO CHECK ON
SET FEEDBACK ON
SET ECHO ON
Fouzi that makes sense. I need to know how to reset my variable. I tried to, I don't seem to get it to work
Published by: user3924223 on January 28, 2009 07:52
Hello
Welcome to the forum!
SQL * undo the command DEFINITION will do what you want.
Say:
UNDEFINE Date_From
UNDEFINE Date_To
at the end of your script, or whenever you are using the old values.
Tags: Database
Similar Questions
-
How to display the value of the variable for bottom of pl/sql
How to display the value of the variable for bottom of pl/sql
declare
V_1 number: = 10;
V_2 number: = 20;
V_3 number: = 30;
v_4 number: = 40;
v_5 number: = 50;
test varchar2 (100);
Start
I'm in 1.5
loop
test: = "v_" | I have;
dbms_output.put_line(i||) e > ' | test);
end loop;
end;
/
How to get below output:
1 > v_1
2 > v_2
3 > v_3
4 > v_4
5 > v_5
But I want to output of
1 > 10
2 > 20
3 > 30
4 > 40
5 > 50
Hello
You cannot reference variables as you did and get the value of the variable. Use pretty collection.
set serveroutput on size 2000 declare type number_table is table of number; numbers number_table := number_table(10, 20, 30, 40, 50); begin for i in numbers.first .. numbers.last loop dbms_output.put_line(i || '->' || numbers(i)); end loop; end; / anonymous block completed 1->10 2->20 3->30 4->40 5->50
See the Collections of PL/SQL and Records http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS005
-
Hello!
I have a simple object type and a proecdure in which I am trying to use it to insert into another table
-object
CREATE ORREPLACETYPEmt_mtg ASOBJECT
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;
-same structure as the use of sampletbl target table in the cursor query
create table tbl_MT_MTG
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
-procedure
CREATE ORREPLACEINTERIORTEST_PROCEDURE1
AS
ref_cur sys_refcursor ;
REFR ref_mtg ;
BEGIN
OPEN ref_cur FOR
Select acol,
BCOL
DE sampletbl où rownum<10;
Fetch ref_cur in bulk collectintorefr;
Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);
commit;
CLOSE Ref_cur;
END;
/
When I run this procedure fails with
ORA-06504: PL/SQL: return variables of the game results or the query types do not match
ORA-06512: at "TEST_PROCEDURE1", line 10
ORA-06512: at line 2
Any help on this please...
Thanks to an OLD POST below
so perfect helped me! Thank you
Tubby
After 5 years of more :-)
How to store refcursor in collection How to store refcursor in collection
-
Why the value of my variable resets Boolean false when executing a method of a Bean?
Hey everybody,
I use JDeveloper 12.1.2.0.0.
As the title says, my Boolean variable resets to false when I run my bean class method.
In my bean class, I have this variable:
Bank private Boolean = false;
{} public void onDimStoreSelect (SelectionEvent selectionEvent)
...
Ranger = true;
FactSalesHUB (selectionEvent);
...
}
{} public void onDimSellerSelect (SelectionEvent selectionEvent)
....
FactSalesHUB (selectionEvent);
}
public void FactSalesHUB (SelectionEvent selectionEvent) {}
GenericTableSelectionHandler.makeCurrent (selectionEvent);
If (product! = true)
matchEmFromJavaScriptProducts();
If (store! = true)
matchEmFromJavaScriptStore();
If (seller! = true)
matchEmFromJavaScriptSeller();
If (project! = true)
matchEmFromJavaScriptProject();
If (customer == false)
matchEmFromJavaScriptCustomer();
If (part! = true)
matchEmFromJavaScriptCoin();
}
If I perform the onDimStoreSelect and after that, if I run the onDimSellerSelect, the value of the client variable is already set to false and it will make my matchEmFromJavaScriptStore() runs when I don't want it.
Why didn't he stores the value as false since I did in the previous method? Any idea?
If the problem is not well explained, or it is not well explained just tell.
Kind regards
Frederico.
Try to increase the scope of your beans. After each request your bean loses value and believe you lose the set Boolean value.
-
the variable name of database query to SQL Server using the Oracle database link
Hi all
I have an ApEx 4.1 application running on x 64 (11.2.0.1) 11g on Windows Server 2008 x 64, and I have a few points of data integration with SQL (2005 and 2008) server that I need to create. I have configured the database with dg4odbc link and it works perfectly... I can run queries on the SQL Server database without any problem using the database link.
However, there is a scenario where the SQL Server database name is dynamic, and I need to generate on the fly in a PL/SQL block and then use it in a query dynamic SQL (all this in the ApEx). It of wherever I meet problems... when I asked the default database that is based on the ODBC connection and I don't have to specify the name of the database, no problem. But when I need access to one of the several other databases by default, I received the error "invalid table.
It works well:* (note that 'fv' is the name of my database link)
v_query1: = "select 'Release Date' from dbo." Schedules@FV where dbo. Annexes. "" SchedID "=: calendar";
EXECUTE IMMEDIATE v_query1 in rel_date using the grid.
I then take this rel_date variable, convert a varchar2 (rel_date_char), then use it as the name of the database in the following query...
_ It returns an error(error ORA-00903: invalid table name)
v_query2: = "select"PARTNO": rel_date_char.dbo.ProdDetails@fv where 'SchedID' =: calendar and"UnitID"=: unit"
and 'MasterKey' =: master and "ParentKey" =: parent';
EXECUTE IMMEDIATE v_query2 in part_number using planning, master, parent unit;
I also tried using all of the following conditions without result:
"select"PARTNO"of" | : rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"of" | rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"of" | @rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"in @rel_date_char.dbo.ProdDetails @fv where 'SchedID'..."
Is it possible to do it in PL/SQL?
Thanks for any help!
-Ian C.
Published by: 946532 on July 15, 2012 19:45Just did a test using passthrough:
SQL > set serveroutput on
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5. start
c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, "select count (*) from EMP");
8 LOOP
9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
10 output when nr = 0;
11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
12 dbms_output.put_line (val);
13 end of loop;
14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
15 end;
16.
24576PL/SQL procedure successfully completed.
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5. start
c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' select count (*) from dbo.) EMP');
8 LOOP
9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
10 output when nr = 0;
11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
12 dbms_output.put_line (val);
13 end of loop;
14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
15 end;
16.
24576PL/SQL procedure successfully completed.
So all 3 ways work for me.
Published by: kgronau on July 23, 2012 10:08
Now, using the variables to make the selection:
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5 tabname varchar2 (20): = 'EMP ';
6 ownr varchar2 (20): = "dbo."
7 dbname varchar2 (20): = "door";
Start 8
c: 9 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
10 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' SELECT count (*) FROM ': dbname: '.) ' || ownr | '.'|| tabname | ") ;
11 LOOP
12 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
13 when the exit nr = 0;
14 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
15 dbms_output.put_line (val);
16 end loop;
17 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
18 end;
19.
24576PL/SQL procedure successfully completed.
=> instead of executing the statement using the "execute Immediate" we use the PASTHROUGH package to pass the statement to SQL Server.
Published by: kgronau on July 23, 2012 10:10
-
Reset of the variable defined by guest presentation
I have 2 guests, State and City, led by a single button print. The State guest sets a variable of presentation called STATE_VAR and filters prompt City column values from list of choices based on the STATE_VAR and sets its own presentation CITY_VAR variable when the user selects a choice in the list. The two guests have flaws - STATE_VAR fast by default to a specific State in the initial page loads and the CITY_VAR defaults to nothing (no option in quick dialogue).
This question I want to address is reset the variable of CITY_VAR presentation (in the default value, no option in the quick dialog) when the user selects a different State in the guest of the State . The sequence I want to reach is listed below.
(1) on page load STATE_VAR and State quick choice are defined in Michigan and the CITY_VAR and the town guest are set to nothing (White option)
(2) user selects Detroit as one of the cities in the prompt the City and click on the GO button.
(3) the loading of the page, the presentation of STATE_VAR variable and corresponding State guest are set in Michigan, but now the guest of CITY_VAR and the City are now set in Detroit
(4) the user selects a different option in the State prompt, say Nebraskaand click on the GO button
(5) after loading the page, the presentation of STATE_VAR variable and corresponding State guest are now defined in Nebraska, however, the default option selected in the rapid City and corresponding CITY_VAR variable of presentation are still Detroit , although the choice list now contains different values.
Is there anyway to restore the prompt of the CITY_VAR and the default City Nothing (no) selected state, essentially reset the variable of presentation?
Thank you.I fear... you will not be able to achieve...
The best thing you can do is check the box store in the guest of the city...
Thank you
Ashish -
APEX_UTIL. JSON of SQL in the variable
Hi all
How do we store result of APEX_UTIL. JSON_FROM_SQL ("select a, b, c of double'") in a SQL PL variable? Any help. Urgent!
Thank you
Sunil bhatia
declare function sql2json( p_sql varchar2 ) return varchar2 is t_cur pls_integer; t_cols dbms_sql.desc_tab2; t_ncols pls_integer; t_dummy pls_integer; t_d date; t_n number; t_v varchar2(4000 char); t_json varchar2(32767); t_object varchar2(32767); begin t_cur := dbms_sql.open_cursor; dbms_sql.parse( t_cur, p_sql, dbms_sql.native ); dbms_sql.describe_columns2( t_cur, t_ncols, t_cols ); for i in 1 .. t_ncols loop case when t_cols(i).col_type in ( 2, 100, 101 ) then dbms_sql.define_column( t_cur, i, t_n ); when t_cols(i).col_type in ( 12, 180, 181, 231 ) then dbms_sql.define_column( t_cur, i, t_d ); else dbms_sql.define_column( t_cur, i, t_v, 4000 ); end case; end loop; t_dummy := dbms_sql.execute( t_cur ); while dbms_sql.fetch_rows( t_cur ) > 0 loop t_object := '{'; for i in 1 .. t_ncols loop t_object := t_object || case when i > 1 then ',' end || '"' || t_cols(i).col_name || '":'; case when t_cols(i).col_type in ( 2, 100, 101 ) then dbms_sql.column_value( t_cur, i, t_n ); t_object := t_object || nvl( to_char( t_n, 'TM9', 'NLS_NUMERIC_CHARACTERS=.,' ), 'null' ); when t_cols(i).col_type in ( 12, 180, 181, 231 ) then dbms_sql.column_value( t_cur, i, t_d ); t_object := t_object || '"' || to_char( t_d, 'dd-mm-yyyy' ) || '"'; else dbms_sql.column_value( t_cur, i, t_v ); t_object := t_object || '"' || replace( replace( replace( replace( replace( replace( replace( replace( t_v , '\', '\\' ) , '"', '\"' ) , '/', '\/' ) , chr(8), '\b' ) , chr(12), '\f' ) , chr(10), '\n' ) , chr(13), '\r' ) , chr(9), '\t' ) || '"'; end case; end loop; t_json := t_json || case when t_json is null then '[' else ',' end || t_object || '}'; end loop; dbms_sql.close_cursor( t_cur ); return nvl( t_json, '[' ) || ']'; end; begin dbms_output.put_line( sql2json( q'~select 'test' || level a, level b, sysdate c from dual connect by level <= 5~' ) ); end;
-
BIND THE VARIABLE INSIDE A LOOP
Hello
I have question about the sort of the values using Plsql... My requirement is to get values of N with the user and sorting in ascending or descending order. I tried the following query
DECLARE
Is of type TABLE numsort
NUMBER
INDEX OF DIRECTORY;
v_num numsort;
number of v_total;
number of v_no;
BEGIN
-get the number of values to sort
v_total: =: TotalNum;
dbms_output.put_line (v_total);
because me in 1.v_total
LOOP
v_no: =: none; -Read the values
v_num (i): = v_no;
dbms_output.put_line (v_num (i): 10;)
END LOOP;
END;
its code is not complete... sound to read the value in the table... Read itself does not
The problem is that the connection variable is not reset with each iteration. I am using Toad and he asked me to pass all the variable binding both... But I want to read the values in the table with each iteration. Is it possible in PLSQL... or is there another way to do this...
hope you are clear with the requirement... If any infomartion extra need please come bk...
Waiting for your replay
Thanks and greetings
RognardMaybe like this?
SQL> create or replace procedure test_proc (p_input varchar2, p_separator varchar2) is 2 v_input varchar2(32767):= p_input||p_separator; 3 begin 4 if p_input is not null then 5 while instr(v_input,p_separator) > 0 loop 6 dbms_output.put_line(substr(v_input,1,instr(v_input,p_separator)-1)); 7 v_input:=substr(v_input,instr(v_input,p_separator)+1); 8 end loop; 9 end if; 10 end; 11 / Procedure created. SQL> exec test_proc('10, 4, 6, 3',',') 10 4 6 3 PL/SQL procedure successfully completed. SQL> exec test_proc('',',') PL/SQL procedure successfully completed. SQL>
Nicolas.
-
Adjust the data in the database with the variables
Hello
For my internship, I have an assignment to read and set a database with the variables. This SQL server 2005 database contains variables of a controller. These are read and write variables. The assignment is to display the read variables and the user can adjust the variables of Scripture. The first part was "easy" because the forum contained a lot of examples of this. The second part is more difficult because the forum contains absolutely no example of this. Can I use LabVIEW 2010 and 2011, and also I downloaded the 30 day trial of the database connection tool. If it's useful, I can recommend my company to buy this package. Playback vi makes use of a UDL (Microsoft data link) connection.
So you guys my question is: is it possible to adjust the specific variables in a database using LabVIEW? And maybe you can give me a little advice on this topic...
Thanks in advance!
Roy
In SQL, the specific data are always selected with the keyword WHERE. In VI to update there is a link for options, you can for example add a constant 'WHERE id = 1457 and measure > 0.54 ".
You can ofc. also build this chain through controls, settings and other means.
If you prefer, you can use the Execute Query (under Advanced tab I think) to which you can send the complete query example "TestTable Update set name ="Zeus"where id > 14 and id.<>
/Y
-
Invalid reference to the variable 'NUMBER '.
Hi gurus
I understand that if someone helps me, I have the following code example.
Code example
SET SERVEROUTPUT ON
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers (1).) (COUNT);
END;
Error
Error report:
ORA-06550: line 7, column 38:
PLS-00487: Invalid reference to the variable 'NUMBER '.
ORA-06550: line 7, column 3:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
I want to check the index 1 of my collection, but I get the above error. Can someone help me to remove this error. Thank you
Concerning
Matt
Hi, Matt,
Matt. wrote:
Hi gurus
I understand that if someone helps me, I have the following code example.
Code example
SET SERVEROUTPUT ON
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers (1).) (COUNT);
END;
Error
Error report:
ORA-06550: line 7, column 38:
PLS-00487: Invalid reference to the variable 'NUMBER '.
ORA-06550: line 7, column 3:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
I want to check the index 1 of my collection, but I get the above error. Can someone help me to remove this error. Thank you
Concerning
Matt
The collections have some counts; scalars don't.
l_numbers is a collection, so you can see the number of items contained in it like this:
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers. (COUNT);
END;
/
l_numbers (1) , however, is just a scalar NUMBER, you can't use COUNT on it
In other words, l_numbers (1) is the number 1, so we can not say
DBMS_OUTPUT. Put_line (l_numbers. (COUNT);
for exactly the same reason that you can't say
DBMS_OUTPUT. Put_line (1. (COUNT);
-
Gettting ODI-17511: no value to the variable. ?
Hi all
I am facing an error when executing a Package to load all dishes unique to Oracle DB folder files.
The thing is that I am able to load data but it's operator error display "no value to the variable ' MULTI_DEMO." "File_name'"
Details of my project are:
PROJECT_NAME: MULTI_DEMO
Name of the interface: MULTI_TEST
Have 5 text files in my folder of the source code. and the target is created as the same schema as the source
variables: filename, County, Files_Count
statement = file_name
DataType: alphanumeric
Keep history: last value
Request used:
SELECT FILE_NAME FROM (SELECT FILE_NAME, SRC_FILE_DETAILS RN ROWNUM)
WHERE RN =' #MULTI_DEMO.count '
statement = count
Data type: digital
Keep a history: last value
Request used: nothing
statement = Files_Count
Data type: digital
Keep a history: last value
Request used: select count (*) in SRC_FILE_DETAILS
I have clearly chosen patterns appropriate for the two variables with queries.
in the Package diagram:
step 1: count = 1 assign (type: set variable) {-> File_Name and failure success: END}
step 2: filename (type: Refresh variable) {-> multi_test success and failure: END}
step 3: multi_test (type: flow (interface)) {success-> count and failure: END}
step 4: count increment = 1 (type: set variable) {success-> Files_Count and failure: END}
step 5: Files_Count (type: Refresh variable) {success-> count and failure: END}
step 6: County (type: evaluate the variable) is operator " > = " value is "MULTI_DEMO.count" {success-> File_Name and failure: END}
Please find below the picture for flow diagram
I have changed the stage names, hope you find my reviews.
Please help me to sort out this error.
I use OBIEE 11.1.1.9
The error is in short:
java.lang.Exception: ODI-17511: no value to the variable ' MULTI_DEMO. File_name'.
at oracle.odi.runtime.agent.execution.sql.RefreshVariableExecutor.execute(RefreshVariableExecutor.java:70)
at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlV.processTask(SnpSessTaskSqlV.java:410)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2637)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlV.treatTask(SnpSessTaskSqlV.java:240)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:380)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:312)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:304)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:874)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:133)
to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:84)
at java.lang.Thread.run(Thread.java:662)
I repeat, "I am able to load data but always error in the last step.
Thanks a mllion.
Shakur
-
Bind the Variable in a dynamic query
The procedure below uses a variable binding for the deptno and run it with a ref cursor The expected result is to display the ename from EMP for the deptno passed for the p_deptno parameter, but the procedure fails with an exception.
CREATE OR REPLACE PROCEDURE dynamic_query(p_deptno NUMBER) AS lv_deptno number(4); -- l_lookup_type VARCHAR2(30):='PBAMERICAS_CO'; lv_query VARCHAR2(15000) :=' SELECT ename,''Year'' from emp where deptno='|| p_deptno; lv_cursor SYS_REFCURSOR; lv_lookup VARCHAR2(20); lv_emp_rec emp%rowtype; lv_ename VARCHAR2(10); lv_year VARCHAR2(10); BEGIN dbms_output.put_line(lv_query); OPEN lv_cursor FOR lv_query USING p_deptno ; Loop FETCH lv_cursor INTO lv_ename,lv_year; dbms_output.put_line(lv_ename || ',' ||lv_year); EXIT WHEN lv_cursor%NOTFOUND; END LOOP; CLOSE lv_cursor; END dynamic_query;
SQL> exec dynamic_query(10); SELECT ename,'Year' from emp where deptno=10 BEGIN dynamic_query(10); END; * ERROR at line 1: ORA-01006: bind variable does not exist ORA-06512: at "APPS.DYNAMIC_QUERY", line 13 ORA-06512: at line 1
I can change the code slightly and change the where clause to work but wanted to know what am I did wrong which makes the procedure fails with the above code.
CREATE OR REPLACE PROCEDURE APPS.dynamic_query(p_deptno NUMBER) AS lv_deptno number(4); lv_query VARCHAR2(15000) :=' SELECT ename,''Year'' from emp ' ; lv_cursor SYS_REFCURSOR; lv_lookup VARCHAR2(20); lv_emp_rec emp%rowtype; lv_ename VARCHAR2(10); lv_year VARCHAR2(10); BEGIN IF p_deptno IS NOT NULL THEN lv_query := lv_query || ' Where deptno =' || TO_CHAR(p_deptno); END IF; dbms_output.put_line(lv_query); OPEN lv_cursor FOR lv_query ; Loop FETCH lv_cursor INTO lv_ename,lv_year; dbms_output.put_line(lv_ename || ',' ||lv_year); EXIT WHEN lv_cursor%NOTFOUND; END LOOP; CLOSE lv_cursor; END dynamic_query; /
PS: I use the table EMP for this example includes so not CREATE TABLE and INSERT.
The procedure below uses a variable binding
No, it isn't.
You're just concatenation of the value of p_deptno in the query, such as a literal.
It's using a variable binding:
lv_query VARCHAR2 (15000): = ' 'year', SELECT ename from emp where deptno =: 1';
Then, the variable may be correctly bound (by post) via the USING clause.
-
to BIND the variable SUBSTITUTION
I have a code where I find dates START and end range for the past 3 years, the beginning Date must start on a Sunday and the end Date is at the end on Saturday using the weird system they have here:-)
the end usable VARIABLE must be in YYYYMMDD format as number, because that's how they set up Date here... can anything about...
So I thought to all the Dates, performing a combination of Variables of SUBSTITUTION AND LINKING, why I do like that it is because
I received an error when I used just the variables SUBSTITUTION (maximum 240 characters used on the START DATE of the year2, in)
switching to this, the error has disappeared), well that's what I thought he'll fix it.
But now, when I try to use and VARIABLE in SQL, I get an error that it cannot use BIND variables, so try to pass values to a SUBSTITUTION
afin_que this error disappears) - unless there is a better way?
If there is a better way to stay maybe everything inside SUBSTITUTION and don't imply any LINK, maybe it would be better, if you guys know a way around the 240 character error...
:-)
My variables are:
-find YEAR 1
SET LY_END_DATE_NUM = "TO_NUMBER (TO_CHAR (NEXT_DAY ((SYSDATE-7), 'SATURDAY'), 'YYYYMMDD'));
variable BIND_LY_END_DATE_N number;
run: BIND_LY_END_DATE_N: = & LY_END_DATE_NUM;
PRINT BIND_LY_END_DATE_N;
SET LY_START_DATE = ' TO_DATE (: BIND_LY_END_DATE_N, 'yyyy-mm-dd')-363;
SET LY_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& LY_START_DATE, 'YYYYMMDD'));
variable BIND_LY_START_DATE_N number;
run: BIND_LY_START_DATE_N: = & LY_START_DATE_NUM;
PRINT BIND_LY_START_DATE_N;
-find YEAR 2
SET YRS2_END_DATE = ' TO_DATE (: BIND_LY_START_DATE_N, 'yyyy-mm-dd')-1;
SET YRS2_END_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS2_END_DATE, 'YYYYMMDD'));
variable BIND_YRS2_END_DATE_N number;
run: BIND_YRS2_END_DATE_N: = & YRS2_END_DATE_NUM;
PRINT BIND_YRS2_END_DATE_N;
SET YRS2_START_DATE = ' TO_DATE (: BIND_YRS2_END_DATE_N, 'yyyy-mm-dd')-363;
SET YRS2_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS2_START_DATE, 'YYYYMMDD'));
variable BIND_YRS2_START_DATE_N number;
run: BIND_YRS2_START_DATE_N: = & YRS2_START_DATE_NUM;
PRINT BIND_YRS2_START_DATE_N;
-find YEAR 3
SET YRS3_END_DATE = ' TO_DATE (: BIND_YRS2_START_DATE_N, 'yyyy-mm-dd')-1;
SET YRS3_END_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS3_END_DATE, 'YYYYMMDD'));
variable BIND_YRS3_END_DATE_N number;
run: BIND_YRS3_END_DATE_N: = & YRS3_END_DATE_NUM;
PRINT BIND_YRS3_END_DATE_N;
SET YRS3_START_DATE = ' TO_DATE (: BIND_YRS3_END_DATE_N, 'yyyy-mm-dd')-363;
SET YRS3_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS3_START_DATE, 'YYYYMMDD'));
variable BIND_YRS3_START_DATE_N number;
run: BIND_YRS3_START_DATE_N: = & YRS3_START_DATE_NUM;
PRINT BIND_YRS3_START_DATE_N;
Hello
Kodiak_Seattle wrote:
I have a code where I find dates START and end range for the past 3 years, the beginning Date must start on a Sunday and the end Date is at the end on Saturday using the weird system they have here:-)
the end usable VARIABLE must be in YYYYMMDD format as number, because that's how they set up Date here... can anything about...
So I thought to all the Dates, performing a combination of Variables of SUBSTITUTION AND LINKING, why I do like that it is because
I received an error when I used just the variables SUBSTITUTION (maximum 240 characters used on the START DATE of the year2, in)
switching to this, the error has disappeared), well that's what I thought he'll fix it.
But now, when I try to use & VARIABLE in SQL, I get an error that it cannot use BIND variables, so try to pass values to a SUBSTITUTION
afin_que this error disappears) - unless there is a better way?
If there is a better way to stay maybe everything inside SUBSTITUTION and don't imply any LINK, maybe it would be better, if you guys know a way around the 240 character error...
:-)
My variables are:
-find YEAR 1
SET LY_END_DATE_NUM = "TO_NUMBER (TO_CHAR (NEXT_DAY ((SYSDATE-7), 'SATURDAY'), 'YYYYMMDD'));
variable BIND_LY_END_DATE_N number;
run: BIND_LY_END_DATE_N: = & LY_END_DATE_NUM;
PRINT BIND_LY_END_DATE_N;
SET LY_START_DATE = ' TO_DATE (: BIND_LY_END_DATE_N, 'yyyy-mm-dd')-363;
SET LY_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& LY_START_DATE, 'YYYYMMDD'));
variable BIND_LY_START_DATE_N number;
run: BIND_LY_START_DATE_N: = & LY_START_DATE_NUM;
PRINT BIND_LY_START_DATE_N;
-find YEAR 2
SET YRS2_END_DATE = ' TO_DATE (: BIND_LY_START_DATE_N, 'yyyy-mm-dd')-1;
SET YRS2_END_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS2_END_DATE, 'YYYYMMDD'));
variable BIND_YRS2_END_DATE_N number;
run: BIND_YRS2_END_DATE_N: = & YRS2_END_DATE_NUM;
PRINT BIND_YRS2_END_DATE_N;
SET YRS2_START_DATE = ' TO_DATE (: BIND_YRS2_END_DATE_N, 'yyyy-mm-dd')-363;
SET YRS2_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS2_START_DATE, 'YYYYMMDD'));
variable BIND_YRS2_START_DATE_N number;
run: BIND_YRS2_START_DATE_N: = & YRS2_START_DATE_NUM;
PRINT BIND_YRS2_START_DATE_N;
-find YEAR 3
SET YRS3_END_DATE = ' TO_DATE (: BIND_YRS2_START_DATE_N, 'yyyy-mm-dd')-1;
SET YRS3_END_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS3_END_DATE, 'YYYYMMDD'));
variable BIND_YRS3_END_DATE_N number;
run: BIND_YRS3_END_DATE_N: = & YRS3_END_DATE_NUM;
PRINT BIND_YRS3_END_DATE_N;
SET YRS3_START_DATE = ' TO_DATE (: BIND_YRS3_END_DATE_N, 'yyyy-mm-dd')-363;
SET YRS3_START_DATE_NUM = "TO_NUMBER (TO_CHAR (& YRS3_START_DATE, 'YYYYMMDD'));
variable BIND_YRS3_START_DATE_N number;
run: BIND_YRS3_START_DATE_N: = & YRS3_START_DATE_NUM;
PRINT BIND_YRS3_START_DATE_N;
Let me make sure I understand the problem.
One year, in this problem, is exactly 364 days.
You want the year that ended on the most recent Saturday (otherwise said, the year ending Saturday between 6 days ago and today) and two years ago.
You want the first date in each of those years and the last date each year, in the format YYYYMMDD.
Is this fair?
Here's a way to define variables of substitution (with names like year_1_start):
COLUMN y1_start new_value by year_1_start
COLUMN y1_end new_value by year_1_end
COLUMN y2_start new_value by year_2_start
COLUMN y2_end new_value by year_2_end
COLUMN y3_start new_value by year_3_start
COLUMN y3_end new_value by year_3_end
WITH got_y1e AS
(
SELECT NEXT_DAY (SYSDATE - 7 'SATURDAY') AS y1e
OF the double
)
SELECT TO_CHAR (y1e + 1 - (364 * 3), 'YYYYMMDD') AS y3_start
, TO_CHAR (y1e - (364 * 2), 'YYYYMMDD') AS y3_end
, TO_CHAR (y1e + 1 - (364 * 2), 'YYYYMMDD') AS y2_start
, TO_CHAR (y1e - 364, 'YYYYMMDD') AS y2_end
, TO_CHAR (y1e + 1-364, 'YYYYMMDD') AS y1_start
, TO_CHAR (y1e, 'YYYYMMDD') AS y1_end
OF got_y1e
;
If you prefer that bind variable, write an anonymous PL/SQL block and use the same logic to 6 variables.
-
Reg exp to divide the values of the variables
Hello all, I use Oracle 11.2 of SOE, the value of the variable C is: numberA:numberB for example, C: = ' 1 B: 5 A: 12 has: B: 43 3A ", I have divided than the values of two Variables A and B with the letters of withdrawal and replacement of: for the comma. Namely, the value of each would be: is: 5,12,43 B is: 1.3 someone could help to come up with the correct Exp Reg for this task. Thanks in advance.
Here's a way (like SQL or PL/SQL):
with t (Spercu))
Select "1 B: 5 A: 12 A: B: 43 3A ' double
)
Select Spercu
, regexp_replace (regexp_replace (regexp_replace(strC||':','\d+B:'),' A:$ '), ':', ',') as strA
, regexp_replace (regexp_replace (regexp_replace(strC||':','\d+A:'),' B:$ '), 'B:', ',') as strB
;SPERCU STRA, STRB
---------------- -------- ------
1 B: 5 A: 12 A: B: 43 3A 1.3 5,12,43or
declare
varA varchar2 (30);
varB varchar2 (30);
varC varchar2 (30): = ' 1 B: 5 A: 12 A: B: 43 3A;
Start
varA: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+B:'),' A:$ '), ':', ',');
varB: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+A:'),' B:$ '), 'B:', ',');
dbms_output.put_line (Vara);
dbms_output.put_line (varB);
end;
anonymous block filled
5,12,43
1, 3Replace it after you add a trailing colon varC, Interior removes all the ' nB: "Vara and all the" nA: "from varB. The Middle replace deletes the pair of colon final letter, and replace external converts the other pairs of commas leter-colon.
Kind regards
Bob -
Cannot use the variable in the Interface.
Hello
I create a variable in the reference to 11g odi below
V_name = FTClient
DataType = alphanumeric
default value = "BANK 1"
I create a filter on the source table to pull records only for 1 BANK and talk CELL_SRC_TBL1. CLIENT = #FTClient in the filter.
But when I try to execute its error display interface.
"Caused by: java.sql.SQLSyntaxErrorException: ORA-00936: lack of expression.
Thank you
Paul
You use ODI 11? If so the name of the variable must bee all uppercase and when you pass too!
I hope this can help you!
Maybe you are looking for
-
How can I cancel scribd? I signed on iTunes for 1 month free, paid for 1 month more, now want to cancel before billing today.
-
Satellite U400 - after update BIOS lighting lights
Since the update the BIOS on my U400-15E (Vista 32), lighting of the multimedia keys, touchpad always turn after the restart, recovery from the sleep or Hibernate. Touch the illuminance on the off button once does that second touch them will turn off
-
Update on Satellite S70-B-10N wireless card
Hello Just got a laptop above this morning and I would like to upgrade the card wireless inside an AC7260 module. There is a significant lack of documentation on the inside of this laptop with no info on youtube either. Research on Amazon there are s
-
loop for doesn't loop in table built from worksheet
I'm probably doing sonthing but really stupid... first I build and table of data in a worksheet (RefLookup) the spreadsheet contains 3 rows above the row is my label (getting by) the second row it my face value the third row is my minimum value. REF
-
How to block a resolution of the screen
I am running Windows Vista Home Premium. At the beginning of Yahoo Instant Messenger, it automatically changes the screen resolution from 32 bit to 8-bit, making images photographic look terrible. Can I change the resolution of the screen in 32 bit