Help Using Count and SQL statements

Hello
This problem has been bugging me incesantly and I would be reaaaaaaally grateful if someone could help here
I want to create query that woud count the number of times a certain unedited word would be matched against different edited words
This query works well in MS ACCess but not in java
query =" SELECT Count(*) AS WordCount, Segmentations.EditedWord FROM [select Segmentations.EditedWord FROM Segmentations where Segmentations.UneditedWord = '"+Word+"']. AS c GROUP BY Segmentations.EditedWord";
I've tried removing the Segmentations. and changing it to
query =" SELECT Count(*) AS WordCount, EditedWord FROM [select EditedWord FROM Segmentations where UneditedWord = '"+Word+"']. AS c GROUP BY EditedWord";
But still nothing
I think that is due to the fact that you can't call Count(*) and another field at the same time
pleas eif anyone knows a way around this send it ASAP
thanx

Why not use,
query = "SELECT Count(*) AS WordCount, EditedWord FROM Segmentations WHERE  UneditedWord = ? GROUP BY EditedWord"and use PreparedStatement to optimize.
HTH

Similar Messages

  • HELP - using variables in SQL statement

    Hi,
    I am sure that this is a small problems for the gurus out there.
    I am trying to execute the following statement usign JDBC:
    String myVariable = "XYZ";
    sSQL = "select COL1, COL2 from TABLE1 where COL3 = '" + myVariable + "'";
    CODE ABOVE DOES NOT WORK FOR ME!!!!!
    HOWEVER, if I were to directly substitute the value XYZ as shown below, then things work. But that does not solve my problem.
    sSQL = "select COL1, COL2 from TABLE1 where COL3 = '" + "XYZ" + "'";
    Any suggestions?
    null

    Use methods setXXXX of the PreparedStatement class.
    Connection conn =
    DriverManager.getConnection("jdbc:default:connection:");
    PreparedStatement stm=conn.prepareStatement(
    "select name from persons where inn=?");
    String inn="ASDDGF12345";
    String name=new String;
    stm.setString(1,inn);
    ResultSet rss = stm.executeQuery();
    if (rss.next())
    name = rss.getString(1);
    rss.close();
    stm.close();
    conn.close();

  • The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.

    Hello All,
    I am getting below error can you please help me
    Error:-
    The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.

    Perhaps this thread will help you out
    http://stackoverflow.com/questions/11453066/error-the-transaction-associated-with-the-current-connection-has-completed-but
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Help with count and sum query

    Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
    SELECT 'ST' LEDGER,
    CASE
    WHEN c.Category = 'E' THEN 'Headcount Exempt'
    ELSE 'Headcount Non-Exempt'
    END
    ACCOUNTS,
    CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
    'MARCH_12' AS PERIOD,
    COUNT (a.empl_id) head_count
    FROM essbase.employee_pubinfo a
    LEFT OUTER JOIN MMS_DIST_COPY b
    ON a.cost_ctr = TRIM (b.bu)
    INNER JOIN MMS_GL_PAY_GROUPS c
    ON a.pay_group = c.group_code
    WHERE a.employee_status IN ('A', 'L', 'P', 'S')
    AND FISCAL_YEAR = '2012'
    AND FISCAL_MONTH = 'MARCH'
    GROUP BY a.company,
    b.district,
    a.cost_ctr,
    c.category,
    a.fiscal_month,
    a.fiscal_year;
    which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    user610131 wrote:
    ... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
    I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
    You may want both a sub-query and a different GROUP BY clause. For example:
    WITH    got_group_by_columns     AS
         SELECT  a.empl_id
         ,     CASE
                        WHEN  c.category = 'E'
                  THEN  'Headcount Exempt'
                        ELSE  'Headcount Non-Exempt'
                END          AS accounts
         ,       CASE
                        WHEN a.company = 'ZEE'
                        THEN 'OH'
                        ELSE 'NA'
                END          AS market
         FROM              essbase.employee_pubinfo a
         LEFT OUTER JOIN  mms_dist_copy             b  ON   a.cost_ctr     = TRIM (b.bu)
         INNER JOIN       mms_gl_pay_groups        c  ON   a.pay_group      = c.group_code
         WHERE     a.employee_status     IN ('A', 'L', 'P', 'S')
         AND        fiscal_year           = '2012'
         AND        fiscal_month          = 'MARCH'
    SELECT    'ST'               AS ledger
    ,       accounts
    ,       market
    ,       'MARCH_12'          AS period
    ,       COUNT (empl_id)       AS head_count
    FROM       got_group_by_columns
    GROUP BY  accounts
    ,            market
    ;But that's just a wild guess.
    You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
    Edited by: Frank Kulash on Apr 4, 2012 5:31 PM

  • Self referencing table and SQL statement

    In my database, I have a self-referencing table, the table itself is for projects, and it allows users to get a hierarchical view of the company.
    Here is the SQL (modifier is the term we use for project code, BBCI is the top project)
    SELECT
    modifier, modifierDescription, level
    FROM
    modifier
    WHERE
    level <= 2
    CONNECT BY PRIOR
    modifier = parentModifier
    START WITH modifier = 'BBCI'
    ORDER BY level
    That perticular query gets the first two levels in the structure. I use this information to produce a tree structure in a web app.
    But users have requested it would be good if in the tree structure is showed an + or - depending on whether there were anymore children under each parent, or better still the number of children under it, for example
    BBCI
    + BBCI_CHILD
    + BBCI_CHILD2
    - BBCI_CHILD3
    or
    BBCI
    + BBCI_CHILD (3 projects underneath)
    + BBCI_CHILD2 (2 projects underneath)
    - BBCI_CHILD3 (0 projects underneath)
    I am really stumped on this issue, and I am sure there is a way to do this in the web app, so for example do a query for each child node to see how many child nodes are underneath, but I figure it would be a lot tidier and faster if I could do it from a single SQL statement. Unfortunately I have tried to do this and am very much stuck.
    If you need more information please let me know
    Thanks!
    Jon

    You may be able to do this using analytical functions but it depends on the Oracle version you are using. It can also be done with standard SQL - you just need to count the number of child rows for each modifier/project first and supply that list as an in-line view:
    SELECT decode(modifier,'X',null,decode(child_rows,null,'-','+')),
    m.modifier,
    decode(modifier,'X',null,'('||nvl(cq.child_rows,0)||' projects underneath)')
    FROM modifier m,
    (select parentModifier,
         count(parentModifier) child_rows
    from modifier
    where parentModifier is not null
    group by parentModifier) cq
    WHERE m.modifier=cq.parentModifier(+)
    AND level <= 2
    CONNECT BY PRIOR
         m.modifier = m.parentModifier
    START WITH modifier = 'X'
    ORDER BY level, modifier;
    which gives you something like...
    D MODIFIER DECODE(MODIFIER,'X',NULL
    X
    - Y1 (0 projects underneath)
    + Y2 (2 projects underneath)
    + Y3 (3 projects underneath)
    The decode stuff is just to show you the result, you can format the output in your calling code. Just extend the columns to include everything you want, modifierDescription etc..
    Hope this helps.

  • Help: Using Record and Collection Methods

    I have created a record and I have to loop for as many records in the "RECORD". However if I attempt using any of the Collection Methods, I get the following error:
    ERROR at line 1:
    ORA-06550: line 41, column 14:
    PLS-00302: component 'EXISTS' must be declared
    ORA-06550: line 41, column 4:
    PL/SQL: Statement ignored
    ORA-06550: line 47, column 26:
    PLS-00302: component 'COUNT' must be declared
    ORA-06550: line 47, column 7:
    PL/SQL: Statement ignored
    Here is the SQL I am trying to execute:
    DECLARE
    TYPE Emp_Rec is RECORD (
    Emp_Id Emp.Emp_no%TYPE
    , Name Emp.Ename%TYPE
    ERec Emp_Rec;
    Cursor C_Emp IS
    SELECT
    Emp_No, Ename
    From Emp;
    begin
    OPEN C_Emp;
    LOOP
    FETCH C_Emp INTO Erec;
    EXIT WHEN C_Emp%NOTFOUND;
    END LOOP;
    IF Erec.Exists(1) THEN
    dbms_output.Put_line('exists' );
    else
    dbms_output.Put_line('does not exists');
    end if;
    CLOSE C_Emp;
    FOR I IN 1..ERec.COUNT
    LOOP
    dbms_Output.Put_Line( 'Row: ' || To_Char(I) || '; Emp: ' || ERec(i).Name) ;
    END LOOP;
    end;
    Can anyone help, please?
    Thanking you in advance,

    You only defined a Record and not a collection, therefore you cannot use .EXISTS
    This is how you would use record, collection and exists together
    DECLARE
    TYPE Emp_Rec is RECORD
             (Emp_Id Emp.Empno%TYPE,
              EName Emp.Ename%TYPE );
    TYPE Emp_tab is table of emp_rec index by binary_integer;
    ERec Emp_tab;
    Idx  INTEGER;
    Cursor C_Emp IS
         SELECT EmpNo, Ename    From Emp;
    begin
    IDX := 1;
    OPEN C_Emp;
    LOOP
           FETCH C_Emp INTO Erec(IDX);
                     EXIT WHEN C_Emp%NOTFOUND;
           IDX := IDX + 1;
    END LOOP;
    IF Erec.Exists(1) THEN
           dbms_output.Put_line('exists' );
    else
           dbms_output.Put_line('does not exists');
    end if;
    CLOSE C_Emp;
    FOR I IN 1..ERec.COUNT  LOOP
            dbms_Output.Put_Line( 'Row: ' || To_Char(I) || '; Emp: ' || ERec(i).eName) ;
    END LOOP;
    end;I hope you realize that this is only an example of how to use RECORD, COLLECTIONS and Collection Methods (.EXISTS, .COUNT)
    and not the best way to display the contents of a table.

  • Can someone help me correct this sql statement in a jsp page?

    ive been getting the java.sql.SQLException: Incorrect syntax error for one of my sql nested statements. i cant seem to find similar egs online, so reckon if anyone here could help, really appreciate it.
    as im putting the nested sql in jsp page, it has to be with lots of " " n crap. very confusing if there are nested.
    heres the sql statement without those "" that i want to use:
    select top 5 * from(
    select top+"'"+offset+"'"+" * from prod where cat=" +"'" cat "'"+"
    )order by prodID desc
    when i put this in my jsp pg, i had to add "" to become:
    String sql = "select top 5 * from("+"select top"+"'"+offset+"'"+" * from prod where cat=" +"'" +cat+ "'"+")order by prodID desc";cat=" +"'" cat "'"+")order by prodID desc";
    all those "" are confusing me to no end, so i cant figure out what should be the correct syntax. the error says the syntax error is near the offset.

    If offset is, say, 10, and cat is, say, "new", then it looks like you're going to produce the SQL:
    select top 5 * from(
      select top '10' * from prod where cat='new'
    )order by prodID descThat looks exactly like incorrect syntax to me... top almost certainly can't handle a string literal as its operand... you almost certainly would want "top 10" instead of "top '10'"...
    If you use PreparedStatement, you don't have to remember what you quote and what you don't and you can have your SQL in a single static final string to boot...

  • Using arrays in sql statement

    Hello,
    I would like to use integer array( say..int count[] = new int[3];) on my sql statement to retrieve some values. Is there a way to use int array variable in sql statement?. If yes, how should I approach doing that?.
    Thank You in Advance.
    Regards,
    Pinal.

    I'm going to be honest, I'm not so sure there is such a thing in standard SQL syntax so it would depend upon the database you were using as to whether this option was available as part of the SQL language.
    My suggestion would be to cheat, naughty I know:String arrayString = "";
    for (int i = 0; i < arrayInt.size(); i++) {
      arrayString += "**" + arrayInt;
    arrayString = arrayString.substring(2, arrayString.length());Then just parse arrayString in to an SQL VARCHAR or TEXT field.
    Obviously when you return it just use StringTokenizer to split the string up using your deliminator (in this case **) and then convert the values back into an int array.
    I'm not sure how efficient that code would be but it should do the job.

  • Function or pseudo-column 'DECODE' may be used inside a SQL statement only

    Hi everyone!
    I got the error in the subject concernig the follow piece of sql code
    + v_str_sql_body :=
    v_str_sql_body || ' and cod_entita ='
    || decode(cur.cod_entita_a,str_all,cur_ent.cod_entita,cur.cod_entita_a);
    execute immediate v_str_sql_body; +
    I can't understand what's the problem with it.
    Can anyone help me to find the error?
    Thank you in advance!
    Samuel
    Edited by: 996508 on 27-mar-2013 5.29

    Hi, Samuel,
    Welcome to the forum!
    996508 wrote:
    Hi everyone!
    I got the error in the subject concernig the follow piece of sql code
    + v_str_sql_body :=
    v_str_sql_body || ' and cod_entita ='
    || decode(cur.cod_entita_a,str_all,cur_ent.cod_entita,cur.cod_entita_a);
    execute immediate v_str_sql_body; +
    I can't understand what's the problem with it.Sorry, I can't understand what you're trying to do.
    Whenever you have a problem, post a complete script that people can run to re-create the problem and test their ideas. Include your complete PL/SQL code (if the problem involves PL/SQL) including code to call your procedure, a little sample data (CREATE TABLE and INSERT statements) for any tables involved, and the results you want the given sample data.
    Always say which version of Oracle you have (e.g., 11.2.0.3.0).
    See the forum FAQ {message:id=9360003}
    Can anyone help me to find the error?As the error message says, you can only use DECODE in a SQL statement. That is:
    v_str_body := v_str_body
            || ' and cod_entita = '
            || DECODE (...);is always an error, no matter what ... stands for.
    Perhaps you meant to have the DECODE inside the string literal.
    If not, then (depending on your version) you can use CASE instead of DECODE:
    v_str_body := v_str_body
            || ' and cod_entita = '
            || CASE  cur.cod_entita_a
                     WHEN  str_all  THEN  cur_ent.cod_entita
                                 ELSE  cur.cod_entita_a
               END;Anything that DECODE can do, CASE can do, too.
    DECODE is sometimes a little simpler than CASE to use, but only a little. It is never faster than CASE.
    CASE is sometimes much, much simpler to use than DECODE, and sometimes much faster, too.
    I won't say never use DECODE; but I will say rarely use DECODE. Use CASE instead, unless you have a specific reason why DECODE is better in that particular situation.
    In PL/SQL, you can also use IF ... THEN ... ELSE in places where you might want to use DECODE or CASE.
    For example:
    v_str_body := v_str_body
            || ' and cod_entita = ';
    IF  cur.cod_entita_a = str_all
    THEN
        v_str_body := v_str_body
                    || cur_ent.cod_entita;
    ELSE
        v_str_body := v_str_body
                    || cur.cod_entita_a;
    END IF;Edited by: Frank Kulash on Mar 27, 2013 5:59 PM
    Added IF ... THEN ... ELSE example.

  • Need Help in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

  • Select count(*) on sql statement returning zero when a matching row exists.

    Our account has an ANSI C application that checks for the existence a row on an Oracle table(s) by using the following SQL:
    int iCount = 0;
    EXEC SQL
    SELECT count(rownum) INTO :iCount
    FROM sys.all_tab_columns
    WHERE table_name IN
    (SELECT table_name FROM
    sys.all_synonyms
    WHERE upper(synonym_name) = upper(:szDestTable))
    AND upper(column_name) = upper(:szColumnName)
    AND owner = 'DBAUSER';
    The bind variables szDestTable and szColumnName are populated with values parsed from columns on another database table. This application is executed through out the day. Occasionally, the application will report a zero in the iCount when there should be a match. I have verified the szDestTable and szColumnName are populated with the correct values which would find a match and they are correct. To make matters even stranger, the application will parse the same input values and find a match (as it should). At some point during the day, and it can be at any time, the application will NOT find a match on the same file, same values. Every subsequent execution of this application will not find a match on the same values. Once the database is brought down and started up in the evening for its normal backups, the application will find a match again on the same values. This problem does not occur every day. I could be a week or a week and a half between incidents.
    I printed the contents of the sqlca.sqqlerrm.sqlerrmc field to a log file. The sqlca.sqlerrm.sqlerrmc field reported an ORA-1405 bind variable was null when the iCount was reporting a zero. When I compiled this application, I set the Proc*C flag to UNSAFE_NULLS=yes since there are other bind variable in the application that can be NULL and that is ok.
    The above SQL is compiled into the C application using the Proc*C compiler. It is compiled using the Oracle 11.2.0.2 libraries. The application is executed against an Oracle 11.2.0.2 database. The database and application are executed on an HP/Unix 11.31 platform.
    This problem did not start occurring until our account went from Oracle 10.2 to Oracle 11.2. Recently, I have changed the SQL to perform a “SELECT COUNT(rownum)” instead of the “SELECT COUNT(*)”. I compiled the application and executed the new application with the SELECT COUNT(rownum) against the same database where the same application with the SELECT COUNT(*) was failing to find a row that actually existed. The application with the SELECT COUNT(rownum) found the matching row as it should have. The new application has been executing in production for about 10 days now without any problems against ten various Oracle 11.2 databases.
    Why would SELECT COUNT(*) and SELECT COUNT(rownum) be any different?

    This forum is about C programming in general, and about using Studio C in particular.
    Your question is about Oracle database programming. You are more likely to find a helpful answer in a forum about database programming. Start here:
    https://forums.oracle.com/forums/category.jspa?categoryID=18

  • Using Procedure in SQL statement

    Dear Sir,
    As you know, I can use any function in SQL statement. For example:
    SELECT systimestamp,
    Function_Name(variable1, variable2,...)
    FROM anytable;
    So the previous function could only retrieve one value -as functions concepts-. Anyhow, Can I, in someway, use Procedure that take multiple in parameters and return multiple out parameters in SQL statement.
    Thank you in advance.

    Sir,
    I got a way in order to use the benefit of procedure in function. It's trough your idea in using TYPE OBJECT as the following:
    ===================================================================
    create or replace type Missed_Txn_type AS OBJECT
    (Txn_Timestamp_obj timestamp,
    Txn_Type_Obj Number(12));
    ===================================================================
    Then I created function and used this type as returned value:
    FUNCTION Get_Shift_Missed_Txn_Obj(F_Date_In     Date,
                        F_Time_In Timestamp,
                        F_Employee_Id     number)
    RETURN Missed_Txn_type;
    The issue is: I want send the variables of the function through SELECT statement which they come from another table like:
    SELECT
    EMP.ID,
    sd.date_value,
    shf.Time_In,
    T.OBJ.Txn_Timestamp_obj,
    T.OBJ.Txn_Type_Obj
    FROM
    EMPLOYEE EMP,
    Stored_Date SD,
    Shifts shf,
    (select Get_Shift_Missed_Txn_Obj(sd.date_value,
    shf.time_in,
    EMP.Id) OBJ from dual) T
    WHERE
    [where clause]
    But the previous statement returned an error shows that it couldn't determine the (EMP.ID, shf.time_in, sd.date_value...)...
    And the same if I use it in the select list!
    So sir, there is any way in order to solve this issue?
    Thank you in advance.

  • PL SQL using variable in SQL statement

    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dual
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1
    select to_char(val) from dual
    Thanks in advance to all who answer

    Hi,
    840386 wrote:
    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?No, you don't need a bind variable, though bind variables may be more efficient than using PL/SQL variables. I don't see where you're trying to use any varibables at all in your examples. Is it in place of the literals, such as 2 or 'YYYY_MM_DD'? You can use either bind varibales or PL/SQL variables in those places.
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dualIn PL/SQL, when you have a SELECT statement, you must specify what you want to do with the results. For example, a SELECT ... INTO statement:
    SELECT  AVG (sal)
    INTO    avg_salary
    FROM    scott.emp;There's usually no point in SELECTing from dual in PL/SQL. It's not an error, but it's simpler just to use an assignment statement.
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.Post a complete procedure or anonymous block, including variable declarations, that shows exactly what you're trying to do.
    >
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1Assuming val is a DATE, that's basically correct. You have unbalanced parentheses (there's a '(', but no matching ')' ), and you need a semicolon (';') at the end of the statement. Perhaps ');' just got cut off when you were posting this.
    select to_char(val) from dualAgain, SELECTing from dual is unnecessary, but if you had some way to catch the returned value, that would work.
    Usually, the reason why you need to call TO_CHAR is that you want a value in a particular format, which is specified in the 2nd argument to TO_CHAR. Calling TO_CHAR with only one argument is a possible mistake, but not something that would raise an error.
    Here's an example that works:
    SET     SERVEROUTPUT     ON
    DECLARE
         d     DATE;
         v     VARCHAR2 (30);
    BEGIN
         d := ADD_MONTHS (SYSDATE, -2);          -- -2 = (-2*1)
         v := TO_CHAR (d, 'DD-Mon-YYYY');
         dbms_output.put_line (v || ' = v');
    END;
    /Output (when run on March 13, 2011):
    13-Jan-2011 = v

  • Use variable in SQL statement

    HI guys:
    I need code three SQL statements.the returned field and selected table are all same,there is only a difference in their "where" statement.
      Sample code:
        select marcmatnr marcwerks
        into table it_data
        from MARC inner join MBEW on marcmatnr = mbewmatnr
        where marcmatnr like 'A%' and mbewzplp1 = '001'.
        second one........................ mbew~zplp2 = '001'
        third one......................... mbew~zplp3 = '001'
      Could I write a FORM gather them with transporting a parameter ZPLPX to determine which condiniton will be execute?
    thank you very much.

    Hi tianli,
    1. source text
       This concept of dynamic where
       condition is called source text.
    2. use like this.
       This is important in the code  --->  WHERE (mywhere).
    REPORT abc LINE-SIZE 80.
    DATA : it_data LIKE TABLE OF mara WITH HEADER LINE.
    QUOTES ARE IMPORTANT
    PERFORM mysql USING 'mbew~zplp2 = ''001'''.
    FORM mysql USING mywhere.
      SELECT marcmatnr marcwerks
      INTO TABLE it_data
      FROM marc INNER JOIN mbew ON marcmatnr = mbewmatnr
      WHERE (mywhere).
    ENDFORM.                    "mysql
    regards,
    amit m.

  • Using TOAD and SQL Developer to compare db objects in schemas in databases

    Hi All,
    My primary objective was to compare objects in schemas in two different databases and find out the differences,
    Execute DDL's in the database where objects are missing and syn schemas in two different databases.
    So I need to compare schemas in databases. Which tool would be helpful and will be user friendly to make a comparison of database objects existing in schemas in two different databases.
    I'd like to see if I can get a list of pro and cons between Toad and SQL Developer for comparing schemas pros and cons.
    Could you please also help me on navigation in SQL Developer to compare schemas.
    Connect to Source
    Connect to Target
    Compare schemas with different object types
    Find out differences
    Generate DDL's for the missing objects or for the objects in difference report
    Run them in missing instace(Source/Target)
    Make sure both are in sync.
    Thanks All

    Hi,
    Most dba type tools have this kind of functionality - personally i use plsqldeveloper but this is very similar to most other tools on the market. SQL Developer seems to rely on you needing the change management pack licence which you likely dont have and would be quite a large cost to roll out.
    I'd compare plsqldeveloper/toad/sqlnavigator etc and maybe the tools from redgate which look pretty good though i haven't used them.
    Regards,
    Harry

Maybe you are looking for

  • Macbook Pro Mid-2010 Crashing Randomly with Mavericks?

    Hey gang, I recently upgraded to Mavericks right after purchasing a used Macbook Pro mid-2010. However, more frequently, the laptop has been crashing randomly, and it does not matter which programs/apps are running when it does. Below is the latest c

  • How to find a Region id/name from a JTT jsp page

    Hi, i am on a SR details page , which i think is , ibuSRDetails.jsp in Isupport. How do i find which region it is belongs to ? I wanted to find out the region id /name so that i can customize the region. thansk -mahendra

  • Issue while connecting from Biztalk adapter to SAP ECC 6.0

    Hi Friends Issue while connecting from Visulal Studio 2005 to SAP ECC 6.0 throgh Biztalk adapter2.0, even if we pass the correct login details, system is throwing an error like incorrect user/password. Can you please tell anybody the solution for thi

  • Problem with XFI platinum fatal1ty sound from panel but not from c

    Hi I just got an XFI platinum fatalty card with front panel, I have only been able to get sound out of the ports on the acctuall card for about 3 minutes then it screetched and went off. Since then the most I can get is an EXTREEMLY quiet (I need to

  • Grid Control compatibility with Agent

    Hi I have Oracle Enterprise Manager version 10g Grid Control (10.2.0.5.0), will I be able to install Oracle Management Agent 11.1.0.1.0? Thanks in advance.