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

Tags: Database

Similar Questions

  • A query on bind variables

    Hello

    I have a procedure that takes the deptno parameter and inserts that records departments of the table emp for the new table.

    This code does not exist in a real system. I was trying to understand that the advantage of linking variable.i he wrote in different ways as below
    Create table emp3 as select * from emp where 1=2;
    
    create or replace procedure test1 (p_deptno in number)as 
    begin
     execute immediate 'insert into emp3
                                   select *
                                   from emp
                                   where deptno=:1'
                                   using p_deptno;
    end;
    The works fine.i code above writes the following much too.

    create or replace procedure test2 (p_deptno in number)as 
    begin
     insert into emp3
          select *
          from emp
          where deptno=p_deptno;
    end;
    the first no matter what performance benefit over the second one that is the right way to do it in a real-world system?
    . I could not do a comparison of performance because I don't have access to a currently oracle instance and did it in workshop SQL that comes with Apex.My apology for this...

    Kind regards
    CKLP

    Published by: CKLP on August 29, 2011 03:21

    CKLP wrote:

    the first no matter what performance benefit over the second one that is the right way to do it in a real-world system?

    Not really. Do not forget that all interpreted SQLs winds up as sliders to the sharing of the database Pool.

    If a cursor exists already for a SQL statement, SQL will reuse this slider existing (soft parser). So in a SQL engine perspective, there is no different between the two methods. These statements will be btw generate the same cursor SQL - code SQL of base and bind variable positions are identical.

    From a PL/SQL's point of view, there is a huge difference.

    The first option may be a little slower. Why? There he uses the immediate execution interface which is not as optimized as the implicit cursor to the PL/SQL interface. You use a "heavier" SQL interface in PL/SQL which results in more work for the PL/SQL engine.

    The second option is compiled in an implicit cursor. The SQL code is known, controlled and checked, and compiled PL/SQL code deals with a known SQL statement. Unlike the first option.

    The second option also means that your code will not fail (because SQL syntax errors, etc.) currently running. If this static SQL statement in your code is no longer valid (due to a table being deleted, used column removed, etc.), then your code becomes invalid. With the first option, the code remains valid - and when it is executed, it will throw an exception that the (dynamic) SQL cannot be analyzed and that it is not valid.

    The first option also introduces the spectrum of a SQL injection. Let's say that there is a way to cause a buffer overflow exploit in the database call that executes this procedure. The SQL itself is a string, it is an easy attack vector as the overflow needs that data of type string to inject executable code - as opposed to the p-code or machine code. (an unlikely scenario, but the basic principle of security remains true)

    Dynamic SQL is unnecessary for 99% of the time in PL/SQL. And 99% of the time, with the help of the dynamic SQL is for the wrong reasons, or ignorance or both.

  • Using Bind Variable in a SELECT statement

    Hello

    I am trying to build my SQL query running using bind variables and in Oracle® Fusion Middleware Fusion developer Guide for Oracle Application Development Framework 11 g Release 1 (11.1.1) it is said that ' after you define bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows you to bind variables to appear in the SELECT list and in the WHERE clause, you'll generally use them in this context, as part of your WHERE clause. ».

    However, when I try to use bind variables in my SELECT list because I had set a type to the string of the variable variable is inserted with quotes each side for example SELECT TestTable FROM 'Service '. Is it possible to use bind variables to insert a value in my list of selection without the quotes around it?

    Thanks in advance,
    Tom

    Hi Robinst,

    I think you want to set up column name of the table that is not possible using bind variables. With the help of the bind variables you can send a value to the SQL. The String value is therefore always with inverted commas.

    Kind regards

    Branislav

  • Production of a file delimited by pipes using SQL * more

    This script

    the colsep value ' |'
    coil outfile.lst
    Select fname, lastname, midinit mytab;
    spool off

    produced this outfile.lst

    John | DOE | A
    Richard | RAO | B

    In other words, it protects the names containing spaces up to the width of the column, 9 characters, even if the data is of type varchar.

    I would like to get fields of variable length, without filling, like this

    John | DOE | q
    Richard | RAO | x

    Can I do this in SQL * more by setting system variables or the order of the COLUMN?

    -Chris Curzon

    Hello

    Christopher Curzon wrote:
    ...
    I would like to get fields of variable length, without filling, like this

    John | DOE | q
    Richard | RAO | x

    Can I do this in SQL * more by setting system variables or the order of the COLUMN?

    Sorry, no.
    You need to do something like this

    COLUMN  one_huge_column  FORMAT A1000
    SET     LINESIZE   1000
    SET     TRIMSPOOL  ON
    
    SPOOL   outfile.lst
    
    SELECT  fname
            || '|' || lastname
            || '|' || midinit   AS one_big_column
    FROM    mytab;
    
    SPOOL   OFF
    

    If SQL * Plus allows 10 places for fname, then fname is completed to occupy the space 10, so that the results look nice when appear it on your screen.
    Above, SQL * Plus allows to 1000 places for one_big_column, but the extra padding is away TRIMSPOOL it prevent to be written to the file.

  • Question on the PL/SQL and substitution of variables

    Good evening

    I just started studying the PL/SQL (currently at page 13 of the book), I typed the following example from the book:
    declare
      v_student_id          number          := &sv_student_id;
      v_first_name          varchar2(35);
      v_last_name           varchar2(35);
    
    begin
      select first_name,
             last_name,
        into v_first_name,
             v_last_name
        from student
       where student_id = v_student_id;
    
    
      dbms_output.put_line('Student name : ' || v_first_name || ' ' v_last_name);
    
      exception
        when no_data_found then
          dbms_output.put_line('There is no such student');
    end;
    /
    that gets me the following error:
    SP2-0552: Bind variable "SV_STUDENT_ID" not declared.
    I thought that SQL * more would invite me for a value to be substituted for SV_STUDENT_ID but it does not, that caused the error. Why has no SQL * more invite me for the value of SV_STUDENT_ID and what is the correct way to do it than the code above?

    Thank you for your help,

    John.

    As a result, DDL for STUDENT table:
    CREATE TABLE STUDENT
     (STUDENT_ID NUMBER(8,0)
     ,SALUTATION VARCHAR2(5)
     ,FIRST_NAME VARCHAR2(25)
     ,LAST_NAME VARCHAR2(25)
     ,STREET_ADDRESS VARCHAR2(50)
     ,ZIP VARCHAR2(5)
     ,PHONE VARCHAR2(15)
     ,EMPLOYER VARCHAR2(50)
     ,REGISTRATION_DATE DATE
     ,CREATED_BY VARCHAR2(30)
     ,CREATED_DATE DATE
     ,MODIFIED_BY VARCHAR2(30)
     ,MODIFIED_DATE DATE
     )
    /

    You had a few syntax errors (lines 7 and 12), but after their attachment, your code worked for me:

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_student_id          number          := &sv_student_id;
      3    v_first_name          varchar2(35);
      4    v_last_name           varchar2(35);
      5  begin
      6    select first_name,
      7           last_name
      8      into v_first_name,
      9           v_last_name
     10      from student
     11     where student_id = v_student_id;
     12    dbms_output.put_line('Student name : ' || v_first_name || ' ' || v_last_n
    ame);
     13    exception
     14      when no_data_found then
     15        dbms_output.put_line('There is no such student');
     16* end;
    SQL> /
    Enter value for sv_student_id: 1
    old   2:   v_student_id          number          := &sv_student_id;
    new   2:   v_student_id          number          := 1;
    
    PL/SQL procedure successfully completed.
    

    Did you happen to define set off?

    SQL> show define
    define "&" (hex 26)
    
    SQL> set define off
    SQL> /
    SP2-0552: Bind variable "SV_STUDENT_ID" not declared.
    SQL> set define on
    SQL> /
    Enter value for sv_student_id: 1
    old   2:   v_student_id          number          := &sv_student_id;
    new   2:   v_student_id          number          := 1;
    
    PL/SQL procedure successfully completed.
    

    Published by: Andy Klock on August 11, 2010 18:13 (sorry, line 7 means there was an error not 9...)

  • How to get SQL that do not use bind variables

    Hello

    I am trying to identify the SQL code which should benefit from the use of bind variables.
    First of all, I tried to get the common signature of all the sql calls, using:
    select * from (
    select  force_matching_signature, count(1) from v$sql where force_matching_signature<>0 group by force_matching_signature order by 2 desc
    ) where rownum < 50;
    Then I copied these values to the Clipboard and run:
    select sql_text from v$sql where force_matching_signature=<<<copied_signature_value>>>;
    Now, I want to make it automatically and get only 1 occurrence of each SQL that resembles others by using a query.

    I tried this:
    select sql_text from
    (
    select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc)rn from v$sql where force_matching_signature <>0
    )where rn <2 and rownum < 10 order by force_matching_signature desc
    But it is not returning results by showing up at the count (1) from the first query, I've used. How can I change this if I get the results in order of "importance"?




    Thank you

    And I said. First use the command by then use rownum. I did not mention row_number. Also, there should be no need to add more columns.
    Have you tried it? Why it did not work?

    example not tested

    select * from (
       select sql_text from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn from v$sql where force_matching_signature != 0)
       where rn = 1
       order by force_matching_signature desc /* add any ordering you like here */
       )
    where rownum < 10  /* then filter on the first 10 results */
    

    If you want to order that the statement that found most of the time comes first, say so. However, I don't see how to group in your case.
    Maybe like this

    example of tested

    select * from (
       select cnt, sql_text
       from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn , count(*) over (partition by force_matching_signature) cnt
             from v$sql
             where force_matching_signature != 0)
       where rn = 1
       order by cnt desc, force_matching_signature desc /* add any ordering you like here */
       )
    where rownum < 10  /* then filter on the first 10 results */
    ;
    

    Published by: Sven w. October 11, 2012 14:49

    Published by: Sven w. October 11, 2012 14:51

    Published by: Sven w. on October 11, 2012 14:56 - number column added to the output

  • The use of bind variables (in &amp; out) with sql dynamic

    I have a table that contains code snippets to make postings on a set of pl/sql database. what the code does is basically receives an ID and returns a number of errors found.
    To run the code, I use dynamic sql with two bind variables.

    When codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;
    However when I get to post more complexes that must perform calculations or run several queries I run into trouble.
    I have boiled down the problem into that:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare 
             some_var number;
          begin
          
          select 1 into some_var from dual
          where :2 = 61; 
          
          :1 := :2;
          end;
    ')
          USING OUT counter, IN my_id;
    
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;
    This code is not really make sense, but it's just to show you what is the problem. When I run this code, I get the error
    ORA-6537 ON bind variable linked to a position IN

    The error doesn't seem wise,: 2 is the only one IN bind variable and it is only used in a where clause clause.
    As soon as I remove this where clause, the code works again (giving me 61-61, in case you want to know).

    Any idea what goes wrong? I just use bind variables in a way that you're not supposed to use it?

    I'm using Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit

    Correction. With immediate execution , the binding is in position, but binds do not need to be repeated. My statement above is incorrect...

    You must link only once - but bind by position. And the connection must correspond to the use of the variable binding.

    If the connection never variable assigns a value in the code, link by in.

    If the binding variable assigns a value in the code, link as OUTPUT.

    If the binding variable assigns a value and is used a variable in another statement in the code, link as IN OUT.

    For example

    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
     10                  1 into n
     11          from dual
     12          where :var1 = 61;       --// var1 is used as IN
     13
     14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
     15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
     16  end;
     17  '
     18          using
     19                  in out id, in out cnt;  --// must reflect usage above
     20
     21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
     22  end;
     23  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Use the bind variable in example of a clause giving questions

    create or replace procedure pr_mbk (p_val in number)
    is
    CROR type is ref cursor;
    REF CROR;
    type numbertype is the table of index number of pls_integer;
    numtype numbertype.
    v_str varchar2 (2000): = 'select empno from emp sample(:val) ";
    Start
    Open ref for v_str using p_val;
    Close ref;
    end;
    /

    Successfully compiled.

    But when I run the same

    Exec pr_mbk (10);

    ERROR on line 1:
    ORA-00933: SQL not correctly completed command.
    ORA-06512: at "SCOTT. PR_MBK', line 9
    ORA-06512: at line 1

    My question is can use us Bind variables within a sample clause.

    Receive your answer.

    Thank you
    Madhu K.

    I guess that SAMPLE is considered as a special case, and is not considered as something that takes a 'value' in the same way as values in where clause or values in the query itself.
    Let's face it, the SAMPLE is not the standard SQL syntax and is probably something Oracle implements in a separate thread for processing SQL itself i.e. engine Oracle saying to herself... "I will remember this bit of the sample until I questioned the data using the SQL engine, so I'll take a suitable sample of the results," but it's the SQL engine treats the binding of values and the Oracle process that awaits the results taste, knows nothing of the binding values in it's special EXAMPLE of keyword.

  • Windows system environment variables in "Sql * more»

    Can I use/reference of Windows system environment variables in "Sql * more?
    For example, I want to create sql-script runs in the database server computer that variable is "ORA_HOME", uses this value to perform a few sentences of sql/plsql.

    Oracle 10g personal, Windows 7.

    Edited by: CharlesRoos the 12.11.2010 17:28

    CharlesRoos wrote:
    The business problem:
    I created 2 databases in my computer. The two databases needs storage created by a script. The names of data files (.dbf files) of storage are the same for the two database. The two database has its own directory, where it holds data for the moment files. At the moment the data files for Database1 are in the folder something like '% ORACLE_HOME%"\oradata\%databasename1%\*.dbf and the second base of data has its data files in the other folder, somewhere '' % ORACLE_HOME%"\oradata\%databasename1%\*.dbf'. Now I want the script to create the tablespace called "INDX" with the same data file name "indx1.dbf" in the two database. If in the two documents mentioned the 'indx1.dbf' file must be created by the script. I think the script must do following:

    1. get ORACLE_HOME.
    2. connect to database "databasename1"
    3. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename1 || indx1.dbf"
    4. connect to database "databasename2"
    5. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename2 || indx1.dbf"
    

    I don't have database Oracle close more, if the code was pseudo-code.

    ---

    I do not understand how to use?-shortcut.

    OK, my first impression is ' why must even be scripted? Creation of new spaces of storage is usually a one-off operation.

    But what side this substitution of sqlplus command line variables. This example is Linux, but works on Windows with the change in the way environment variables are referenced:

    * echo nix - $myvariable
    Windows - echo myvariable %

    First of all, sqlscript to create the TS. Note the use of the substitution variable '& 1 '.
    {code}
    [oracle@vmlnx01 ~] $ cat makets.sql cat
    set echo on the comments on check on trimsp on
    Guest & 1
    --
    CREATE TABLESPACE EDSTEST PETIT_FICHIER
    DATAFILE ' / ora01/oradata/&1/edstest.dbf'
    SIZE 5 M
    REUSE
    AUTOEXTEND ON
    NEXT 1280K
    MAXSIZE 32767M
    LOGGING
    LOCAL MANAGEMENT MEASURE
    SEGMENT SPACE MANAGEMENT AUTO
    ;
    --
    Drop tablespace edstest
    including content and data files
    ;
    output
    {code}

    Thus, the OS invites: note that the @ is separated by a space, which makes a parm from command line instead of the part of the connection string

    {code}
    [oracle@vmlnx01 ~] $ export myparm = vlnxora1
    [oracle@vmlnx01 ~] $ sqlplus system/pswd @makets $myparm

    SQL * more: Release 10.2.0.4.0 - Production on Fri Nov 12 18:13:05 2010

    Copyright (c) 1982, 2007, Oracle. All rights reserved.

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With partitioning, OLAP, Data Mining and Real Application Testing options

    SQL > prompt & 1
    vlnxora1
    SQL >--
    SQL > CREATE TABLESPACE EDSTEST PETIT_FICHIER
    2 DATAFILE ' / ora01/oradata/&1/edstest.dbf'
    3 SIZE 5 M
    4 REUSE
    5 AUTOEXTEND ON
    6. THE NEXT 1280K
    7 MAXSIZE 32767M
    8 LOGGING
    MEASURE 9 LOCAL MANAGEMENT
    10 SEGMENT SPACE MANAGEMENT AUTO
    11;
    2 old: DATAFILE ' / ora01/oradata/&1/edstest.dbf'
    2 new: DATAFILE ' / ora01/oradata/vlnxora1/edstest.dbf'

    Created tablespace.

    SQL >--
    SQL > drop tablespace edstest
    2 content and data files including
    3;

    Tablespace has fallen.

    SQL > exit
    Disconnected from the database to Oracle 10 g Enterprise Edition Release 10.2.0.4.0 - Production
    With partitioning, OLAP, Data Mining and Real Application Testing options
    [oracle@vmlnx01 ~] $
    {code}

  • Convert SQL to take advantage of the Bind Variables

    Hi all

    Is it possible to convert the SQL below so I can enjoy variable Bind?  It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...

    ACCEPT script_name_like prompt 'ENTER SCRIPT NAME OR HIT ENTER TO GET ALL SCRIPT NAME OR PUT PART OF THE SCRIPT NAME : ' 
    WITH help_script AS
    ( SELECT 'top_seg_tab_obj_ash'                    AS Script_Name,
                        'top segment by tot wait time' AS Description,
                        '# of mins to go back'            AS INPUT
       FROM dual  
      UNION ALL SELECT 'v$_tab'                    AS Script_Name,
                        'shows list v$ views' AS Description,
                        'view name like'            AS INPUT
       FROM dual
      UNION ALL SELECT 'dba_tab'                    AS Script_Name,
                        'shows list dba views' AS Description,
                        'view name like'            AS INPUT
       FROM dual
      UNION ALL SELECT 'nls_params'                    AS Script_Name,
                        'shows list of current NLS setting for DB/INST/SESS' AS Description,
                        'no Input Needed'            AS INPUT )
    SELECT upper(script_name) AS "MY SCRIPT NAME",
           upper(description) AS description,
           upper(INPUT) AS INPUT
    FROM help_script
    WHERE script_name LIKE nvl('%&script_name_like%', script_name) ;
    

    Hello

    user13454469 wrote:

    Hi all

    Is it possible to convert the SQL below so I can enjoy variable Bind?  It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...

    1. ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '
    2. WITH help_script AS
    3. (SELECT "top_seg_tab_obj_ash" AS Script_Name,
    4. "upper segment by tot queue time" AS Description,.
    5. "# of minutes to go back" AS INPUT
    6. OF the double
    7. UNION ALL SELECT ' v$ _tab "AS Script_Name,.
    8. "Show list views$ v ' AS Description,.
    9. 'show the name as' AS ENTRY
    10. OF the double
    11. UNION ALL SELECT 'dba_tab' AS Script_Name,
    12. "Show list views dba" AS Description,.
    13. 'show the name as' AS ENTRY
    14. OF the double
    15. UNION ALL SELECT 'nls_params' AS Script_Name,
    16. 'displays the list of current NLS parameter for DB/INST/SESS' AS Description,.
    17. ("No input is necessary" IN ENTRY)
    18. SELECT upper (script_name) AS "MY SCRIPT NAME",
    19. Upper (Description) as a description,
    20. Upper (Input) AS INPUT
    21. OF help_script
    22. WHERE script_name AS nvl (script_name ' % & script_name_like %',);)

    The WHERE clause (last line) of is the only place where you are using the proxy & script_name_like?  If so:

    -ACCEPT command is exactly the same as before

    ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '

    VARIABLE script_name_like_b VARCHAR2 (30)

    EXEC: script_name_like_b: = '% & script_name_like;

    WITH the help _script AS

    ...

    WHERE script_name AS NVL (: script_name_like_b, script_name);

  • problem with bind variables in the SQL query view object

    Hi all

    I use JDev 11.1.2.4.0.

    I have a problem with bind variables in the SQL query view object.

    This is my original SQL

    SELECT sum(t.TIME) , t.legertype_id
    FROM LEDGER t
    WHERE t.nctuser_id = '20022' 
          AND to_char(t.insertdate,'YYYYMMDD') in ('20130930','20130929')
    group by t.legertype_id
    

    In my view .xml object query tab, I am writing this

    SELECT sum(t.TIME) , t.legertype_id
    FROM LEDGER t
    WHERE   t.nctuser_id = '20022'
        AND to_char(t.insertdate,'YYYYMMDD') in :dddd
    group by t.legertype_id
    

    Davis here is a variable of Type liaison: String, updatable and necessary.

    I try to deal with Davis as ('20130930 ', ' 20130929') hoping the view object, run as my original SQL.

    But failed. The view object retrieves 0 line after that I run.

    Why?

    Thank you! ('2original SQL0130930', '20130929') ('20130930 ', ' 20130929')

    A variable binding cannot be used as this is why you must use years table. Check decompilation binary ADF: using oracle.jbo.domain.Array with ViewCriteria to see a solution.

    Timo

  • How to pass a list as a bind variable in SQL Developer?

    How can I pass a list as a bind variable in SQL Developer?

    The following query in SQL Developer so work I put ": prmRegionID = 2.

    SELECT COUNTRY_ID,
    COUNTRY_NAME
    OF HUMAN RESOURCES. COUNTRY
    WHERE IN REGION_ID (: prmRegionID);

    The problem is that I can't find how to set ": prmRegionID = 2, 3.

    I know that I can replace ": prmRegionID" by a proxy '& prmRegionID '. The above query will work well with"& prmRegionID = 2" and with "& prmRegionID = 2, 3". "

    But with this solution, I lost all the benefit of the use of bound variables (analysis hard against soft parse, possibility of SQL injection, etc.).

    I'm learning how to do this in SQL, as well as the use of UDT in this thread: How to move a list as a bind variable?

    But with this solution, I've lost nice SQL Developer user interface. In SQL developer, it is easy to test a query using the standard binding variable. When we start the application, a pop up asking for a value of the variable binding.

    With the UDT, the interface request always variable binding standard. You have an idea on how I can get a variable string binding (such as 1, 2, 10) in a set of NUMBER or VARCHAR2? This way I would be able to launch a standard query in SQL Developer to test my application.


    Can someone tell me what is the best approach to this?

    Thank you in advance,


    MB

    Hi Blais,

    Thank you for trying the SQL and PL/SQL instance before coming here - it was definitely the right approach, and you've got some very good suggestions there. Your needs for a invite only bind to the value in the clause list, I think I have a possible solution. I'll introduce you to a list of characters, so you'll have to tweak it for other types of data. First, add the following to your schema:

    create or replace
    TYPE bind_tab_typ AS TABLE OF VARCHAR2(4000);
    
    create or replace
    FUNCTION comma_to_table(iv_raw IN VARCHAR2)
    RETURN bind_tab_typ
    PIPELINED
    IS
       ltab_lname dbms_utility.lname_array;
       ln_len     BINARY_INTEGER;
    BEGIN
       dbms_utility.comma_to_table(list   => iv_raw
                                  ,tablen => ln_len
                                  ,tab    => ltab_lname);
       FOR i IN 1 .. ln_len LOOP
          PIPE ROW (ltab_lname(i));
       END LOOP;
    END;
    

    Now you can write a query, say for scott.dept, as follows, and have executed statement ask the value list in the clause as a single binding variable:

    select *
    from dept
    where dname in (
      select * from table( comma_to_table( :BNDS ))
    );
    

    When you are prompted, provide the list of values separated by a single comma without any extra spaces.

    I don't know if the Varchar2 (4000) really needs to be which is great. I use it because that's what dbms_utility.lname_array uses.

    Kind regards
    Gary
    SQL development team

  • SQL Bind Variables workshop - Date issues

    I use SQL Workshop to run through some queries. I'm having a problem with Bind Variables that contain dates. I enter the following date:

    12/12/2013

    but it is converted to:

    12 & amp; #x2F 12 & amp; #x2F; 2013

    I'm doing something wrong?

    Thank you
    Glen

    It looks like a bug. It should not escape what either.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Apress.com/9781430235125
    http://Apex.Oracle.com/pls/Apex/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

  • Get the bind variables name string SQL or the cursor

    Hello

    Is there way to get of the bind variables name string SQL or the cursor?

    Example of
    DECLARE
      l_sql VARCHAR2(2000);
      desctab DBMS_SQL.DESC_TAB;
      curid   PLS_INTEGER;
    BEGIN
    
      l_sql := 'SELECT * FROM emp WHERE mgr = :X and deptno = :Y';
    
      curid := dbms_sql.open_cursor;
      dbms_sql.parse(curid, l_sql, dbms_sql.NATIVE);
      ....
    END;
    What I mean with the SQL string:
    I love to get using some functions from above code variable l_sql all the bind variable.
    In this case the function should return array where is for example: X and: Y

    Back to bind the cursor variable names, I mean same but rather string I pass number of cursor.

    Y at - it sucks ready function or some may share a code customized for this purpose?

    Thanks

    Kind regards
    Jari

    http://dbswh.webhop.NET/dbswh/f?p=blog:Home:0Regards,

    Published by: jarola December 19, 2011 02:44

    I found there are wwv_flow_utilities.get_binds of the function not documented in APEX packages that do what I want.
    Usage example
    set serveroutput on
    DECLARE
      binds DBMS_SQL.varchar2_table;
    BEGIN
      binds := wwv_flow_utilities.get_binds('select :P1_TEST from dual');
      FOR i IN 1 .. binds.count
      LOOP
        dbms_output.put_line(binds(i));
      END LOOP;
    END;
    /
    
    anonymous block completed
    :P1_TEST
    But I would not use these functions without papers as those who can change or there is no future versions APEX.
    Is there a documented function or the custom function that do the same thing as wwv_flow_utilities.get_binds?

    Some old basic example code of my friends. Also the media getting the bind variable of PL/SQL code blocks anon.

    SQL> create or replace function GetBindVariables( statement varchar2 ) return TStrings is
      2          --// bind variables names are terminated by one the following special chars
      3          SPECIAL_CHAR    constant TStrings := TStrings(' ',')','+','-','>','<','*',',','=',';',CHR(10),CHR(13));
      4
      5          --// max size of a bind var name
      6          MAX_VARSIZE     constant integer := 100;
      7
      8          pos     integer;
      9          pos1    integer;
     10          occur   integer;
     11          varName varchar2(100);
     12          varList TStrings;
     13  begin
     14          varList := new TStrings();
     15
     16          --// looking for the 1st occurance of a bind variable
     17          occur := 1;
     18
     19          loop
     20                  pos := InStr( statement, ':', 1, occur );
     21                  exit when pos = 0;
     22
     23                  varName := SubStr( statement, pos, 100 );
     24
     25                  --// find the terminating char trailing the
     26                  --// bind variable name
     27                  pos1 := Length( varName );
     28                  for i in 1..SPECIAL_CHAR.Count
     29                  loop
     30                          pos := InStr( varName, SPECIAL_CHAR(i) ) - 1;
     31                          if (pos > 0) and (pos < pos1) then
     32                                  pos1 := pos;
     33                          end if;
     34                  end loop;
     35
     36                  --// extract the actual bind var name (without
     37                  --// colon char prefix)
     38                  varName := SubStr( varName, 2, pos1-1 );
     39
     40                  --// maintain a unique list of var names
     41                  if not varName member of varList then
     42                          varList.Extend(1);
     43                          varList( varList.Count ) := varName;
     44                  end if;
     45
     46                  --// look for the next occurance
     47                  occur := occur + 1;
     48          end loop;
     49
     50          return( varList );
     51  end;
     52  /
    
    Function created.
    
    SQL>
    SQL> select
      2          column_value as BIND_VAR
      3  from TABLE(
      4          GetBindVariables('select * from foo where col=:BIND1 and day = to_date(:B2,''yyyy/mm/dd'')')
      5  );
    
    BIND_VAR
    ------------------------------
    BIND1
    B2
    
    SQL> 
    

    PS. just realize this code is case-sensitive, while variable bind is not. Should throw a upper() or lower() by adding the name of the var to the list - never really a problem for me because I'm pretty tense when it use cases correctly in the code. ;-)

    Published by: Billy Verreynne, December 19, 2011 06:19

  • VO with bind variable defined in SQL is not updated correctly

    Hi Experts,

    I have a simple question here, could you please help answer? Thank you very much!

    I have 2 pages, the first page displays an employee table, the second page shows a few details to the selected employee. When to choose a single employee and click the details button I can be naviaged to the second page and see the details for the selected employee. The vo used on the second page uses a connection variable called "empId" thing for a 'adf.context.pageFlowScope.empId' pageFlowScope value, and this value pageFlowScope will be filled to the empId selected detail button actionListener during execution).

    The question is, now first navigation is ok, the details of the page can display the correct information for the employee selected on the page of the employee, but when browsing back and choosing another employee, and then again click the details button, the details of the page is NOT updated, it still shows the initial information for the selected employee. I debug the actionListener in support bean and the second selected empId passed to pageFlowScope.empId, the link in the t variable should get the new value, right? But why the second page gets no updates (request using the new value of the bind variable)?

    Thank you!

    Published by: user774592 on July 20, 2011 23:13

    Published by: user774592 on July 20, 2011 23:15

    Published by: user774592 on July 20, 2011 23:15

    In theory, if you expose specific objects of customer to your business (for example pageflowscope) service layer, you may miss 1. test driven development assistance (case of unit test can fail) 2. Customer service of independent business etc... :)
    To respond to your request try to call TargetPagesVO.execute () before the second page (by program or activity method)

Maybe you are looking for

  • Cannot start my Qosmio X 70-A-11R

    Hello My problem is: While playing CoD ghosts my X 70 closed and now I have the problem that I can not restart it.Nothing works, the only thing that works is the power LED. The X 70 is 2 days, so I can't believe that something is too dirty or somethi

  • can I back up and restore on the same beta software

    I want to restore my iphone 6 to solve some problem, but I'm on the iOS 9.3 public beta 4 and I don't know if I am able to back up and restore to the same beta version. My problem is not related to the beta software and I don't want to go down, I wan

  • Tecra M5 hangs during the shutdown process

    Thanks to those who responded to my query. With your advice, I have now uninstalled Norton Ghost - and the problem disappeared, my machine now stops, goes to sleep and Hibernate properly and wakes up again properly. The next question to consider is w

  • officelivesigin.exe:causing a lot of mistakes

    How to stop the officesignin.exe dialog box popping up when I close applications or send information.

  • Portal of the point 8 WC

    using the portal 11.1.1.8In JDEV 11.1.17 we installed updates from the help-> Check Update webcenterWe will open a page template in Jdev. Under ADF Faces component palette, we try to see "SpacesDeclarativeComponent" but we're just not finding it. Why