Varchar2 variable in Forms_DDL

hi
I need to refer to a varchar2 variable within a forms_ddl call e.g
declare
myvar varchar2(10) ;
begin
forms_ddl ('create or replace view myview as
select * from emp where job = myvar');
end;
how do I make forms_ddl know the value in myvar? I have tried -- job = ' ||myvar||''); and I get ORA-936 missing expression.
anybody know the solution please help. NB I dont want to hardcode the value of myvar!
Mbachi

Hello
Probably, you are missing quotations. If the "JOB" is a varchar2 column, then make it
forms_ddl('create or replace view myview as select * from emp where job = '||''''||myvar||'''');
This should work, if you still get some problems then get back to me at [email protected]
Regards,
Asif Momen.

Similar Messages

  • Error reading data from CLOB column into VARCHAR2 variable

    Hi all,
    Am hitting an issue retrieving data > 8K (minus 1) stored in a CLOB column into a VARCHAR2 variable in PL/SQL...
    The "problem to be solved" here is storing DDL, in this case a "CREATE VIEW" statement, that is longer than 8K for later retrieval (and execution) using dynamic SQL. Given that the EXECUTE IMMEDIATE statement can take a VARCHAR2 variable (up to 32K(-1)), this should suffice for our needs, however, it seems that somewhere in the process of converting this VARCHAR2 text to a CLOB for storage, and then retrieving the CLOB and attempting to put it back into a VARCHAR2 variable, it is throwing a standard ORA-06502 exception ("PL/SQL: numeric or value error"). Consider the following code:
    set serveroutput on
    drop table test1;
    create table test1(col1 CLOB);
    declare
    cursor c1 is select col1 from test1;
    myvar VARCHAR2(32000);
    begin
    myvar := '';
    for i in 1..8192 loop
    myvar := myvar || 'a';
    end loop;
    INSERT INTO test1 (col1) VALUES (myvar);
    for arec in c1 loop
    begin
    myvar := arec.col1;
    dbms_output.put_line('Read data of length ' || length(myvar));
    exception when others then
    dbms_output.put_line('Error reading data: ' || sqlerrm);
    end;
    end loop;
    end;
    If you change the loop upper bound to 8191, all works fine. I'm guessing this might have something to do with the database character set -- we've recently converted our databases over to UTF-8, for Internationalizion support, and that seems to have changed underlying assumptions regarding character processing...?
    As far as the dynamic SQL issue goes, we can probably use the DBMS_SQL interface instead, with it's EXECUTE procedure that takes a PL/SQL array of varchar2(32K) - the only issue there is reading the data from the CLOB column, and then breaking that data into an array but that doesn't seem insurmountable. But this same basic issue (when a 9K text block, let's say, turns into a >32K block after being CLOBberred) seems to comes up in other text-processing situations also, so any ideas for how to resolve would be much appreciated.
    Thanks for any tips/hints/ideas...
    Jim

    For those curious about this, here's the word from Oracle support (courtesy of Metalinks):
    RESEARCH
    ========
    Test the issue for different DB version and different characterset.
    --Testing the following PL/SQL blocks by using direct assignment method(myvar := arec.col1;) on
    different database version and different characterset.
    SQL>create table test1(col1 CLOB);
    --Inserting four CLOB data into test1.
    declare
    myvar VARCHAR2(32767);
    begin
    myvar := RPAD('a',4000);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('a',8191);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('b',8192);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('c',32767);
    INSERT INTO test1 (col1) VALUES (myvar);
    commit;
    end;
    --Testing the direct assignment method.
    declare
    cursor c1 is select col1, length(col1) len1 from test1;
    myvar VARCHAR2(32767);
    begin
    for arec in c1 loop
    myvar := arec.col1;
    --DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar);
    dbms_output.put_line('Read data of length: ' || length(myvar));
    end loop;
    end;
    The following are the summary of the test results:
    ===================================
    1. If the database characterset is WE8ISO8859P1, then the above direct assignment
    method(myvar := arec.col1;) works for database version 9i/10g/11g without any
    errors.
    2. If the database characterset is UTF8 or AL32UTF8, then the above direct assignment method(myvar := arec.col1;) will generate the "ORA-06502:
    PL/SQL: numeric or value error" when the length of the CLOB data is greater
    than 8191(=8K-1). The same error can be reproduced across all database versions
    9i/10g/11g.
    3. Using DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar) method to read CLOB data into a VARCHAR2 variable works for both WE8ISO8859P1 and UTF8
    characterset and for all database versions.
    So - it seems as I'd surmised, UTF8 changes the way VARCHAR2 and CLOB data is handled. Not too surprising, I suppose - may you all be lucky enough to be able to stay away from this sort of issue. But - the DBMS_LOB.READ workaround is certainly sufficient for the text processing situations we find ourselves in currently.
    Cheers,
    Jim C.

  • What's the maximum size a varchar2  variable can hold for and NDS Stmnt?

    What's the maximum size a varchar2 variable can hold for and NDS Statement? I read that NDS is good for doing EXECUTE IMMEDIATE on statements that aren't too big. The 10g PL/SQL manual recommends using DBMS_SQL for statements that are too large, but it never gave a limit for what too large was. Does anyone know offhand?

    The limit is the same as the length of varchar2 variable within PL/SQL - that is varchar2(32767).It's not documented, but intermediate concatenation result can hold up to (64k-1) :
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    declare
      part1 varchar2(32767) := rpad('begin null;', 32767);
      part2 varchar2(32767) := lpad('end;',        32767);
    begin
      dbms_output.put_line(length(part1 || ' ' || /*' ' ||*/ part2));
      execute immediate part1 || ' ' || part2;
    end;
    65535
    PL/SQL procedure successfully completed.

  • Passing PL/SQL varchar2 variable to XML Query

    Hi guys,
    i'm having trouble passing a pl/sql varchar2 variable to an XMLQuery.
    This is the relevant part of my code:
    DECLARE
       lo_result   XMLTYPE;         --contains the XML which is being parsed below
       lo_return   XMLTYPE;             -- for the XML result returned by XMLQuery
       lo_start    VARCHAR2 (100) DEFAULT 'Toronto'; -- a PL/SQL varchar2 variable
       lo_end      VARCHAR2 (100) DEFAULT 'Ottawa';  -- a PL/SQL varchar2 variable
    BEGIN
       SELECT XMLQUERY (
                 'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
                 PASSING lo_result, lo_start AS "lo_start", lo_end AS "lo_end"
                 RETURNING CONTENT)
         INTO lo_return
         FROM DUAL;
    END;The XPath expression is correct but it doesn't seem to accept my variables since lo_return is empty.
    I think the variables should be of type Xmltype but the compiler won't let me convert them because they do not contain any XML tags .
    Hope anyone can help.
    Thanks,
    Martina

    may be i missed anything but
    >
    <start_address>Toronto, Ontario, Kanada</start_address>
    <end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
    >
    and
    >
    lo_start VARCHAR2 (100) DEFAULT 'Toronto'; -- a PL/SQL varchar2 variable
    lo_end VARCHAR2 (100) DEFAULT 'Ottawa'; -- a PL/SQL varchar2 variable
    >
    so
    SQL> SELECT XMLQUERY (
      2              'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
      3               PASSING
      4               xmltype('<DirectionsResponse>
      5    <status>OK</status>
      6    <route>
      7      <summary>I-75 N</summary>
      8      <leg>
      9        <duration>
    10          <value>48220</value>
    11          <text>13 Stunden, 24 Minuten</text>
    12        </duration>
    13        <distance>
    14          <value>1404935</value>
    15          <text>1.405 km</text>
    16        </distance>
    17        <start_location>
    18          <lat>43.6533100</lat>
    19          <lng>-79.3827700</lng>
    20        </start_location>
    21        <end_location>
    22          <lat>34.7303300</lat>
    23          <lng>-86.5860700</lng>
    24        </end_location>
    25        <start_address>Toronto, Ontario, Kanada</start_address>
    26        <end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
    27      </leg>
    28    </route>
    29  </DirectionsResponse>'),
    30               'Toronto' AS "lo_start", 'Ottawa' AS "lo_end"
    31               RETURNING CONTENT)
    32       FROM DUAL;
    XMLQUERY('FOR$IIN//LEG[START_A
    SQL>
    SQL>
    SQL>
    SQL> SELECT XMLQUERY (
      2              'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
      3               PASSING
      4               xmltype('<DirectionsResponse>
      5    <status>OK</status>
      6    <route>
      7      <summary>I-75 N</summary>
      8      <leg>
      9        <duration>
    10          <value>48220</value>
    11          <text>13 Stunden, 24 Minuten</text>
    12        </duration>
    13        <distance>
    14          <value>1404935</value>
    15          <text>1.405 km</text>
    16        </distance>
    17        <start_location>
    18          <lat>43.6533100</lat>
    19          <lng>-79.3827700</lng>
    20        </start_location>
    21        <end_location>
    22          <lat>34.7303300</lat>
    23          <lng>-86.5860700</lng>
    24        </end_location>
    25        <start_address>Toronto, Ontario, Kanada</start_address>
    26        <end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
    27      </leg>
    28    </route>
    29  </DirectionsResponse>'),
    30               'Toronto' AS "lo_start", /*'Ottawa'*/'Huntsville' AS "lo_end"
    31               RETURNING CONTENT)
    32       FROM DUAL;
    XMLQUERY('FOR$IIN//LEG[START_A
    1404935
    SQL>

  • How to see the datas stored in DBMS_SQL.Varchar2S variable?

    how to see the datas stored in DBMS_SQL.Varchar2S variable?
    it says error if i use dbms_out.put_line.

    in PLSQL :
    procedure p_try (p_test IN OUT DBMS_SQL.VARCHAR2S) is
    begin
        p_test.delete ;
        p_test(    -3000) := '===============' ;
        p_test(       22) := 'Hello'  ;
        p_test(    55555) := 'World' ;
        p_test(987654321) := '===============' ;
    end p_try;
    set serveroutput on
    declare
         l_test dbms_sql.varchar2s ;
         i number ;
    begin
         p_try (l_test) ;
         i :=  l_test.first ;
         while i >= l_test.first and i <= l_test.last loop
                 dbms_output.put_line (l_test(i)) ;
                 i := l_test.next(i) ;
         end loop ;
    end ;
    ===============
    Hello
    World
    ===============when using Forms, you would use TEXT_IO instead of DBMS_OUTPUT

  • Inputing the character 'ł' into a varchar2 variable in an oracle database?

    how do I input the character 'ł' into a varchar2 variable in an oracle database?
    I tried in sql plus or PL/SQL developer, I think the app I need it for is run through Oracle forms. each time it appears as a question mark when I cut and psate it from MS word.

    Can anyone help?

  • JDBC truncates plsql varchar2 variable to 4000

    I have recently upgraded classes12.jar and ojdbc14.jar used in our app to 10gR2 versions. However all pl/sql VARCHAR2 variables >4000 characters retrieved via a package are now truncated to 400 characters.
    I am using the database package to generate a query on the fly which I then pass back to the calling java for it to execute.
    The VARCHAR2 variables are PL/SQL varaiables only - nothing is being written to the database (hence the 4000 character limit shouldn't apply)

    Johnny98 wrote:
    I'm trying to pass a JSON string into a stored procedure that has a single VARCHAR2 variable.Usually JSON is output from a stored proc (as part of generating dynamic web content or responding to Ajax calls). Strange to see it being passed as input.. and parsed?
    The error you get is from the Save_JSON() procedure itself. The error stack (that you did not post), will include the call stack, unit code names, and source code line numbers. This will pinpoint just where the exception was raised.
    I asked, "+parsed?+" - as that would explain the error. A bug in parsing text into structured data typically results in a "+ORA-06502: PL/SQL: numeric or value error+".
    Also, the actual exception text you posted says:
    ORA-20001: ORA-06502: PL/SQL: numeric or value error
    And this points to yet another fubar exception handler implementation.
    The exception handler very likely looks as follows:
    exception when OTHERS then
      raise_application_error( -20001, SQLERRM(SQLCODE) );
    end;Pardon my blunt response, but this is idiotic. Exception handlers should NOT change a meaningful exception (like -6502) into a generic catchall error (like -20001). NOT IN ANY LANGUAGE. NOT IN PL/SQL. This is not how robust and well designed software is engineered.

  • Numbers in varchar2 variable

    Dear friends,
    i have case like the following example, and i hope you have solution for my problem, lets assume the following:
    declare
    xx varchar2(10);
    begin
    xx := 5 ||','||6;
    select * from emp where emp_no in (xx);
    end ;
    when you run above query it will give invalid number. as the query didn't recognized the numbers inside the variable.
    Thanks in advance

    You want something like this:
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where ename in (
      4    with t as (select '&input_string' as txt from dual)
      5    select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
      6    from t
      7    connect by level <= length(regexp_replace(txt,'[^,]*'))+1
      8*   )
    SQL> /
    Enter value for input_string: SCOTT,JAMES
    old   4:   with t as (select '&input_string' as txt from dual)
    new   4:   with t as (select 'SCOTT,JAMES' as txt from dual)
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7788 SCOTT      ANALYST         7566 19-04-1987 00:00:00       3000                    20
          7900 JAMES      CLERK           7698 03-12-1981 00:00:00        950                    30
    SQL>Which would also work if the input was numbers and you were comparing against e.g. the empno column.

  • How to retrieve data from IN OUT VARCHAR2 variable of PL/SQL

    Hi, everyone,
    OCCI : OCCI10gR2
    Here is a sample PL/SQL code.
    SQL> CREATE PROCEDURE test4_proc( str IN OUT VARCHAR2 ) IS
    2 BEGIN
    3 str := str || ':' || str;
    4 END;
    And here is a C++ sample code using OCCI.
    std::string sql4 = "BEGIN test4_proc(:1); END;";
    std::string result;
    Statement* stmt4 = conn->createStatement(sql4);
    stmt4->setString(1, "Hello");
    stmt4->registerOutParam(1, OCCISTRING, 12);
    stmt4->executeUpdate();
    result = stmt4->getString(1);
    std::cout << "<" << result << ">" << std::endl;
    Executing this sample code, the output is "<:>" disappointingly.
    I expect that the output would be "<Hello:Hello>"
    Am I wrong ? Please let me know.
    Thanks in advance.

    Hello Shankar,
    Thank you for your instant reply.
    Thanks to you, I can write the sample code that works fine.
    I understand that calling setMaxParamSize() before calling setString() is very important.
    Below is the final sample code that works fine.
    std::string sql4 = "BEGIN test4_proc(:1); END;";
    std::string result;
    Statement* stmt4 = conn->createStatement(sql4);
    stmt4->setMaxParamSize(1, 12); // Important!! Call before setXXX()
    stmt4->setString(1, "Hello");
    stmt4->executeUpdate();
    result = stmt4->getString(1);
    std::cout << "result : <" << result << ">" << std::endl;
    Thank you.

  • Executing PL/SQL from a varchar2 variable

    so i've got an instruction ie:
    test in varchar2;
    test <= TO_DATE('2009-08-27', 'YYYY-MM-DD') ;
    how to execute "test" from inside a stored function/procedure?
    thanks i'm kind of noob, any help would be appreciated :)

    ¿Not sure here whether you've edited your original question, as Toon uses := instead of <=?
    Anyway:
    so i've got an instruction ie:
    test in varchar2;
    test <= TO_DATE('2009-08-27', 'YYYY-MM-DD') ;
    how to execute "test" from inside a stored function/procedure?
    thanks i'm kind of noob, any help would be appreciated :)So, I'm assuming your 'instruction' in human language would be something like:
    "Check if your in-parameter is older or equal to the current present day (a.k.a. SYSDATE)"
    But, WHY you need a stored function/procedure you do not mention.
    So, please read this to begin with, to get the most and maximum out of your questions:
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    And if my assumption is right, you could do something like:
    MHO%xe> create or replace function date_in_future
      2  (p_date_str in varchar2)
      3  return varchar2
      4  as
      5    rtn varchar2(1);
      6  begin
      7    case when to_date(p_date_str, 'yyyy-mm-dd') > trunc(sysdate)
      8         then rtn := 'Y';
      9         else rtn := 'N';
    10    end case;
    11    --
    12    return rtn;
    13    --
    14  end date_in_future;
    15  /
    Functie is aangemaakt.
    Verstreken: 00:00:00.25
    MHO%xe> select date_in_future('2008-02-12') from dual;
    DATE_IN_FUTURE('2008-02-12')
    N
    Verstreken: 00:00:00.07
    MHO%xe> select date_in_future('2020-02-12') from dual;
    DATE_IN_FUTURE('2020-02-12')
    YBut perhaps a BOOLEAN return or whatever would suit your requirement better.
    But then you'd need to provide a more complete and concisive case/requirement/question.
    Please remember these sites as well in any way, besides OTN, they contain tons of useful stuff (that's an understatement ;) ):
    http://tahiti.oracle.com
    http://asktom.oracle.com

  • How to SELECT * FROM varchar2 variable

    Hi there!
    I want to create a SELECT statement inside a FOR LOOP. With each loop iteration, this SELECT shall get data from a different table:
    FOR R_CURSOR IN C_CURSOR LOOP
    V_FROM_CLAUSE := R_CURSOR.TABLE;
    SELECT *
    INTO V_RESULT
    FROM V_FROM_CLAUSE:
    Obviously, this doesn't work (it might be possible that a table/view has exactly the name as the variable). But is there any possibility to create a statement like this? Please help me out :-)
    Regards,
    Thomas

    you need dynamic sql:
    EXECUTE IMMEDIATE
    'SELECT * INTO V_RESULT FROM ' || V_FROM_CLAUSE

  • On the use of VARCHAR2 vs. CHAR

    I'm posting an e-mail thread that has been moving around in my organization, whith guidance from an Oracle representative.
    The basic issue concerns the use of CHAR vs. VARCHAR2 when defining a table in Oracle.
    I would like to get some comments from the community at large.
    1. Business semantics should be represented in every aspect of a database, application, and design as far as I am concerned. Noteably, if the business rule at a corporate entity is clearly stated that when using Oracle the use of CHAR should be limited to those attribute implementations which have the following characteristics; a) The attribute may not be null, b) The attribute must have a character in each of the declared positions.
    2. When the Visual Basic application began writing data to the CHAR columns in your application someone should have had a discussion with the developer to find out why this was happening. If the business semantics changed then the logical implemention of the business semantics should have changed as well. That the two were disconnected is not a problem with the CHAR type, it is a problem with the designer or the developer. The bottom line on this instance is that the column should have been defined as a VARCHAR2 data type since the business semantics no longer complied with the criteria set forth in the previous paragraph.
    3. I think Oracle trys to load as much of the data from a table or index into shared memory, in this case the database block buffers, as it can in order to facilitate query operations. If Oracle has enough memory and can load a table or index into memory, it will do so. At the same time the database engine will move previously cached data out of memory to accommodate the new requirement.
    -----Original Message-----
    Thank you for the detail information on CHAR and VARCHAR2. It got me thinking with a DBA hat. I worked as a DBA before and I did use the CHAR type and I will share my experience/thought on CHAR.
    I don't like to use the char type like Tom has advised because Oracle does not check to see if the value being inserted fills up the column or not which can lead to a problem. And there is no performance gain or save space in Oracle.
    I worked as a DBA before, I used char type on the "must fill/always filled" column (pre DMDC). The application was written in VB with Oracle back end. At some point, VB started inserting values that are short of the column width and created a minor problem (it was supposed to be filled column). The problem was quickly identified and fixed, but it caused an issue.
    I realize that I don’t want to define it as a "must fill/always filled" column if you can't enforce it by simply defining the char data type on a table and prevent possible issue in the future.
    For a manager, in order to use the char properly, you have to hire client developers with Oracle experience or provide a basic Oracle training in order to avoid the problem I mentioned above in order to use the char type correctly.
    I think you, Tom and I are saying the same thing really. Only difference is that Tom and I can not think of a good reason why anyone would like to indicate the business semantics using column type on the database, when it can lead to more work/issues.
    In regards to wasted 25 million byes, why would Oracle load the table with 25 million rows? Shouldn't it use an index? Don't you have a serious problem if Oracle is loading table with the 25 million rows?
    Just my two cents... : )
    -----Original Message-----
    May I beg to differ?
    CHAR plays a vital role in the intuitive interpretation of a database schema. If designed correctly, the use of CHAR tells anyone who is in the know that this is a must fill column. Thus if a column is defined as CHAR(3) everyone should know that the column will always contain three characters. Defining the column as VARCHAR2(3) does not tell you anything about the data other than that the column may contain 0-3 characters.
    Also, If a column is defined as CHAR the column should always be populated. One of the nice features of VARCHAR2 is that if the column is defined at the end of a table, there is no storage overhead until that column is actually populated. Thus if you have a table that has an identifier that is nine characters in length and will always be populated with nine characters, an attribute which describes the type of identifier which is contained in the first column and which must always be populated and is a must fill attribute, and another column which is descriptive and may vary in length or not be populated at time of insert; the following definition does not express the business semantics of the entity:
    COL_CD VARCHAR2(9)
    COL_TYP_TXT VARCHAR2(26)
    COL_TYP_CD VARCHAR2(2)
    The above definition also does not take advantage of inherent storage features of Oracle; notably there is a wasted place holder between COL_CD and COL_TYP_TXT and between COL_TYP_TXT and COL_TYP_CD. The next definition does take advantage of the storage features but does not represent the business semantics of the entity:
    COL_CD VARCHAR2(9)
    COL_TYP_CD VARCHAR2(2)
    COL_TYP_TXT VARCHAR2(26)
    The above definition does not waste space storing a place holder between COL_TYP_CD and COL_TYP_TXT if the COL_TYP_TXT may be null. The column separator will only be used when the column contains data. The below definition satisfies both the storage and business semantics issues:
    COL_CD CHAR(9)
    COL_TYP_CD CHAR(2)
    COL_TYP_TXT VARCHAR2(26)
    This may seem pedantic in nature until you consider the situation where there are 25 million rows in the table represented by the above entity. If each row has a NULL COL_TYP_TXT value then the first example wasted 25 million bytes of storage and 25 million bytes of memory if the full table is loaded into memory. This is an issue which cannot be ignored in high volume databases.
    You may wish to know why it is important to define a must fill/always fill column as a CHAR to express the business semantics of an attribute. I can't give a definitive answer to that other than to say that it is just good database manners.
    So please, continue to use CHAR when the shoe fits. Don't throw something away that has use just because it is not popular or in the mode.
    Also, if I am mistaken in any of the above, please feel free to educate me.
    Thanks.
    -----Original Message-----
    Subject: RE: Oracle on the use of VARCHAR2 vs. CHAR
    Ignore if you already got this. This is just FYI.
    -----Original Message-----
    Below is a detailed answer to your VARCHAR2 or CHAR questions from our Database expert Tom Kyte. The short answer is VARCHAR2 is what you want to use. If you have any questions or want to discuss this in more detail let me know.
    A CHAR datatype and VARCHAR2 datatype are stored identically (eg: the word 'WORD' stored in a CHAR(4) and a varchar2(4) consume exactly the same amount of space on disk, both have leading byte counts).
    The difference between a CHAR and a VARCHAR is that a CHAR(n) will ALWAYS be N bytes long, it will be blank padded upon insert to ensure this. A varchar2(n) on the other hand will be 1 to N bytes long, it will NOT be blank padded.
    Using a CHAR on a varying width field can be a pain due to the search semantics of CHAR.
    Consider the following examples:
    ops$tkyte@8i> create table t ( x char(10) ); Table created.
    ops$tkyte@8i> insert into t values ( 'Hello' );
    1 row created.
    ops$tkyte@8i> select * from t where x = 'Hello';
    X
    Hello
    ops$tkyte@8i> variable y varchar2(25)
    ops$tkyte@8i> exec :y := 'Hello'
    PL/SQL procedure successfully completed.
    ops$tkyte@8i> select * from t where x = :y; no rows selected
    ops$tkyte@8i> select * from t where x = rpad(:y,10);
    X
    Hello
    Notice how when doing the search with a varchar2 variable (almost every tool in the world uses this type), we have to rpad() it to get a hit.
    If the field is in fact ALWAYS 10 bytes long, using a CHAR will not hurt -- HOWEVER, it will not help either.
    The only time I personally use a CHAR type is for CHAR(1). And that is only because its faster to type char(1) then varchar2(1) -- it offers no advantages.
    If you just use varchar2 everywhere, no problem
    My advice is, has been, will be very loudly stated as:
    IGNORE THE EXISTENCE OF CHAR.
    period. If you never use char, you never compare char to varchar2, problem solved.
    And if you use char and compare a char(n) to a char(m) they will never compare either.
    Just say NO TO CHAR.
    **************************************************

    Hi,
    >>A CHAR datatype and VARCHAR2 datatype are stored identically (eg: the word 'WORD' stored in a CHAR(4) and a varchar2(4) consume exactly the same amount of space on disk, both have leading byte counts).
    Ok, but on the other hands:
    SGMS@ORACLE10> create table x (name char(10), name2 varchar2(10));
    Table created.
    SGMS@ORACLE10> insert into  x values ('hello','hello');
    1 row created.
    SGMS@ORACLE10> commit;
    Commit complete.
    SGMS@ORACLE10> select vsize(name),vsize(name2) from x;
    VSIZE(NAME) VSIZE(NAME2)
             10            5
    SGMS@ORACLE10> select dump(name),dump(name2) from x;
    DUMP(NAME)                                         DUMP(NAME2)
    Typ=96 Len=10: 104,101,108,108,111,32,32,32,32,32  Typ=1 Len=5: 104,101,108,108,111Cheers

  • XMLELEMENT/ XMLAGG functions - Fetching the result into a variable

    Hi, I have a query to generate an XML output. I have the following questions:
    1) I am typecasting the result from this query to a VARCHAR2 and I want to assign the output to a VARCHAR2 variable. Can you please help me with that. When I try to get this into a varchar variable, i get the following error:
    declare
    x varchar2(6000);
    begin
    SELECT CAST(xmlelement("itemMaster",
    xmlelement("itemNumber",lpad(d.dept_i,3,0)||lpad(d.class_i,2,0)||lpad(d.item_i,4,0)),
    xmlelement("itemDesc",NVL(d.ITEM_DESC_T,lpad(d.dept_i,3,0)||lpad(d.class_i,2,0)||lpad(d.item_i,4,0))),
    xmlelement("paltSize",p1_test),
    xmlelement("stdUOM",p1_test),
    xmlelement("sellByDayQty",d.sell_by_day_q),
    xmlelement("shflfUOM",p1_test),
    xmlelement("minShflfDayQty",d.min_shflf_day_q),
    xmlelement("itemCatgCode",NVL(d.dc_item_catg_c,'GM')),
    xmlelement("strgTempZoneCode",NVL(d.strg_tmpr_zone_c,'01')),
    xmlelement("retailAmt",retl_a),
    xmlelement("expireDateFlag",NVL(d.expire_date_f,'N')),
    xmlelement("randomWtFlag",NVL(d.rndm_wt_f,'N')),
    xmlelement("wetFlag",NVL(d.wet_f,'N')),
    xmlelement("areaCode",d.area_c),
    xmlelement("vcpQty",d.vcp_q),
    xmlelement("sspQty",d.ssp_q),
    xmlelement("hndlTypeCode",d.hndl_type_c),
    xmlelement("mstrPackTypeCode",d.mstr_pk_type_c),
    xmlelement("mstrItemTypeCode",NVL(d.mstr_item_type_c,'00')),
    xmlelement("sszCode",d.reg_ssz_excpt_c),
    xmlelement("agriFlag",NVL(d.agrl_f,'N')),
    xmlelement("itemRankCode",d.item_rank_c),
    xmlelement("hazardFlag",NVL(d.hazd_mtrl_f,'N')),
    xmlelement("createDate",to_char(d.create_d,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("updateDate",to_char(d.modf_ts,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("actvnDate",to_char(d.actvn_d,'MM-DD-YYYY HH24:MI:SS')),
    xmlelement("organicCode",d.ognc_c),
    xmlelement("lotCntlFlag",NVL(d.lot_cntl_f,'N')),
    xmlelement("flammableFlag",NVL(d.flam_c,'N')),
    xmlelement("recordMode",c.action_c),
    xmlelement("areaType",p1_test),
    xmlelement("uoms",
    xmlelement("uom",
    xmlelement("prodUOM",p1_test),
    xmlelement("ratioDen",p1_test),
    xmlelement("consldtRule",p1_test),
    xmlelement("unitWtQty",NVL(d.unit_wt_q,1)),
    xmlelement("vcpHeightQty",NVL(d.vcp_ht_q,1)),
    xmlelement("vcpWidthQty",NVL(d.vcp_wth_q,1)),
    xmlelement("vcpLengthQty",NVL(d.vcp_lgth_q,1)),
    xmlelement("layerQty",p1_test)
    (SELECT xmlelement("aliases",
    xmlagg(xmlelement("upcCode",trunc(b.bar_code_i))
    ORDER BY b.dept_i,b.class_i,b.item_i
    FROM dc_item_bar_code b,
    dc_item a
    WHERE a.dept_i = b.dept_i
    AND a.class_i = b.class_i
    AND a.item_i = b.item_i
    AND a.dept_i = c.dept_i
    AND a.class_i = c.class_i
    AND a.item_i = c.item_i
    AS VARCHAR2(4000)
    ) INTO x
    FROM dc_item d, item_wm_trigger_w c
    WHERE d.dept_i = c.dept_i
    AND d.class_i = c.class_i
    AND d.item_i = c.item_i;
    end;
    ERROR at line 1:
    ORA-06550: line 49, column 33:
    PLS-00306: wrong number or types of arguments in call to 'XMLAGG'
    ORA-06550: line 49, column 33:
    PL/SQL: ORA-00904: "XMLAGG": invalid identifier
    ORA-06550: line 4, column 1:
    PL/SQL: SQL Statement ignored
    When I run this query without the
    declare
    begin
    select....
    into...
    end
    construct, it's working perfectly fine.
    Any help would be greatly appreciated.
    Thanks,
    Nitin

    I think I confused you. The 'pre' tags are for this Oracle Forum ( not your code). If your code was formatted we can look at it better .
    For example, I have put your code in those tags(you won't see them), they are for the forum software to process.
    See, how I didn't lose the formatting?
    DECLARE
      x VARCHAR2(6000);
    BEGIN
      SELECT CAST(xmlelement("itemMaster",
                             xmlelement("itemNumber",
                                        lpad(d.dept_i, 3, 0) || lpad(d.class_i, 2, 0) ||
                                        lpad(d.item_i, 4, 0)),
                             xmlelement("itemDesc",
                                        NVL(d.ITEM_DESC_T,
                                            lpad(d.dept_i, 3, 0) ||
                                            lpad(d.class_i, 2, 0) ||
                                            lpad(d.item_i, 4, 0))),
                             xmlelement("paltSize", p1_test),
                             xmlelement("stdUOM", p1_test),
                             xmlelement("sellByDayQty", d.sell_by_day_q),
                             xmlelement("shflfUOM", p1_test),
                             xmlelement("minShflfDayQty", d.min_shflf_day_q),
                             xmlelement("itemCatgCode", NVL(d.dc_item_catg_c, 'GM')),
                             xmlelement("strgTempZoneCode",
                                        NVL(d.strg_tmpr_zone_c, '01')),
                             xmlelement("retailAmt", retl_a),
                             xmlelement("expireDateFlag", NVL(d.expire_date_f, 'N')),
                             xmlelement("randomWtFlag", NVL(d.rndm_wt_f, 'N')),
                             xmlelement("wetFlag", NVL(d.wet_f, 'N')),
                             xmlelement("areaCode", d.area_c),
                             xmlelement("vcpQty", d.vcp_q),
                             xmlelement("sspQty", d.ssp_q),
                             xmlelement("hndlTypeCode", d.hndl_type_c),
                             xmlelement("mstrPackTypeCode", d.mstr_pk_type_c),
                             xmlelement("mstrItemTypeCode",
                                        NVL(d.mstr_item_type_c, '00')),
                             xmlelement("sszCode", d.reg_ssz_excpt_c),
                             xmlelement("agriFlag", NVL(d.agrl_f, 'N')),
                             xmlelement("itemRankCode", d.item_rank_c),
                             xmlelement("hazardFlag", NVL(d.hazd_mtrl_f, 'N')),
                             xmlelement("createDate",
                                        to_char(d.create_d, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("updateDate",
                                        to_char(d.modf_ts, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("actvnDate",
                                        to_char(d.actvn_d, 'MM-DD-YYYY HH24:MI:SS')),
                             xmlelement("organicCode", d.ognc_c),
                             xmlelement("lotCntlFlag", NVL(d.lot_cntl_f, 'N')),
                             xmlelement("flammableFlag", NVL(d.flam_c, 'N')),
                             xmlelement("recordMode", c.action_c),
                             xmlelement("areaType", p1_test),
                             xmlelement("uoms",
                                        xmlelement("uom",
                                                   xmlelement("prodUOM", p1_test),
                                                   xmlelement("ratioDen", p1_test),
                                                   xmlelement("consldtRule", p1_test),
                                                   xmlelement("unitWtQty",
                                                              NVL(d.unit_wt_q, 1)),
                                                   xmlelement("vcpHeightQty",
                                                              NVL(d.vcp_ht_q, 1)),
                                                   xmlelement("vcpWidthQty",
                                                              NVL(d.vcp_wth_q, 1)),
                                                   xmlelement("vcpLengthQty",
                                                              NVL(d.vcp_lgth_q, 1)),
                                                   xmlelement("layerQty", p1_test))),
                             (SELECT xmlelement("aliases",
                                                xmlagg(xmlelement("upcCode",
                                                                  trunc(b.bar_code_i))
                                                       ORDER BY b.dept_i,
                                                       b.class_i,
                                                       b.item_i))
                                FROM dc_item_bar_code b, dc_item a
                               WHERE a.dept_i = b.dept_i
                                 AND a.class_i = b.class_i
                                 AND a.item_i = b.item_i
                                 AND a.dept_i = c.dept_i
                                 AND a.class_i = c.class_i
                                 AND a.item_i = c.item_i)) AS VARCHAR2(4000))
        INTO x
        FROM dc_item d, item_wm_trigger_w c
       WHERE d.dept_i = c.dept_i
         AND d.class_i = c.class_i
         AND d.item_i = c.item_i;
    END;
    /

  • Conversion of batch file parameter to varchar2

    Hello, I currently have a batch file that accepts a parameter: login/password@database.
    The way i assign it in the batch file is as follows:
    %1 parameter login/password@database
    The batch file then calls sqlplus to run a script, called test.sql, it passes the %1 parameter to the test.sql script. The call from the batch file looks as follows:
    sqlplus %1 <test.sql> %1
    where test.sql is the location of the script.
    The problem arises when i try to assign the %1 parameter which is equal to say, johndoe/doe@database, to a varchar2 variable in the pl/sql anonymous block.
    Here is how that assignment looks:
    declare
    login varchar2(50);
    begin
    login := %1;
    end;
    The error i recieve is:
    invalid indentifer 'johndoe' must be declared.
    I was thinking to solve this problem all i need to do is change it to a character datatype, however, when i try TO_CHAR or using concatenation using the '||' operator
    they do not work.
    Does anyone have any ideas<QUESTION MARK>
    Thanks.

    Hello
    try to put the %1 variable in single quotes like
    login := '%1';

  • Call Data in Variable in Stored Procedure for Partition Name

    Hi,
    Here is an excerpt from a Srored Proc I have written.
    The aim here is to copy data from a partition of a table.
    I first query the partition-name from the ALL_TAB_PARTITIONS table and store the same in a VARCHAR2 variable named partition_name_low.
    I then try to select the data in this partition of the table by using the variable name.
    PROCEDURE purging AS
    partition_name_low VARCHAR2(25);
    BEGIN
    --+
    -- Query for the Highest Value of the timestamp in the 1st partition in current table.
    --+
    SELECT PARTITION_NAME
    INTO partition_name_low
    FROM ALL_TAB_PARTITIONS
    WHERE TABLE_NAME = 'TABLE1' AND PARTITION_POSITION IN
    +(+
    SELECT MIN(PARTITION_POSITION)
    FROM ALL_TAB_PARTITIONS
    WHERE TABLE_NAME = 'TABLE1'
    +);+
    COMMIT;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE(partition_name_low ||' **********  ' || TO_char(sysdate, 'MM/DD/YYYY HH24:MI:SS')||' Starting Purging Data  *********');
    --+
    -- Copy data from 1st partition to Archive Table
    --+
    INSERT /* APPEND */ INTO TABLE1_ARCHIVE+
    SELECT * FROM TABLE1 PARTITION(partition_name_low);
    However, I am facing an issue here since I keep on gettin an error that "ORA-02149: Specified Partition does not exist".
    What I understand is that the Oracle query is picking up the literal string "partition_name_low", instead of the data inside it.
    I tried with
    &partition_name_low
    AND
    :partition_name_low
    with no luck.
    For the 2nd case I get the obvious exception "bad bind variable".
    Can someone please suggest in which way I can handle this situation where I can use a variable refer the partition name in a select query?
    Thanks in advance!!
    Abhishek.

    Hi,
    You have to use "execute immediate" to launch dynamic SQL command.
    So you should write
    execute immediate 'INSERT /* APPEND */ INTO TABLE1_ARCHIVE+
    SELECT * FROM TABLE1 PARTITION('||partition_name_low||')' ;
    Mike

Maybe you are looking for

  • JLabel/html question

    how do you make a tab in html within a JLabel text. also how do you get rid of the bold that seems to be on every J label?

  • How can I change the song order when burning a CD?

    I'm trying to burn about 20 songs to a CD. However they are in alphabetical order in the burn folder which I don't want. I want then in the original order they were performed. How do I re-order them before burning? A related question: eventually I wi

  • T61p Drivers

    Does Lenovo have a piece of software that would check my machine for outdated drivers, give me a report and allow me to select which drivers to automatically install? I ran a third party app on my laptop and it came back with 26 "out dated" drivers.

  • Role of Developer

    Hi experts, What is the typical role of a Developer/Duties where BIA is used.

  • Is The Online Number Compatible With INQ1 Skype Mo...

    Hi Guys, I want to know if the Skype INQ1 mobile is compatible with the "Skype Online Number" feature? Basically, if I purchase a skype number and link my account to the INQ1, if someone calls me will the mobile ring? Also, any idea on what the inter